grosser-algorithms 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/History.txt +176 -0
  2. data/Manifest +47 -0
  3. data/README.markdown +102 -0
  4. data/Rakefile +26 -0
  5. data/algorithms.gemspec +32 -0
  6. data/benchmarks/deque.rb +18 -0
  7. data/benchmarks/sorts.rb +34 -0
  8. data/benchmarks/treemaps.rb +52 -0
  9. data/ext/algorithms/string/extconf.rb +4 -0
  10. data/ext/algorithms/string/string.c +70 -0
  11. data/ext/containers/deque/deque.c +249 -0
  12. data/ext/containers/deque/extconf.rb +4 -0
  13. data/ext/containers/rbtree_map/extconf.rb +4 -0
  14. data/ext/containers/rbtree_map/rbtree.c +500 -0
  15. data/ext/containers/splaytree_map/extconf.rb +4 -0
  16. data/ext/containers/splaytree_map/splaytree.c +421 -0
  17. data/grosser-algorithms.gemspec +31 -0
  18. data/lib/algorithms.rb +71 -0
  19. data/lib/algorithms/search.rb +86 -0
  20. data/lib/algorithms/sort.rb +243 -0
  21. data/lib/algorithms/string.rb +8 -0
  22. data/lib/containers/deque.rb +176 -0
  23. data/lib/containers/heap.rb +507 -0
  24. data/lib/containers/kd_tree.rb +113 -0
  25. data/lib/containers/priority_queue.rb +117 -0
  26. data/lib/containers/queue.rb +72 -0
  27. data/lib/containers/rb_tree_map.rb +402 -0
  28. data/lib/containers/splay_tree_map.rb +273 -0
  29. data/lib/containers/stack.rb +71 -0
  30. data/lib/containers/suffix_array.rb +72 -0
  31. data/lib/containers/trie.rb +188 -0
  32. data/spec/deque_gc_mark_spec.rb +18 -0
  33. data/spec/deque_spec.rb +108 -0
  34. data/spec/heap_spec.rb +126 -0
  35. data/spec/kd_expected_out.txt +10000 -0
  36. data/spec/kd_test_in.txt +10000 -0
  37. data/spec/kd_tree_spec.rb +34 -0
  38. data/spec/map_gc_mark_spec.rb +29 -0
  39. data/spec/priority_queue_spec.rb +75 -0
  40. data/spec/queue_spec.rb +61 -0
  41. data/spec/rb_tree_map_spec.rb +122 -0
  42. data/spec/search_spec.rb +28 -0
  43. data/spec/sort_spec.rb +27 -0
  44. data/spec/splay_tree_map_spec.rb +106 -0
  45. data/spec/stack_spec.rb +60 -0
  46. data/spec/string_spec.rb +13 -0
  47. data/spec/suffix_array_spec.rb +40 -0
  48. data/spec/trie_spec.rb +59 -0
  49. metadata +141 -0
