algorithms 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +139 -2
- data/Manifest +31 -8
- data/README +90 -0
- data/Rakefile +22 -9
- data/algorithms.gemspec +28 -101
- data/benchmark.rb +29 -27
- data/benchmarks/rbench.rb +16 -0
- data/benchmarks/rbench/column.rb +26 -0
- data/benchmarks/rbench/group.rb +43 -0
- data/benchmarks/rbench/report.rb +53 -0
- data/benchmarks/rbench/runner.rb +109 -0
- data/benchmarks/rbench/summary.rb +51 -0
- data/benchmarks/sorts.rb +33 -0
- data/ext/containers/bst/bst.c +205 -0
- data/ext/containers/{priority_queue → bst}/extconf.rb +1 -1
- data/ext/containers/deque/deque.c +233 -0
- data/ext/containers/deque/extconf.rb +4 -0
- data/ext/containers/tree_map/extconf.rb +1 -1
- data/ext/containers/tree_map/rbtree.c +73 -25
- data/lib/algorithms.rb +65 -6
- data/lib/algorithms/search.rb +84 -0
- data/lib/algorithms/sort.rb +238 -0
- data/lib/containers/deque.rb +176 -0
- data/lib/containers/heap.rb +451 -111
- data/lib/containers/kd_tree.rb +87 -0
- data/lib/containers/priority_queue.rb +107 -508
- data/lib/containers/queue.rb +62 -23
- data/lib/containers/rb_tree_map.rb +398 -0
- data/lib/containers/splay_tree_map.rb +274 -0
- data/lib/containers/stack.rb +59 -21
- data/lib/containers/suffix_array.rb +68 -0
- data/lib/containers/trie.rb +182 -0
- data/lib/graphs/graph.rb +25 -0
- data/spec/bst_spec.rb +31 -0
- data/spec/deque_spec.rb +108 -0
- data/spec/heap_spec.rb +111 -66
- data/spec/kd_tree_spec.rb +89 -0
- data/spec/priority_queue_spec.rb +71 -27
- data/spec/queue_spec.rb +53 -45
- data/spec/rb_tree_map_spec.rb +123 -0
- data/spec/search_spec.rb +28 -0
- data/spec/sort_spec.rb +28 -0
- data/spec/splay_tree_map_spec.rb +102 -0
- data/spec/stack_spec.rb +56 -49
- data/spec/suffix_array_spec.rb +40 -0
- data/spec/trie_spec.rb +59 -0
- metadata +54 -32
- data/README.txt +0 -58
- data/ext/containers/priority_queue/priority_queue.c +0 -948
- data/ext/containers/tree_map/Rakefile +0 -4
- data/lib/containers/hash.rb +0 -0
- data/lib/containers/tree_map.rb +0 -265
- data/spec/priority_queue_test.rb +0 -371
- data/spec/tree_map_spec.rb +0 -99
data/spec/tree_map_spec.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
require 'lib/algorithms'
|
2
|
-
|
3
|
-
describe "(empty)", :shared => true do
|
4
|
-
it "should let you put stuff in" do
|
5
|
-
100.times { |x| @tree[x] = x }
|
6
|
-
@tree.size.should eql(100)
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should return 0 for height" do
|
10
|
-
@tree.height.should eql(0)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should return 0 for size" do
|
14
|
-
@tree.size.should eql(0)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should return nil for #min_key and #max_key" do
|
18
|
-
@tree.min_key.should eql(nil)
|
19
|
-
@tree.max_key.should eql(nil)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "should not delete" do
|
23
|
-
@tree.delete(:non_existing).should eql(nil)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "(non-empty)", :shared => true do
|
28
|
-
before(:each) do
|
29
|
-
@num_items = 100
|
30
|
-
@random_array = []
|
31
|
-
@num_items.times { @random_array << rand(@num_items) }
|
32
|
-
@random_array.each { |x| @tree[x] = x }
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should return correct size (uniqify items first)" do
|
36
|
-
@tree.size.should eql(@random_array.uniq.size)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should return correct max and min keys" do
|
40
|
-
@tree.min_key.should eql(@random_array.min)
|
41
|
-
@tree.max_key.should eql(@random_array.max)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should not #contain? keys it doesn't have" do
|
45
|
-
@tree.contains?(10000).should eql(false)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should #contain? keys it does have" do
|
49
|
-
@tree.contains?(@random_array[0]).should eql(true)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should remove any key" do
|
53
|
-
random_key = @random_array[rand(@num_items)]
|
54
|
-
@tree.contains?(random_key).should eql(true)
|
55
|
-
@tree.delete(random_key).should eql(random_key)
|
56
|
-
@tree.contains?(random_key).should eql(false)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should let you iterate with #each" do
|
60
|
-
counter = 0
|
61
|
-
sorted_array = @random_array.uniq.sort
|
62
|
-
@tree.each do |key, val|
|
63
|
-
key.should eql(sorted_array[counter])
|
64
|
-
counter += 1
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe Containers::CTreeMap do
|
70
|
-
describe "empty" do
|
71
|
-
before(:each) do
|
72
|
-
@tree = Containers::CTreeMap.new
|
73
|
-
end
|
74
|
-
it_should_behave_like "(empty)"
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "full" do
|
78
|
-
before(:each) do
|
79
|
-
@tree = Containers::CTreeMap.new
|
80
|
-
end
|
81
|
-
it_should_behave_like "(non-empty)"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe Containers::RubyTreeMap do
|
86
|
-
describe "empty" do
|
87
|
-
before(:each) do
|
88
|
-
@tree = Containers::RubyTreeMap.new
|
89
|
-
end
|
90
|
-
it_should_behave_like "(empty)"
|
91
|
-
end
|
92
|
-
|
93
|
-
describe "full" do
|
94
|
-
before(:each) do
|
95
|
-
@tree = Containers::RubyTreeMap.new
|
96
|
-
end
|
97
|
-
it_should_behave_like "(non-empty)"
|
98
|
-
end
|
99
|
-
end
|