algorithms 0.5.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ === January 22, 2013
2
+
3
+ * JRuby support
4
+
1
5
  === April 15, 2012
2
6
 
3
7
  * Use long instead of int for string methods
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "rspec"
7
+ gem "rake-compiler"
8
+ end
9
+
@@ -1,7 +1,4 @@
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/)
1
+ # algorithms [![Build Status](https://travis-ci.org/kanwei/algorithms.png)](https://travis-ci.org/kanwei/algorithms)
5
2
 
6
3
  ## DESCRIPTION:
7
4
 
@@ -9,7 +6,9 @@ Started as a [Google Summer of Code 2008](http://code.google.com/soc/2008/ruby/a
9
6
 
10
7
  Written by [Kanwei Li](http://kanwei.com/), mentored by Austin Ziegler
11
8
 
12
- Original Proposal: Using the right data structure or algorithm for the situation is an important
9
+ ### Original Proposal: ###
10
+
11
+ Using the right data structure or algorithm for the situation is an important
13
12
  aspect of programming. In computer science literature, many data structures
14
13
  and algorithms have been researched and extensively documented. However, there
15
14
  is still no standard library in Ruby implementing useful structures and
@@ -18,60 +17,52 @@ This project will create such a library with documentation on when to use a
18
17
  particular structure/algorithm. It will also come with a benchmark suite to
19
18
  compare performance in different situations.
20
19
 
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
20
+ ## COMPLETED:
21
+
22
+ * Heaps Containers::Heap, Containers::MaxHeap, Containers::MinHeap
23
+ * Priority Queue Containers::PriorityQueue
24
+ * Deque Containers::Deque, Containers::CDeque (C ext)
25
+ * Stack Containers::Stack
26
+ * Queue Containers::Queue
27
+ * Red-Black Trees Containers::RBTreeMap, Containers::CRBTreeMap (C ext)
28
+ * Splay Trees Containers::SplayTreeMap, Containers::CSplayTreeMap (C ext)
29
+ * Tries Containers::Trie
30
+ * Suffix Array Containers::SuffixArray
31
+
32
+ * Search algorithms
33
+ - Binary Search Algorithms::Search.binary_search
34
+ - Knuth-Morris-Pratt Algorithms::Search.kmp_search
35
+ * Sorting algorithms
36
+ - Bubble sort Algorithms::Sort.bubble_sort
37
+ - Comb sort Algorithms::Sort.comb_sort
38
+ - Selection sort Algorithms::Sort.selection_sort
39
+ - Heapsort Algorithms::Sort.heapsort
40
+ - Insertion sort Algorithms::Sort.insertion_sort
41
+ - Shell sort Algorithms::Sort.shell_sort
42
+ - Quicksort Algorithms::Sort.quicksort
43
+ - Mergesort Algorithms::Sort.mergesort
48
44
 
49
45
  ## SYNOPSIS:
50
46
 
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
47
+ require 'rubygems'
48
+ require 'algorithms'
59
49
 
50
+ max_heap = Containers::MaxHeap.new
60
51
 
61
- ## REQUIREMENTS:
52
+ # To not have to type "Containers::" before each class, use:
53
+ include Containers
54
+ max_heap = MaxHeap.new
62
55
 
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:
56
+ ## REQUIREMENTS:
67
57
 
68
- * sudo gem install algorithms
58
+ * Ruby 1.8, Ruby 1.9, JRuby
59
+ * C extensions (optional, but very much recommended for vast performance benefits)
69
60
 
70
61
  ## LICENSE:
71
62
 
72
63
  (The MIT License)
73
64
 
74
- Algorithms and Containers project is Copyright (c) 2009 Kanwei Li
65
+ Ruby Algorithms and Containers project is Copyright (c) 2009 Kanwei Li
75
66
 
76
67
  Permission is hereby granted, free of charge, to any person obtaining
77
68
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,13 +1,18 @@
1
1
  require 'rubygems'
2
- require 'echoe'
3
-
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 data structures (containers).'
8
- p.url = 'https://rubygems.org/gems/algorithms'
9
- p.version = "0.5.0"
10
- p.retain_gemspec = true
11
- p.runtime_dependencies = []
12
- p.development_dependencies = ["rspec", "echoe"]
2
+ require 'rake/extensiontask'
3
+ require 'rspec/core/rake_task'
4
+ require 'bundler/gem_tasks'
5
+
6
+ Rake::ExtensionTask.new('algorithms/string') { |ext| ext.name = "CString" }
7
+ Rake::ExtensionTask.new('containers/deque') { |ext| ext.name = "CDeque" }
8
+ Rake::ExtensionTask.new('containers/bst') { |ext| ext.name = "CBst" }
9
+ Rake::ExtensionTask.new('containers/rbtree_map') { |ext| ext.name = "CRBTreeMap" }
10
+ Rake::ExtensionTask.new('containers/splaytree_map') { |ext| ext.name = "CSplayTreeMap" }
11
+
12
+ RSpec::Core::RakeTask.new
13
+
14
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
15
+ task :default => [:spec]
16
+ else
17
+ task :default => [:compile, :spec]
13
18
  end
@@ -2,35 +2,22 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "algorithms"
5
- s.version = "0.5.0"
5
+ s.version = "0.6.1"
6
6
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
7
  s.authors = ["Kanwei Li"]
9
- s.date = "2012-04-25"
10
- s.description = "A library of algorithms and data structures (containers)."
11
8
  s.email = "kanwei@gmail.com"
12
- s.extensions = ["ext/algorithms/string/extconf.rb", "ext/containers/bst/extconf.rb", "ext/containers/deque/extconf.rb", "ext/containers/rbtree_map/extconf.rb", "ext/containers/splaytree_map/extconf.rb"]
13
- s.extra_rdoc_files = ["CHANGELOG.markdown", "README.markdown", "ext/algorithms/string/extconf.rb", "ext/algorithms/string/string.c", "ext/containers/bst/bst.c", "ext/containers/bst/extconf.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", "lib/algorithms.rb", "lib/algorithms/search.rb", "lib/algorithms/sort.rb", "lib/algorithms/string.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"]
14
- s.files = ["CHANGELOG.markdown", "Manifest", "README.markdown", "Rakefile", "algorithms.gemspec", "benchmarks/deque.rb", "benchmarks/sorts.rb", "benchmarks/treemaps.rb", "ext/algorithms/string/extconf.rb", "ext/algorithms/string/string.c", "ext/containers/bst/bst.c", "ext/containers/bst/extconf.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", "lib/algorithms.rb", "lib/algorithms/search.rb", "lib/algorithms/sort.rb", "lib/algorithms/string.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", "spec/bst_gc_mark_spec.rb", "spec/bst_spec.rb", "spec/deque_gc_mark_spec.rb", "spec/deque_spec.rb", "spec/heap_spec.rb", "spec/kd_expected_out.txt", "spec/kd_test_in.txt", "spec/kd_tree_spec.rb", "spec/map_gc_mark_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/string_spec.rb", "spec/suffix_array_spec.rb", "spec/trie_spec.rb"]
15
- s.homepage = "https://rubygems.org/gems/algorithms"
9
+ s.license = 'MIT'
10
+ s.date = "2013-01-22"
11
+ s.summary = "Useful algorithms and data structures for Ruby. Optional C extensions."
12
+ s.description = "Heap, Priority Queue, Deque, Stack, Queue, Red-Black Trees, Splay Trees, sorting algorithms, and more"
13
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
14
+ s.platform = "java"
15
+ else
16
+ s.extensions = ["ext/algorithms/string/extconf.rb", "ext/containers/bst/extconf.rb", "ext/containers/deque/extconf.rb", "ext/containers/rbtree_map/extconf.rb", "ext/containers/splaytree_map/extconf.rb"]
17
+ end
18
+ s.files = ["Gemfile", "CHANGELOG.markdown", "Manifest", "README.markdown", "Rakefile", "algorithms.gemspec", "benchmarks/deque.rb", "benchmarks/sorts.rb", "benchmarks/treemaps.rb", "ext/algorithms/string/extconf.rb", "ext/algorithms/string/string.c", "ext/containers/bst/bst.c", "ext/containers/bst/extconf.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", "lib/algorithms.rb", "lib/algorithms/search.rb", "lib/algorithms/sort.rb", "lib/algorithms/string.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", "spec/bst_gc_mark_spec.rb", "spec/bst_spec.rb", "spec/deque_gc_mark_spec.rb", "spec/deque_spec.rb", "spec/heap_spec.rb", "spec/kd_expected_out.txt", "spec/kd_test_in.txt", "spec/kd_tree_spec.rb", "spec/map_gc_mark_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/string_spec.rb", "spec/suffix_array_spec.rb", "spec/trie_spec.rb"]
19
+ s.homepage = "https://github.com/kanwei/algorithms"
16
20
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Algorithms", "--main", "README.markdown"]
17
21
  s.require_paths = ["lib", "ext"]
18
22
  s.rubyforge_project = "algorithms"
19
- s.rubygems_version = "1.8.15"
20
- s.summary = "A library of algorithms and data structures (containers)."
21
-
22
- if s.respond_to? :specification_version then
23
- s.specification_version = 3
24
-
25
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- s.add_development_dependency(%q<rspec>, [">= 0"])
27
- s.add_development_dependency(%q<echoe>, [">= 0"])
28
- else
29
- s.add_dependency(%q<rspec>, [">= 0"])
30
- s.add_dependency(%q<echoe>, [">= 0"])
31
- end
32
- else
33
- s.add_dependency(%q<rspec>, [">= 0"])
34
- s.add_dependency(%q<echoe>, [">= 0"])
35
- end
36
23
  end
@@ -5,4 +5,5 @@
5
5
 
6
6
  begin
7
7
  require 'CString'
8
+ rescue LoadError
8
9
  end
@@ -13,7 +13,7 @@ class Containers::Trie
13
13
  #
14
14
  # t = Containers::Trie.new
15
15
  # t["hello"] = "world"
16
- # t["hello] #=> "world"
16
+ # t["hello"] #=> "world"
17
17
  def initialize
18
18
  @root = nil
19
19
  end
@@ -1,27 +1,29 @@
1
1
  $: << File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
2
2
  require 'algorithms'
3
3
 
4
- describe "map gc mark test" do
5
- it "should mark ruby object references" do
6
- anon_key_class = Class.new do
7
- attr :value
8
- def initialize(x); @value = x; end
9
- def <=>(other); value <=> other.value; end
4
+ if !(defined? RUBY_ENGINE && RUBY_ENGINE == 'jruby')
5
+ describe "map gc mark test" do
6
+ it "should mark ruby object references" do
7
+ anon_key_class = Class.new do
8
+ attr :value
9
+ def initialize(x); @value = x; end
10
+ def <=>(other); value <=> other.value; end
11
+ end
12
+ anon_val_class = Class.new
13
+ @rbtree = Containers::RBTreeMap.new
14
+ @splaytree = Containers::SplayTreeMap.new
15
+ 100.times { |x|
16
+ @rbtree[anon_key_class.new(x)] = anon_val_class.new
17
+ @splaytree[anon_key_class.new(x)] = anon_val_class.new
18
+ }
19
+ # Mark and sweep
20
+ ObjectSpace.garbage_collect
21
+ # Check if any instances were swept
22
+ count = 0
23
+ ObjectSpace.each_object(anon_key_class) { |x| count += 1 }
24
+ count.should eql(200)
25
+ ObjectSpace.each_object(anon_val_class) { |x| count += 1 }
26
+ count.should eql(400)
10
27
  end
11
- anon_val_class = Class.new
12
- @rbtree = Containers::CRBTreeMap.new
13
- @splaytree = Containers::CSplayTreeMap.new
14
- 100.times { |x|
15
- @rbtree[anon_key_class.new(x)] = anon_val_class.new
16
- @splaytree[anon_key_class.new(x)] = anon_val_class.new
17
- }
18
- # Mark and sweep
19
- ObjectSpace.garbage_collect
20
- # Check if any instances were swept
21
- count = 0
22
- ObjectSpace.each_object(anon_key_class) { |x| count += 1 }
23
- count.should eql(200)
24
- ObjectSpace.each_object(anon_val_class) { |x| count += 1 }
25
- count.should eql(400)
26
28
  end
27
29
  end
@@ -1,13 +1,15 @@
1
1
  $: << File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
2
2
  require 'algorithms'
3
3
 
4
- describe "string algorithms" do
5
- it "should do levenshtein distance" do
6
- Algorithms::String.levenshtein_dist("Hello", "Hel").should eql(2)
7
- Algorithms::String.levenshtein_dist("Hello", "").should eql(5)
8
- Algorithms::String.levenshtein_dist("", "Hello").should eql(5)
9
- Algorithms::String.levenshtein_dist("Hello", "Hello").should eql(0)
10
- Algorithms::String.levenshtein_dist("Hello", "ello").should eql(1)
11
- Algorithms::String.levenshtein_dist("Hello", "Mello").should eql(1)
4
+ if defined? Algorithms::String
5
+ describe "string algorithms" do
6
+ it "should do levenshtein distance" do
7
+ Algorithms::String.levenshtein_dist("Hello", "Hel").should eql(2)
8
+ Algorithms::String.levenshtein_dist("Hello", "").should eql(5)
9
+ Algorithms::String.levenshtein_dist("", "Hello").should eql(5)
10
+ Algorithms::String.levenshtein_dist("Hello", "Hello").should eql(0)
11
+ Algorithms::String.levenshtein_dist("Hello", "ello").should eql(1)
12
+ Algorithms::String.levenshtein_dist("Hello", "Mello").should eql(1)
13
+ end
12
14
  end
13
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algorithms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,31 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-25 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rspec
16
- requirement: &70163289605640 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
- prerelease: false
24
- version_requirements: *70163289605640
25
- - !ruby/object:Gem::Dependency
26
- name: echoe
27
- requirement: &70163289605060 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70163289605060
36
- description: A library of algorithms and data structures (containers).
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Heap, Priority Queue, Deque, Stack, Queue, Red-Black Trees, Splay Trees,
15
+ sorting algorithms, and more
37
16
  email: kanwei@gmail.com
38
17
  executables: []
39
18
  extensions:
@@ -42,34 +21,9 @@ extensions:
42
21
  - ext/containers/deque/extconf.rb
43
22
  - ext/containers/rbtree_map/extconf.rb
44
23
  - ext/containers/splaytree_map/extconf.rb
45
- extra_rdoc_files:
46
- - CHANGELOG.markdown
47
- - README.markdown
48
- - ext/algorithms/string/extconf.rb
49
- - ext/algorithms/string/string.c
50
- - ext/containers/bst/bst.c
51
- - ext/containers/bst/extconf.rb
52
- - ext/containers/deque/deque.c
53
- - ext/containers/deque/extconf.rb
54
- - ext/containers/rbtree_map/extconf.rb
55
- - ext/containers/rbtree_map/rbtree.c
56
- - ext/containers/splaytree_map/extconf.rb
57
- - ext/containers/splaytree_map/splaytree.c
58
- - lib/algorithms.rb
59
- - lib/algorithms/search.rb
60
- - lib/algorithms/sort.rb
61
- - lib/algorithms/string.rb
62
- - lib/containers/deque.rb
63
- - lib/containers/heap.rb
64
- - lib/containers/kd_tree.rb
65
- - lib/containers/priority_queue.rb
66
- - lib/containers/queue.rb
67
- - lib/containers/rb_tree_map.rb
68
- - lib/containers/splay_tree_map.rb
69
- - lib/containers/stack.rb
70
- - lib/containers/suffix_array.rb
71
- - lib/containers/trie.rb
24
+ extra_rdoc_files: []
72
25
  files:
26
+ - Gemfile
73
27
  - CHANGELOG.markdown
74
28
  - Manifest
75
29
  - README.markdown
@@ -121,8 +75,9 @@ files:
121
75
  - spec/string_spec.rb
122
76
  - spec/suffix_array_spec.rb
123
77
  - spec/trie_spec.rb
124
- homepage: https://rubygems.org/gems/algorithms
125
- licenses: []
78
+ homepage: https://github.com/kanwei/algorithms
79
+ licenses:
80
+ - MIT
126
81
  post_install_message:
127
82
  rdoc_options:
128
83
  - --line-numbers
@@ -145,11 +100,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
100
  requirements:
146
101
  - - ! '>='
147
102
  - !ruby/object:Gem::Version
148
- version: '1.2'
103
+ version: '0'
149
104
  requirements: []
150
105
  rubyforge_project: algorithms
151
- rubygems_version: 1.8.15
106
+ rubygems_version: 1.8.23
152
107
  signing_key:
153
108
  specification_version: 3
154
- summary: A library of algorithms and data structures (containers).
109
+ summary: Useful algorithms and data structures for Ruby. Optional C extensions.
155
110
  test_files: []