@@ -0,0 +1,176 @@
1
+ === Jan 3, 2009
2
+
3
+ * Levenshtein distance in C
4
+
5
+ === April 3, 2009
6
+
7
+ * Finished C refactorization of SplayTree
8
+
9
+ === March 28, 2009
10
+
11
+ * Implemented SplayTree in C
12
+ * Made recursively_free_nodes methods static to fix a SEGFAULT
13
+ * Improved CBst
14
+ * Moved to Markdown for README
15
+ * 0.2.0 release
16
+
17
+ === January 19, 2009
18
+
19
+ * kd-tree for points in multi-dimensional space
20
+
21
+ === November 25, 2008
22
+
23
+ * Checked in gnufied's C BST
24
+
25
+ === November 13, 2008
26
+
27
+ * Removed #each for Hash and Priority Queue (Feature)
28
+
29
+ === September 15, 2008
30
+
31
+ * Added comb sort
32
+ * Benchmark work on sorting algorithms
33
+
34
+ === September 1, 2008
35
+
36
+ * Switched to Hanna rdoc template
37
+ * RBTree#isred now private
38
+
39
+ === August 20, 2008
40
+
41
+ * Implemented Knuth-Morris-Pratt substring algorithm
42
+
43
+ === August 15, 2008
44
+
45
+ * Updated README to reflect progress
46
+
47
+ === August 10, 2008
48
+
49
+ * Implemented mergesort, insertion_sort, shell_sort, quicksort
50
+
51
+ === August 8, 2008
52
+
53
+ * Implemented bubble_sort, selection_sort, heapsort
54
+
55
+ === August 5, 2008
56
+
57
+ * Started Algorithms portion
58
+ * Implemented Search#binary_search
59
+
60
+ === July 20, 2008
61
+
62
+ * Iterate over trees iteratively instead of recursively
63
+ * Implemented Deque in C
64
+
65
+ === July 15, 2008
66
+
67
+ * Refactored namespaces, thank you Austin Ziegler!
68
+
69
+ === July 14, 2008
70
+
71
+ * Use alias_method instead of alias
72
+ * Found and fixed RBTree#delete bug (finally!)
73
+ * Refactored Trie, SuffixArray, SplayTreeMap
74
+
75
+ === July 13, 2008
76
+
77
+ * Refactored Deque
78
+ * Implemented Deque#reverse_each (like Array's)
79
+
80
+ === July 12, 2008
81
+
82
+ * Reformatted some specs to be more idiomatic (Thank you Federico Builes)
83
+
84
+ === July 10, 2008
85
+
86
+ * Added algorithm complexity information for all Containers
87
+ * Implemented Trie for string representation
88
+ * Implmented SuffixArray for fast substring search
89
+ * Fixed memory leak in CRBTree
90
+ * Updated Manifest and algorithms.rb to match progress
91
+
92
+ === July 9, 2008
93
+
94
+ * Implemented Deque
95
+ * Stack and Queue now use Deque
96
+ * Fixed issues with CRBTree's #empty? and delete methods
97
+
98
+ === July 8, 2008
99
+
100
+ * Can now iterate over a heap
101
+ * Renamed #contains_key -> has_key? since it's more idiomatic
102
+ * Implented #change_key and #delete for Heap
103
+ * Priority Queue is now implemented with the new Fibonacci Heap
104
+ * Removed old Priority Queue code as a result
105
+ * Heap: fixed #delete bug not checking if item exists, #has_key? bug
106
+ for not returning boolean
107
+ * Heap: value field is now optional and defaults to the key if not specified
108
+ * More refactoring of RBTreeMap (both Ruby and C)
109
+
110
+ === July 7, 2008
111
+
112
+ * Heap is now implemented with a Fibonacci Heap, not a binomial heap
113
+
114
+ === July 4, 2008
115
+
116
+ * Implemented SplayTreeMap
117
+ * Heap now uses kind_of? to check for other heaps when doing #merge
118
+ * Renamed some Heap methods for consistency with the rest of the library
119
+ * RBTreeMap#contains? -> contains_key?
120
+ * Refactored RBTreeMap to be more object-oriented
121
+ * More documentation for RBTreeMap
122
+
123
+ === July 3, 2008
124
+
125
+ * Added documentation for Stack and Queue
126
+
127
+ === June 24, 2008
128
+
129
+ * Imported Brian Amberg's priority queue implementation
130
+ * Now uses Echoe to build gem
131
+ * Gem builds for the first time
132
+
133
+ === June 18, 2008
134
+
135
+ * Can now enumerate over RBTreeMap
136
+
137
+ === June 17, 2008
138
+
139
+ * RBTreemap#delete now returns deleted value
140
+ * Added delete method to C implementation
141
+
142
+ === June 16, 2008
143
+
144
+ * Implemented delete methods for RBTreeMap
145
+
146
+ === June 14, 2008
147
+
148
+ * Renamed the data structures module to "Containers"
149
+ * Removed dependence on stdbool.h
150
+ * Renamed RBTree to RBTreeMap
151
+
152
+ === June 13, 2008
153
+
154
+ * Implemented Sedgewick's Left Leaning Red Black Tree in C!
155
+
156
+ === June 12, 2008
157
+
158
+ * Implemented Sedgewick's Left Leaning Red Black Tree
159
+
160
+ === June 10, 2008
161
+
162
+ * Implemented merge! for other heaps and heap initialization from an array
163
+ * Implemented Queue
164
+
165
+ === June 9, 2008
166
+
167
+ * Finished binomial heap implementation
168
+
169
+ === June 8, 2008
170
+
171
+ * Added Stack
172
+ * Working on heap
173
+
174
+ === April 20
175
+
176
+ * Accepted to Google Summer of Code!
@@ -0,0 +1,47 @@
1
+ History.txt
2
+ Manifest
3
+ README.markdown
4
+ Rakefile
5
+ algorithms.gemspec
6
+ benchmarks/deque.rb
7
+ benchmarks/sorts.rb
8
+ benchmarks/treemaps.rb
9
+ ext/algorithms/string/extconf.rb
10
+ ext/algorithms/string/string.c
11
+ ext/containers/deque/deque.c
12
+ ext/containers/deque/extconf.rb
13
+ ext/containers/rbtree_map/extconf.rb
14
+ ext/containers/rbtree_map/rbtree.c
15
+ ext/containers/splaytree_map/extconf.rb
16
+ ext/containers/splaytree_map/splaytree.c
17
+ lib/algorithms.rb
18
+ lib/algorithms/search.rb
19
+ lib/algorithms/sort.rb
20
+ lib/algorithms/string.rb
21
+ lib/containers/deque.rb
22
+ lib/containers/heap.rb
23
+ lib/containers/kd_tree.rb
24
+ lib/containers/priority_queue.rb
25
+ lib/containers/queue.rb
26
+ lib/containers/rb_tree_map.rb
27
+ lib/containers/splay_tree_map.rb
28
+ lib/containers/stack.rb
29
+ lib/containers/suffix_array.rb
30
+ lib/containers/trie.rb
31
+ spec/deque_gc_mark_spec.rb
32
+ spec/deque_spec.rb
33
+ spec/heap_spec.rb
34
+ spec/kd_expected_out.txt
35
+ spec/kd_test_in.txt
36
+ spec/kd_tree_spec.rb
37
+ spec/map_gc_mark_spec.rb
38
+ spec/priority_queue_spec.rb
39
+ spec/queue_spec.rb
40
+ spec/rb_tree_map_spec.rb
41
+ spec/search_spec.rb
42
+ spec/sort_spec.rb
43
+ spec/splay_tree_map_spec.rb
44
+ spec/stack_spec.rb
45
+ spec/string_spec.rb
46
+ spec/suffix_array_spec.rb
47
+ spec/trie_spec.rb
@@ -0,0 +1,102 @@
1
+ # This branch
2
+ - gem install grosser-algorithms
3
+ - misc fixes for jruby/1.9 by [szuecs](http://github.com/szuecs)
4
+ - gemification + rdoc by [Michael Grosser](http://pragmatig.wordpress.com)
5
+
6
+ # algorithms
7
+
8
+ * Official homes are here on github, and at [rubyforge](http://rubyforge.org/projects/algorithms/)
9
+ * Documentation: [http://algorithms.rubyforge.org/](http://algorithms.rubyforge.org/)
10
+
11
+ ## DESCRIPTION:
12
+
13
+ Started as a [Google Summer of Code 2008](http://code.google.com/soc/2008/ruby/about.html) project
14
+
15
+ Written by [Kanwei Li](http://kanwei.com/), mentored by Austin Ziegler
16
+
17
+ Original Proposal: Using the right data structure or algorithm for the situation is an important
18
+ aspect of programming. In computer science literature, many data structures
19
+ and algorithms have been researched and extensively documented. However, there
20
+ is still no standard library in Ruby implementing useful structures and
21
+ algorithms like Red/Black Trees, tries, different sorting algorithms, etc.
22
+ This project will create such a library with documentation on when to use a
23
+ particular structure/algorithm. It will also come with a benchmark suite to
24
+ compare performance in different situations.
25
+
26
+ ## FEATURES:
27
+
28
+ Done so far:
29
+
30
+ * Heaps Algorithms::Containers::Heap, Containers::MaxHeap, Containers::MinHeap
31
+ * Priority Queue Algorithms::Containers::PriorityQueue
32
+ * Deque Algorithms::Containers::Deque, Containers::CDeque (C extension), Containers::RubyDeque
33
+ * Stack Algorithms::Containers::Stack (uses Deque)
34
+ * Queue Algorithms::Containers::Queue (uses Deque)
35
+ * Red-Black Trees Algorithms::Containers::RBTreeMap, Containers::CRBTreeMap (C extension), Containers::RubyRBTreeMap
36
+ * Splay Trees Algorithms::Containers::SplayTreeMap, Containers::CSplayTreeMap (C extension), Containers::RubySplayTreeMap
37
+ * Tries Algorithms::Containers::Trie
38
+ * Suffix Array Algorithms::Containers::SuffixArray
39
+ * kd Tree Algorithms::Containers::KDTree
40
+
41
+ * Search algorithms
42
+ - Binary Search Algorithms::Algorithms::Search.binary_search
43
+ - Knuth-Morris-Pratt Algorithms::Algorithms::Search.kmp_search
44
+ * Sort algorithms
45
+ - Bubble sort Algorithms::Algorithms::Sort.bubble_sort
46
+ - Comb sort Algorithms::Algorithms::Sort.comb_sort
47
+ - Selection sort Algorithms::Algorithms::Sort.selection_sort
48
+ - Heapsort Algorithms::Algorithms::Sort.heapsort
49
+ - Insertion sort Algorithms::Algorithms::Sort.insertion_sort
50
+ - Shell sort Algorithms::Algorithms::Sort.shell_sort
51
+ - Quicksort Algorithms::Algorithms::Sort.quicksort
52
+ - Mergesort Algorithms::Algorithms::Sort.mergesort
53
+
54
+ ## SYNOPSIS:
55
+
56
+ require 'rubygems'
57
+ require 'algorithms'
58
+ max_heap = Algorithms::Containers::MaxHeap.new
59
+
60
+ # To not have to type "Algorithms::" before each class, use:
61
+ include Algorithms
62
+
63
+ max_heap = Containers::MaxHeap.new
64
+
65
+ # To not have to type "Containers::" before each class, use:
66
+ include Containers
67
+ max_heap = MaxHeap.new
68
+
69
+
70
+ ## REQUIREMENTS:
71
+
72
+ * Ruby 1.8 compatible Ruby, or Ruby 1.9
73
+ * C compiler for C extensions (optional, but very much recommended for vast performance benefits)
74
+
75
+ ## INSTALL:
76
+
77
+ * sudo gem install algorithms
78
+
79
+ ## LICENSE:
80
+
81
+ (The MIT License)
82
+
83
+ Algorithms and Containers project is Copyright (c) 2009 Kanwei Li
84
+
85
+ Permission is hereby granted, free of charge, to any person obtaining
86
+ a copy of this software and associated documentation files (the
87
+ 'Software'), to deal in the Software without restriction, including
88
+ without limitation the rights to use, copy, modify, merge, publish,
89
+ distribute, sublicense, and/or sell copies of the Software, and to
90
+ permit persons to whom the Software is furnished to do so, subject to
91
+ the following conditions:
92
+
93
+ The above copyright notice and this permission notice shall be
94
+ included in all copies or substantial portions of the Software.
95
+
96
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
97
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
98
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
99
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
100
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
101
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
102
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ require 'rake'
2
+ require 'rake/rdoctask'
3
+
4
+ # get the c specs running
5
+ require 'echoe'
6
+ require "rake/clean"
7
+ OBJ = FileList['**/*.rbc']
8
+ CLEAN.include(OBJ)
9
+
10
+ Echoe.new('grosser-algorithms') do |p|
11
+ p.author = 'Kanwei Li'
12
+ p.email = 'kanwei@gmail.com'
13
+ p.summary = 'A library of algorithms and containers.'
14
+ p.url = 'http://rubyforge.org/projects/algorithms/'
15
+ p.version = File.read('VERSION').strip
16
+ p.runtime_dependencies = []
17
+ end
18
+
19
+ desc 'Generate documentation for the userstamp plugin.'
20
+ Rake::RDocTask.new(:rdoc) do |rdoc|
21
+ rdoc.title = 'Algorithms'
22
+ rdoc.rdoc_dir = 'rdoc'
23
+ rdoc.options << '--line-numbers' << '--inline-source'
24
+ rdoc.rdoc_files.include('README.markdown', 'History.txt')
25
+ rdoc.rdoc_files.include('lib/**/*.rb')
26
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{algorithms}
5
+ s.version = "0.2.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Kanwei Li"]
9
+ s.date = %q{2009-03-29}
10
+ s.description = %q{A library of algorithms and containers.}
11
+ s.email = %q{kanwei@gmail.com}
12
+ s.extensions = ["ext/containers/deque/extconf.rb", "ext/containers/rbtree_map/extconf.rb", "ext/containers/splaytree_map/extconf.rb"]
13
+ s.extra_rdoc_files = ["ext/containers/deque/deque.c", "ext/containers/deque/extconf.rb", "ext/containers/rbtree_map/extconf.rb", "ext/containers/rbtree_map/rbtree.c", "ext/containers/splaytree_map/extconf.rb", "ext/containers/splaytree_map/splaytree.c", "lib/algorithms/search.rb", "lib/algorithms/sort.rb", "lib/algorithms.rb", "lib/containers/deque.rb", "lib/containers/heap.rb", "lib/containers/kd_tree.rb", "lib/containers/priority_queue.rb", "lib/containers/queue.rb", "lib/containers/rb_tree_map.rb", "lib/containers/splay_tree_map.rb", "lib/containers/stack.rb", "lib/containers/suffix_array.rb", "lib/containers/trie.rb", "README.markdown"]
14
+ s.files = ["algorithms.gemspec", "benchmarks/deque.rb", "benchmarks/sorts.rb", "benchmarks/treemaps.rb", "ext/containers/deque/deque.c", "ext/containers/deque/extconf.rb", "ext/containers/rbtree_map/extconf.rb", "ext/containers/rbtree_map/rbtree.c", "ext/containers/splaytree_map/extconf.rb", "ext/containers/splaytree_map/splaytree.c", "History.txt", "lib/algorithms/search.rb", "lib/algorithms/sort.rb", "lib/algorithms.rb", "lib/containers/deque.rb", "lib/containers/heap.rb", "lib/containers/kd_tree.rb", "lib/containers/priority_queue.rb", "lib/containers/queue.rb", "lib/containers/rb_tree_map.rb", "lib/containers/splay_tree_map.rb", "lib/containers/stack.rb", "lib/containers/suffix_array.rb", "lib/containers/trie.rb", "Manifest", "Rakefile", "README.markdown", "spec/deque_gc_mark_spec.rb", "spec/deque_spec.rb", "spec/heap_spec.rb", "spec/kd_tree_spec.rb", "spec/priority_queue_spec.rb", "spec/queue_spec.rb", "spec/rb_tree_map_gc_mark_spec.rb", "spec/rb_tree_map_spec.rb", "spec/search_spec.rb", "spec/sort_spec.rb", "spec/splay_tree_map_spec.rb", "spec/stack_spec.rb", "spec/suffix_array_spec.rb", "spec/trie_spec.rb"]
15
+ s.has_rdoc = true
16
+ s.homepage = %q{http://rubyforge.org/projects/algorithms/}
17
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Algorithms", "--main", "README.markdown"]
18
+ s.require_paths = ["lib", "ext"]
19
+ s.rubyforge_project = %q{algorithms}
20
+ s.rubygems_version = %q{1.3.1}
21
+ s.summary = %q{A library of algorithms and containers.}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 2
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ else
29
+ end
30
+ else
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ $: << File.join(File.expand_path(File.dirname(__FILE__)), '../lib')
2
+ require 'algorithms'
3
+ include Algorithms
4
+ include Containers
5
+
6
+ require 'rubygems'
7
+ require 'rbench'
8
+
9
+ RBench.run(2) do
10
+ %w(array deque).each { |s| self.send(:column, s.intern) }
11
+ deque = Deque.new
12
+ array = []
13
+
14
+ report "Insertion at end" do
15
+ array { 1_000_000.times { |x| array << x } }
16
+ deque { 1_000_000.times { |x| deque.push_back(x) } }
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ $: << File.join(File.expand_path(File.dirname(__FILE__)), '../lib')
2
+ require 'algorithms'
3
+ include Algorithms::Algorithms
4
+
5
+ require 'rubygems'
6
+ require 'rbench'
7
+
8
+ RBench.run(5) do
9
+
10
+ sorts = %w(ruby comb_sort heapsort insertion_sort shell_sort quicksort mergesort)
11
+ sorts.each { |sort| self.send(:column, sort.intern) }
12
+
13
+ n = 10_000
14
+
15
+ proc = lambda { |scope, ary|
16
+ scope.ruby { ary.dup.sort }
17
+ scope.comb_sort { Sort.comb_sort(ary.dup) }
18
+ scope.heapsort { Sort.heapsort(ary.dup) }
19
+ scope.insertion_sort { Sort.insertion_sort(ary.dup) }
20
+ scope.shell_sort { Sort.shell_sort(ary.dup) }
21
+ scope.quicksort { Sort.quicksort(ary.dup) }
22
+ scope.mergesort { Sort.mergesort(ary.dup) }
23
+ }
24
+
25
+ report "Already sorted" do
26
+ sorted_array = Array.new(n) { rand(n) }.sort
27
+ proc.call(self, sorted_array)
28
+ end
29
+
30
+ report "Random" do
31
+ random_array = Array.new(n) { rand(n) }
32
+ proc.call(self, random_array)
33
+ end
34
+ end
@@ -0,0 +1,52 @@
1
+ $: << File.join(File.expand_path(File.dirname(__FILE__)), '../lib')
2
+ require 'algorithms'
3
+ include Algorithms
4
+ include Containers
5
+
6
+ require 'rubygems'
7
+ require 'rbench'
8
+
9
+ RBench.run(2) do
10
+ trees = %w(hash rbtree splaytree)
11
+ trees.each { |tree| self.send(:column, tree.intern) }
12
+
13
+ rbtree = RBTreeMap.new
14
+ splaytree = SplayTreeMap.new
15
+ hash = Hash.new
16
+
17
+ random_array = Array.new(300_000) { |i| rand(i) }
18
+
19
+ report "Insertion" do
20
+ rbtree { random_array.each_with_index { |x,index| rbtree[index] = x } }
21
+ splaytree { random_array.each_with_index { |x,index| splaytree[index] = x } }
22
+ hash { random_array.each_with_index { |x,index| hash[index] = x } }
23
+ end
24
+
25
+ report "has_key? (linear order)" do
26
+ rbtree { random_array.each { |n| rbtree.has_key?(n) } }
27
+ splaytree { random_array.each { |n| splaytree.has_key?(n) } }
28
+ hash { random_array.each { |n| hash.has_key?(n) } }
29
+ end
30
+
31
+ report "Lookup in sorted order" do
32
+ rbtree { rbtree.each { |k, v| k } }
33
+ splaytree { splaytree.each { |k, v| k } }
34
+ hash { hash.sort.each { |k, v| k } }
35
+
36
+ # a1, a2, a3 = [], [], []
37
+ # rbtree.each { |k, v| a1 << k }
38
+ # splaytree.each { |k, v| a2 << k }
39
+ # hash.sort.each { |k, v| a3 << k }
40
+ #
41
+ # puts "Lookup correct" if a1 == a2 && a1 == a3
42
+ end
43
+
44
+ report "Random lookups in a smaller subset" do
45
+ select_subset = random_array[0..random_array.size/20] # 5%
46
+ size = select_subset.size
47
+ rbtree { 10_000.times { rbtree[ select_subset[rand(size)] ] } }
48
+ splaytree { 10_000.times { splaytree[ select_subset[rand(size)] ] } }
49
+ hash { 10_000.times { hash[ select_subset[rand(size)] ] } }
50
+ end
51
+
52
+ end