algorithms-aunderwo 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.gitignore +9 -0
  2. data/History.txt +176 -0
  3. data/Manifest +47 -0
  4. data/README.markdown +93 -0
  5. data/Rakefile +31 -0
  6. data/VERSION +1 -0
  7. data/algorithms-aunderwo.gemspec +110 -0
  8. data/algorithms.gemspec +32 -0
  9. data/benchmarks/deque.rb +17 -0
  10. data/benchmarks/sorts.rb +34 -0
  11. data/benchmarks/treemaps.rb +51 -0
  12. data/ext/algorithms/string/extconf.rb +4 -0
  13. data/ext/algorithms/string/string.c +68 -0
  14. data/ext/containers/bst/bst.c +247 -0
  15. data/ext/containers/bst/extconf.rb +4 -0
  16. data/ext/containers/deque/deque.c +247 -0
  17. data/ext/containers/deque/extconf.rb +4 -0
  18. data/ext/containers/rbtree_map/extconf.rb +4 -0
  19. data/ext/containers/rbtree_map/rbtree.c +498 -0
  20. data/ext/containers/splaytree_map/extconf.rb +4 -0
  21. data/ext/containers/splaytree_map/splaytree.c +419 -0
  22. data/lib/algorithms.rb +65 -0
  23. data/lib/algorithms/search.rb +84 -0
  24. data/lib/algorithms/sort.rb +238 -0
  25. data/lib/algorithms/string.rb +8 -0
  26. data/lib/containers/deque.rb +171 -0
  27. data/lib/containers/heap.rb +486 -0
  28. data/lib/containers/kd_tree.rb +110 -0
  29. data/lib/containers/priority_queue.rb +113 -0
  30. data/lib/containers/queue.rb +68 -0
  31. data/lib/containers/rb_tree_map.rb +398 -0
  32. data/lib/containers/splay_tree_map.rb +269 -0
  33. data/lib/containers/stack.rb +67 -0
  34. data/lib/containers/suffix_array.rb +68 -0
  35. data/lib/containers/trie.rb +182 -0
  36. data/spec/bst_gc_mark_spec.rb +25 -0
  37. data/spec/bst_spec.rb +25 -0
  38. data/spec/deque_gc_mark_spec.rb +18 -0
  39. data/spec/deque_spec.rb +108 -0
  40. data/spec/heap_spec.rb +126 -0
  41. data/spec/kd_expected_out.txt +10000 -0
  42. data/spec/kd_test_in.txt +10000 -0
  43. data/spec/kd_tree_spec.rb +34 -0
  44. data/spec/map_gc_mark_spec.rb +27 -0
  45. data/spec/priority_queue_spec.rb +75 -0
  46. data/spec/queue_spec.rb +61 -0
  47. data/spec/rb_tree_map_spec.rb +123 -0
  48. data/spec/search_spec.rb +28 -0
  49. data/spec/sort_spec.rb +28 -0
  50. data/spec/splay_tree_map_spec.rb +106 -0
  51. data/spec/stack_spec.rb +60 -0
  52. data/spec/string_spec.rb +13 -0
  53. data/spec/suffix_array_spec.rb +40 -0
  54. data/spec/trie_spec.rb +59 -0
  55. metadata +138 -0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.rbc
