algorithms 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/History.txt +139 -2
  2. data/Manifest +31 -8
  3. data/README +90 -0
  4. data/Rakefile +22 -9
  5. data/algorithms.gemspec +28 -101
  6. data/benchmark.rb +29 -27
  7. data/benchmarks/rbench.rb +16 -0
  8. data/benchmarks/rbench/column.rb +26 -0
  9. data/benchmarks/rbench/group.rb +43 -0
  10. data/benchmarks/rbench/report.rb +53 -0
  11. data/benchmarks/rbench/runner.rb +109 -0
  12. data/benchmarks/rbench/summary.rb +51 -0
  13. data/benchmarks/sorts.rb +33 -0
  14. data/ext/containers/bst/bst.c +205 -0
  15. data/ext/containers/{priority_queue → bst}/extconf.rb +1 -1
  16. data/ext/containers/deque/deque.c +233 -0
  17. data/ext/containers/deque/extconf.rb +4 -0
  18. data/ext/containers/tree_map/extconf.rb +1 -1
  19. data/ext/containers/tree_map/rbtree.c +73 -25
  20. data/lib/algorithms.rb +65 -6
  21. data/lib/algorithms/search.rb +84 -0
  22. data/lib/algorithms/sort.rb +238 -0
  23. data/lib/containers/deque.rb +176 -0
  24. data/lib/containers/heap.rb +451 -111
  25. data/lib/containers/kd_tree.rb +87 -0
  26. data/lib/containers/priority_queue.rb +107 -508
  27. data/lib/containers/queue.rb +62 -23
  28. data/lib/containers/rb_tree_map.rb +398 -0
  29. data/lib/containers/splay_tree_map.rb +274 -0
  30. data/lib/containers/stack.rb +59 -21
  31. data/lib/containers/suffix_array.rb +68 -0
  32. data/lib/containers/trie.rb +182 -0
  33. data/lib/graphs/graph.rb +25 -0
  34. data/spec/bst_spec.rb +31 -0
  35. data/spec/deque_spec.rb +108 -0
  36. data/spec/heap_spec.rb +111 -66
  37. data/spec/kd_tree_spec.rb +89 -0
  38. data/spec/priority_queue_spec.rb +71 -27
  39. data/spec/queue_spec.rb +53 -45
  40. data/spec/rb_tree_map_spec.rb +123 -0
  41. data/spec/search_spec.rb +28 -0
  42. data/spec/sort_spec.rb +28 -0
  43. data/spec/splay_tree_map_spec.rb +102 -0
  44. data/spec/stack_spec.rb +56 -49
  45. data/spec/suffix_array_spec.rb +40 -0
  46. data/spec/trie_spec.rb +59 -0
  47. metadata +54 -32
  48. data/README.txt +0 -58
  49. data/ext/containers/priority_queue/priority_queue.c +0 -948
  50. data/ext/containers/tree_map/Rakefile +0 -4
  51. data/lib/containers/hash.rb +0 -0
  52. data/lib/containers/tree_map.rb +0 -265
  53. data/spec/priority_queue_test.rb +0 -371
  54. data/spec/tree_map_spec.rb +0 -99