2
+ *.bundle
3
+ *.o
4
+ *.so
5
+ Makefile
6
+ .DS_Store
7
+ doc
8
+ pkg
9
+ *#
data/History.txt ADDED
@@ -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!
data/Manifest ADDED
@@ -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
data/README.markdown ADDED
@@ -0,0 +1,93 @@
1
+ # algorithms
2
+
3
+ * Official homes are here on github, and at [rubyforge](http://rubyforge.org/projects/algorithms/)
4
+ * Documentation: [http://algorithms.rubyforge.org/](http://algorithms.rubyforge.org/)
5
+
6
+ ## DESCRIPTION:
7
+
8
+ Started as a [Google Summer of Code 2008](http://code.google.com/soc/2008/ruby/about.html) project
9
+
10
+ Written by [Kanwei Li](http://kanwei.com/), mentored by Austin Ziegler
11
+
12
+ Original Proposal: 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:
22
+
23
+ Done so far:
24
+
25
+ * Heaps Containers::Heap, Containers::MaxHeap, Containers::MinHeap
26
+ * Priority Queue Containers::PriorityQueue
27
+ * Deque Containers::Deque, Containers::CDeque (C extension), Containers::RubyDeque
28
+ * Stack Containers::Stack (uses Deque)
29
+ * Queue Containers::Queue (uses Deque)
30
+ * Red-Black Trees Containers::RBTreeMap, Containers::CRBTreeMap (C extension), Containers::RubyRBTreeMap
31
+ * Splay Trees Containers::SplayTreeMap, Containers::CSplayTreeMap (C extension), Containers::RubySplayTreeMap
32
+ * Tries Containers::Trie
33
+ * Suffix Array Containers::SuffixArray
34
+ * kd Tree Containers::KDTree
35
+
36
+ * Search algorithms
37
+ - Binary Search Algorithms::Search.binary_search
38
+ - Knuth-Morris-Pratt Algorithms::Search.kmp_search
39
+ * Sort algorithms
40
+ - Bubble sort Algorithms::Sort.bubble_sort
41
+ - Comb sort Algorithms::Sort.comb_sort
42
+ - Selection sort Algorithms::Sort.selection_sort
43
+ - Heapsort Algorithms::Sort.heapsort
44
+ - Insertion sort Algorithms::Sort.insertion_sort
45
+ - Shell sort Algorithms::Sort.shell_sort
46
+ - Quicksort Algorithms::Sort.quicksort
47
+ - Mergesort Algorithms::Sort.mergesort
48
+
49
+ ## SYNOPSIS:
50
+
51
+ require 'rubygems'
52
+ require 'algorithms'
53
+
54
+ max_heap = Containers::MaxHeap.new
55
+
56
+ # To not have to type "Containers::" before each class, use:
57
+ include Containers
58
+ max_heap = MaxHeap.new
59
+
60
+
61
+ ## REQUIREMENTS:
62
+
63
+ * Ruby 1.8 compatible Ruby, or Ruby 1.9
64
+ * C compiler for C extensions (optional, but very much recommended for vast performance benefits)
65
+
66
+ ## INSTALL:
67
+
68
+ * sudo gem install algorithms
69
+
70
+ ## LICENSE:
71
+
72
+ (The MIT License)
73
+
74
+ Algorithms and Containers project is Copyright (c) 2009 Kanwei Li
75
+
76
+ Permission is hereby granted, free of charge, to any person obtaining
77
+ a copy of this software and associated documentation files (the
78
+ 'Software'), to deal in the Software without restriction, including
79
+ without limitation the rights to use, copy, modify, merge, publish,
80
+ distribute, sublicense, and/or sell copies of the Software, and to
81
+ permit persons to whom the Software is furnished to do so, subject to
82
+ the following conditions:
83
+
84
+ The above copyright notice and this permission notice shall be
85
+ included in all copies or substantial portions of the Software.
86
+
87
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
88
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
89
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
90
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
91
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
92
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
93
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gemspec|
6
+ gemspec.name = "algorithms-aunderwo"
7
+ gemspec.summary = "A library of algorithms and containers."
8
+ gemspec.description = "A modfication of the algorithms gem to include the latest String function"
9
+ gemspec.email = "algorithms@ants.otherinbox.co, kanwei@gmail.com"
10
+ gemspec.homepage = "http://github.com/aunderwo/algorithms"
11
+ gemspec.authors = ["Kanwei Li", "Anthony Underwood"]
12
+ end
13
+ Jeweler::GemcutterTasks.new
14
+ rescue LoadError
15
+ puts "Jeweler not available. Install it with: gem install jeweler"
16
+ end
17
+
18
+
19
+ task :push do
20
+ sh "git push" # Rubyforge
21
+ sh "git push --tags" # Rubyforge
22
+ sh "git push gh" # Github
23
+ sh "git push gh --tags" # Github
24
+ end
25
+
26
+ task :hanna do
27
+ sh "rm -fr doc"
28
+ sh "hanna -SN lib/ -m Algorithms"
29
+ sh "scp -rq doc/* kanwei@rubyforge.org:/var/www/gforge-projects/algorithms"
30
+ end
31
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.0
@@ -0,0 +1,110 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{algorithms-aunderwo}
8
+ s.version = "0.4.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kanwei Li", "Anthony Underwood"]
12
+ s.date = %q{2010-07-29}
13
+ s.description = %q{A modfication of the algorithms gem to include the latest String function}
14
+ s.email = %q{algorithms@ants.otherinbox.co, kanwei@gmail.com}
15
+ s.extensions = ["ext/algorithms/string/extconf.rb", "ext/containers/splaytree_map/extconf.rb", "ext/containers/bst/extconf.rb", "ext/containers/rbtree_map/extconf.rb", "ext/containers/deque/extconf.rb"]
16
+ s.extra_rdoc_files = [
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "History.txt",
22
+ "Manifest",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "algorithms-aunderwo.gemspec",
27
+ "algorithms.gemspec",
28
+ "benchmarks/deque.rb",
29
+ "benchmarks/sorts.rb",
30
+ "benchmarks/treemaps.rb",
31
+ "ext/algorithms/string/extconf.rb",
32
+ "ext/algorithms/string/string.c",
33
+ "ext/containers/bst/bst.c",
34
+ "ext/containers/bst/extconf.rb",
35
+ "ext/containers/deque/deque.c",
36
+ "ext/containers/deque/extconf.rb",
37
+ "ext/containers/rbtree_map/extconf.rb",
38
+ "ext/containers/rbtree_map/rbtree.c",
39
+ "ext/containers/splaytree_map/extconf.rb",
40
+ "ext/containers/splaytree_map/splaytree.c",
41
+ "lib/algorithms.rb",
42
+ "lib/algorithms/search.rb",
43
+ "lib/algorithms/sort.rb",
44
+ "lib/algorithms/string.rb",
45
+ "lib/containers/deque.rb",
46
+ "lib/containers/heap.rb",
47
+ "lib/containers/kd_tree.rb",
48
+ "lib/containers/priority_queue.rb",
49
+ "lib/containers/queue.rb",
50
+ "lib/containers/rb_tree_map.rb",
51
+ "lib/containers/splay_tree_map.rb",
52
+ "lib/containers/stack.rb",
53
+ "lib/containers/suffix_array.rb",
54
+ "lib/containers/trie.rb",
55
+ "spec/bst_gc_mark_spec.rb",
56
+ "spec/bst_spec.rb",
57
+ "spec/deque_gc_mark_spec.rb",
58
+ "spec/deque_spec.rb",
59
+ "spec/heap_spec.rb",
60
+ "spec/kd_expected_out.txt",
61
+ "spec/kd_test_in.txt",
62
+ "spec/kd_tree_spec.rb",
63
+ "spec/map_gc_mark_spec.rb",
64
+ "spec/priority_queue_spec.rb",
65
+ "spec/queue_spec.rb",
66
+ "spec/rb_tree_map_spec.rb",
67
+ "spec/search_spec.rb",
68
+ "spec/sort_spec.rb",
69
+ "spec/splay_tree_map_spec.rb",
70
+ "spec/stack_spec.rb",
71
+ "spec/string_spec.rb",
72
+ "spec/suffix_array_spec.rb",
73
+ "spec/trie_spec.rb"
74
+ ]
75
+ s.homepage = %q{http://github.com/aunderwo/algorithms}
76
+ s.rdoc_options = ["--charset=UTF-8"]
77
+ s.require_paths = ["lib"]
78
+ s.rubygems_version = %q{1.3.7}
79
+ s.summary = %q{A library of algorithms and containers.}
80
+ s.test_files = [
81
+ "spec/rb_tree_map_spec.rb",
82
+ "spec/kd_tree_spec.rb",
83
+ "spec/suffix_array_spec.rb",
84
+ "spec/trie_spec.rb",
85
+ "spec/map_gc_mark_spec.rb",
86
+ "spec/heap_spec.rb",
87
+ "spec/stack_spec.rb",
88
+ "spec/priority_queue_spec.rb",
89
+ "spec/deque_gc_mark_spec.rb",
90
+ "spec/bst_spec.rb",
91
+ "spec/string_spec.rb",
92
+ "spec/queue_spec.rb",
93
+ "spec/deque_spec.rb",
94
+ "spec/sort_spec.rb",
95
+ "spec/bst_gc_mark_spec.rb",
96
+ "spec/splay_tree_map_spec.rb",
97
+ "spec/search_spec.rb"
98
+ ]
99
+
100
+ if s.respond_to? :specification_version then
101
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
102
+ s.specification_version = 3
103
+
104
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
105
+ else
106
+ end
107
+ else
108
+ end
109
+ end
110
+