@@ -1,3 +1,138 @@
1
+ === January 19, 2009
2
+
3
+ * kd-tree for points in multi-dimensional space
4
+
5
+ === November 25, 2008
6
+
7
+ * Checked in gnufied's C BST
8
+
9
+ === November 13, 2008
10
+
11
+ * Removed #each for Hash and Priority Queue (Feature)
12
+
13
+ === September 15, 2008
14
+
15
+ * Added comb sort
16
+ * Benchmark work on sorting algorithms
17
+
18
+ === September 1, 2008
19
+
20
+ * Switched to Hanna rdoc template
21
+ * RBTree#isred now private
22
+
23
+ === August 20, 2008
24
+
25
+ * Implemented Knuth-Morris-Pratt substring algorithm
26
+
27
+ === August 15, 2008
28
+
29
+ * Updated README to reflect progress
30
+
31
+ === August 10, 2008
32
+
33
+ * Implemented mergesort, insertion_sort, shell_sort, quicksort
34
+
35
+ === August 8, 2008
36
+
37
+ * Implemented bubble_sort, selection_sort, heapsort
38
+
39
+ === August 5, 2008
40
+
41
+ * Started Algorithms portion
42
+ * Implemented Search#binary_search
43
+
44
+ === July 20, 2008
45
+
46
+ * Iterate over trees iteratively instead of recursively
47
+ * Implemented Deque in C
48
+
49
+ === July 15, 2008
50
+
51
+ * Refactored namespaces, thank you Austin Ziegler!
52
+
53
+ === July 14, 2008
54
+
55
+ * Use alias_method instead of alias
56
+ * Found and fixed RBTree#delete bug (finally!)
57
+ * Refactored Trie, SuffixArray, SplayTreeMap
58
+
59
+ === July 13, 2008
60
+
61
+ * Refactored Deque
62
+ * Implemented Deque#reverse_each (like Array's)
63
+
64
+ === July 12, 2008
65
+
66
+ * Reformatted some specs to be more idiomatic (Thank you Federico Builes)
67
+
68
+ === July 10, 2008
69
+
70
+ * Added algorithm complexity information for all Containers
71
+ * Implemented Trie for string representation
72
+ * Implmented SuffixArray for fast substring search
73
+ * Fixed memory leak in CRBTree
74
+ * Updated Manifest and algorithms.rb to match progress
75
+
76
+ === July 9, 2008
77
+
78
+ * Implemented Deque
79
+ * Stack and Queue now use Deque
80
+ * Fixed issues with CRBTree's #empty? and delete methods
81
+
82
+ === July 8, 2008
83
+
84
+ * Can now iterate over a heap
85
+ * Renamed #contains_key -> has_key? since it's more idiomatic
86
+ * Implented #change_key and #delete for Heap
87
+ * Priority Queue is now implemented with the new Fibonacci Heap
88
+ * Removed old Priority Queue code as a result
89
+ * Heap: fixed #delete bug not checking if item exists, #has_key? bug
90
+ for not returning boolean
91
+ * Heap: value field is now optional and defaults to the key if not specified
92
+ * More refactoring of RBTreeMap (both Ruby and C)
93
+
94
+ === July 7, 2008
95
+
96
+ * Heap is now implemented with a Fibonacci Heap, not a binomial heap
97
+
98
+ === July 4, 2008
99
+
100
+ * Implemented SplayTreeMap
101
+ * Heap now uses kind_of? to check for other heaps when doing #merge
102
+ * Renamed some Heap methods for consistency with the rest of the library
103
+ * RBTreeMap#contains? -> contains_key?
104
+ * Refactored RBTreeMap to be more object-oriented
105
+ * More documentation for RBTreeMap
106
+
107
+ === July 3, 2008
108
+
109
+ * Added documentation for Stack and Queue
110
+
111
+ === June 24, 2008
112
+
113
+ * Imported Brian Amberg's priority queue implementation
114
+ * Now uses Echoe to build gem
115
+ * Gem builds for the first time
116
+
117
+ === June 18, 2008
118
+
119
+ * Can now enumerate over RBTreeMap
120
+
121
+ === June 17, 2008
122
+
123
+ * RBTreemap#delete now returns deleted value
124
+ * Added delete method to C implementation
125
+
126
+ === June 16, 2008
127
+
128
+ * Implemented delete methods for RBTreeMap
129
+
130
+ === June 14, 2008
131
+
132
+ * Renamed the data structures module to "Containers"
133
+ * Removed dependence on stdbool.h
134
+ * Renamed RBTree to RBTreeMap
135
+
1
136
  === June 13, 2008
2
137
 
3
138
  * Implemented Sedgewick's Left Leaning Red Black Tree in C!
@@ -11,13 +146,15 @@
11
146
  * Implemented merge! for other heaps and heap initialization from an array
12
147
  * Implemented Queue
13
148
 
14
-
15
149
  === June 9, 2008
16
150
 
17
151
  * Finished binomial heap implementation
18
152
 
19
-
20
153
  === June 8, 2008
21
154
 
22
155
  * Added Stack
23
156
  * Working on heap
157
+
158
+ === April 20
159
+
160
+ * Accepted to Google Summer of Code!
data/Manifest CHANGED
@@ -1,23 +1,46 @@
1
+ algorithms.gemspec
1
2
  benchmark.rb
2
- ext/containers/priority_queue/extconf.rb
3
- ext/containers/priority_queue/priority_queue.c
3
+ benchmarks/rbench/column.rb
4
+ benchmarks/rbench/group.rb
5
+ benchmarks/rbench/report.rb
6
+ benchmarks/rbench/runner.rb
7
+ benchmarks/rbench/summary.rb
8
+ benchmarks/rbench.rb
9
+ benchmarks/sorts.rb
10
+ ext/containers/bst/bst.c
11
+ ext/containers/bst/extconf.rb
12
+ ext/containers/deque/deque.c
13
+ ext/containers/deque/extconf.rb
4
14
  ext/containers/tree_map/extconf.rb
5
- ext/containers/tree_map/Rakefile
6
15
  ext/containers/tree_map/rbtree.c
7
16
  History.txt
17
+ lib/algorithms/search.rb
18
+ lib/algorithms/sort.rb
8
19
  lib/algorithms.rb
9
- lib/containers/hash.rb
20
+ lib/containers/deque.rb
10
21
  lib/containers/heap.rb
22
+ lib/containers/kd_tree.rb
11
23
  lib/containers/priority_queue.rb
12
24
  lib/containers/queue.rb
25
+ lib/containers/rb_tree_map.rb
26
+ lib/containers/splay_tree_map.rb
13
27
  lib/containers/stack.rb
14
- lib/containers/tree_map.rb
28
+ lib/containers/suffix_array.rb
29
+ lib/containers/trie.rb
30
+ lib/graphs/graph.rb
15
31
  Manifest
16
32
  Rakefile
17
- README.txt
33
+ README
34
+ spec/bst_spec.rb
35
+ spec/deque_spec.rb
18
36
  spec/heap_spec.rb
37
+ spec/kd_tree_spec.rb
19
38
  spec/priority_queue_spec.rb
20
- spec/priority_queue_test.rb
21
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
22
44
  spec/stack_spec.rb
23
- spec/tree_map_spec.rb
45
+ spec/suffix_array_spec.rb
46
+ spec/trie_spec.rb
data/README ADDED
@@ -0,0 +1,90 @@
1
+ = algorithms
2
+
3
+ * http://rubyforge.org/projects/algorithms/
4
+ * Documentation: http://algorithms.rubyforge.org/
5
+
6
+ == DESCRIPTION:
7
+
8
+ This is a Google Summer of Code 2008 project
9
+
10
+ Written by Kanwei Li, mentored by Austin Ziegler
11
+
12
+ Using the right data structure or algorithm for the situation is an important
13
+ aspect of programming. In computer science literature, many data structures
14
+ and algorithms have been researched and extensively documented. However, there
15
+ is still no standard library in Ruby implementing useful structures and
16
+ algorithms like Red/Black Trees, tries, different sorting algorithms, etc.
17
+ This project will create such a library with documentation on when to use a
18
+ particular structure/algorithm. It will also come with a benchmark suite to
19
+ compare performance in different situations.
20
+
21
+ == FEATURES/PROBLEMS:
22
+
23
+ Done so far:
24
+ * Heaps - Containers::Heap, Containers::MaxHeap, Containers::MinHeap
25
+ * Priority Queue - Containers::PriorityQueue
26
+ * Stack - Containers::Stack
27
+ * Queue - Containers::Queue
28
+ * Deque - Containers::Deque, Containers::CDeque (C extension), Containers::RubyDeque
29
+ * Red-Black Trees - Containers::RBTreeMap, Containers::CRBTreeMap (C extension), Containers::RubyRBTreeMap
30
+ * Splay Trees - Containers::SplayTreeMap
31
+ * Tries - Containers::Trie
32
+ * Suffix Array - Containers::SuffixArray
33
+
34
+ * Search algorithms
35
+ - Binary Search - Algorithms::Search.binary_search
36
+ - Knuth-Morris-Pratt - Algorithms::Search.kmp_search
37
+ * Sort algorithms
38
+ - Bubble sort - Algorithms::Sort.bubble_sort
39
+ - Comb sort - Algorithms::Sort.comb_sort
40
+ - Selection sort - Algorithms::Sort.selection_sort
41
+ - Heapsort - Algorithms::Sort.heapsort
42
+ - Insertion sort - Algorithms::Sort.insertion_sort
43
+ - Shell sort - Algorithms::Sort.shell_sort
44
+ - Quicksort - Algorithms::Sort.quicksort
45
+ - Mergesort - Algorithms::Sort.mergesort
46
+
47
+ == SYNOPSIS:
48
+
49
+ require 'rubygems'
50
+ require 'algorithms'
51
+
52
+ max_heap = Containers::MaxHeap.new
53
+
54
+ # To not have to type "Containers::" before each class, use:
55
+ include Containers
56
+ max_heap = MaxHeap.new
57
+
58
+ == REQUIREMENTS:
59
+
60
+ * Ruby 1.8 compatible Ruby, or Ruby 1.9
61
+ * C compiler for extensions (optional)
62
+
63
+ == INSTALL:
64
+
65
+ * sudo gem install
66
+
67
+ == LICENSE:
68
+
69
+ (The MIT License)
70
+
71
+ Algorithms and Containers project is Copyright (c) 2008 Kanwei Li
72
+
73
+ Permission is hereby granted, free of charge, to any person obtaining
74
+ a copy of this software and associated documentation files (the
75
+ 'Software'), to deal in the Software without restriction, including
76
+ without limitation the rights to use, copy, modify, merge, publish,
77
+ distribute, sublicense, and/or sell copies of the Software, and to
78
+ permit persons to whom the Software is furnished to do so, subject to
79
+ the following conditions:
80
+
81
+ The above copyright notice and this permission notice shall be
82
+ included in all copies or substantial portions of the Software.
83
+
84
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
85
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
86
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
87
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
88
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
89
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
90
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,17 +1,30 @@
1
1
  require 'rubygems'
2
2
  require 'echoe'
3
-
3
+
4
4
  Echoe.new('algorithms') do |p|
5
- p.author = 'Kanwei Li'
6
- p.email = 'kanwei@gmail.com'
7
- p.summary = 'A library of algorithms and containers.'
8
- p.url = 'http://rubyforge.org/projects/algorithms/'
9
- p.version = "0.0.1"
5
+ p.author = 'Kanwei Li'
6
+ p.email = 'kanwei@gmail.com'
7
+ p.summary = 'A library of algorithms and containers.'
8
+ p.url = 'http://rubyforge.org/projects/algorithms/'
9
+ p.version = "0.1.0"
10
10
  p.runtime_dependencies = []
11
11
  end
12
12
 
13
13
  task :default => :spec
14
14
 
15
- task :spec => :compile do
16
- sh "spec -c spec/"
17
- end
15
+ task :spec do
16
+ sh "spec spec/*.rb --color"
17
+ end
18
+
19
+ task :push do
20
+ sh "git push" # Rubyforge
21
+ sh "git push gt" # Gitorious
22
+ sh "git push gh" # Github
23
+ end
24
+
25
+ task :hanna do
26
+ sh "rm -fr doc"
27
+ sh "hanna -SN lib/ -m Algorithms"
28
+ sh "scp -rq doc/* kanwei@rubyforge.org:/var/www/gforge-projects/algorithms"
29
+ end
30
+
@@ -1,105 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
1
2
 
2
- # Gem::Specification for Algorithms-0.0.1
3
- # Originally generated by Echoe
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{algorithms}
5
+ s.version = "0.1.0"
4
6
 
5
- --- !ruby/object:Gem::Specification
6
- name: algorithms
7
- version: !ruby/object:Gem::Version
8
- version: 0.0.1
9
- platform: ruby
10
- authors:
11
- - Kanwei Li
12
- autorequire:
13
- bindir: bin
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-02-21}
10
+ s.description = %q{A library of algorithms and containers.}
11
+ s.email = %q{kanwei@gmail.com}
12
+ s.extensions = ["ext/containers/bst/extconf.rb", "ext/containers/deque/extconf.rb", "ext/containers/tree_map/extconf.rb"]
13
+ s.extra_rdoc_files = ["ext/containers/bst/bst.c", "ext/containers/bst/extconf.rb", "ext/containers/deque/deque.c", "ext/containers/deque/extconf.rb", "ext/containers/tree_map/extconf.rb", "ext/containers/tree_map/rbtree.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", "lib/graphs/graph.rb", "README"]
14
+ s.files = ["algorithms.gemspec", "benchmark.rb", "benchmarks/rbench/column.rb", "benchmarks/rbench/group.rb", "benchmarks/rbench/report.rb", "benchmarks/rbench/runner.rb", "benchmarks/rbench/summary.rb", "benchmarks/rbench.rb", "benchmarks/sorts.rb", "ext/containers/bst/bst.c", "ext/containers/bst/extconf.rb", "ext/containers/deque/deque.c", "ext/containers/deque/extconf.rb", "ext/containers/tree_map/extconf.rb", "ext/containers/tree_map/rbtree.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", "lib/graphs/graph.rb", "Manifest", "Rakefile", "README", "spec/bst_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_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"]
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.}
14
22
 
15
- date: 2008-06-25 00:00:00 -04:00
16
- default_executable:
17
- dependencies:
18
- - !ruby/object:Gem::Dependency
19
- name: echoe
20
- type: :development
21
- version_requirement:
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: "0"
27
- version:
28
- description: A library of algorithms and containers.
29
- email: kanwei@gmail.com
30
- executables: []
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 2
31
26
 
32
- extensions:
33
- - ext/containers/priority_queue/extconf.rb
34
- - ext/containers/tree_map/extconf.rb
35
- extra_rdoc_files:
36
- - ext/containers/priority_queue/extconf.rb
37
- - ext/containers/priority_queue/priority_queue.c
38
- - ext/containers/tree_map/extconf.rb
39
- - ext/containers/tree_map/Rakefile
40
- - ext/containers/tree_map/rbtree.c
41
- - lib/algorithms.rb
42
- - lib/containers/hash.rb
43
- - lib/containers/heap.rb
44
- - lib/containers/priority_queue.rb
45
- - lib/containers/queue.rb
46
- - lib/containers/stack.rb
47
- - lib/containers/tree_map.rb
48
- - README.txt
49
- files:
50
- - benchmark.rb
51
- - ext/containers/priority_queue/extconf.rb
52
- - ext/containers/priority_queue/priority_queue.c
53
- - ext/containers/tree_map/extconf.rb
54
- - ext/containers/tree_map/Rakefile
55
- - ext/containers/tree_map/rbtree.c
56
- - History.txt
57
- - lib/algorithms.rb
58
- - lib/containers/hash.rb
59
- - lib/containers/heap.rb
60
- - lib/containers/priority_queue.rb
61
- - lib/containers/queue.rb
62
- - lib/containers/stack.rb
63
- - lib/containers/tree_map.rb
64
- - Manifest
65
- - Rakefile
66
- - README.txt
67
- - spec/heap_spec.rb
68
- - spec/priority_queue_spec.rb
69
- - spec/priority_queue_test.rb
70
- - spec/queue_spec.rb
71
- - spec/stack_spec.rb
72
- - spec/tree_map_spec.rb
73
- - algorithms.gemspec
74
- has_rdoc: true
75
- homepage: http://rubyforge.org/projects/algorithms/
76
- post_install_message:
77
- rdoc_options:
78
- - --line-numbers
79
- - --inline-source
80
- - --title
81
- - Algorithms
82
- - --main
83
- - README.txt
84
- require_paths:
85
- - lib
86
- - ext
87
- required_ruby_version: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: "0"
92
- version:
93
- required_rubygems_version: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - "="
96
- - !ruby/object:Gem::Version
97
- version: "1.2"
98
- version:
99
- requirements: []
100
-
101
- rubyforge_project: algorithms
102
- rubygems_version: 1.2.0
103
- specification_version: 2
104
- summary: A library of algorithms and containers.
105
- test_files: []
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ else
29
+ end
30
+ else
31
+ end
32
+ end