algorithms 0.4.0 → 0.5.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.
@@ -1,3 +1,9 @@
1
+ === April 15, 2012
2
+
3
+ * Use long instead of int for string methods
4
+ * Use VALUE instead of int for comparison vars
5
+ * Now compiles without warnings (OS X 10.7)
6
+
1
7
  === April 19, 2012
2
8
 
3
9
  * Pulled in fix for ruby 1.9 compilation error (sorry!!)
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ Echoe.new('algorithms') do |p|
6
6
  p.email = 'kanwei@gmail.com'
7
7
  p.summary = 'A library of algorithms and data structures (containers).'
8
8
  p.url = 'https://rubygems.org/gems/algorithms'
9
- p.version = "0.4.0"
9
+ p.version = "0.5.0"
10
10
  p.retain_gemspec = true
11
11
  p.runtime_dependencies = []
12
12
  p.development_dependencies = ["rspec", "echoe"]
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "algorithms"
5
- s.version = "0.4.0"
5
+ s.version = "0.5.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Kanwei Li"]
9
- s.date = "2012-04-19"
9
+ s.date = "2012-04-25"
10
10
  s.description = "A library of algorithms and data structures (containers)."
11
11
  s.email = "kanwei@gmail.com"
12
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"]
@@ -1,7 +1,7 @@
1
1
  #include "ruby.h"
2
2
 
3
- int min(int a, int b, int c) {
4
- int min = a;
3
+ long min_three(long a, long b, long c) {
4
+ long min = a;
5
5
  if (b < min)
6
6
  min = b;
7
7
  if( c < min)
@@ -9,11 +9,11 @@ int min(int a, int b, int c) {
9
9
  return min;
10
10
  }
11
11
 
12
- int levenshtein_distance(VALUE str1, VALUE str2) {
13
- int i, j, s1_len, s2_len, *d;
12
+ long levenshtein_distance(VALUE str1, VALUE str2) {
13
+ long i, j, s1_len, s2_len, *d;
14
14
  char * s = RSTRING_PTR(str1);
15
15
  char * t = RSTRING_PTR(str2);
16
- s1_len = RSTRING_LEN(str1);
16
+ s1_len = RSTRING_LEN(str1);
17
17
  s2_len = RSTRING_LEN(str2);
18
18
 
19
19
  if (s1_len == 0) {
@@ -26,7 +26,7 @@ int levenshtein_distance(VALUE str1, VALUE str2) {
26
26
  s1_len++;
27
27
  s2_len++;
28
28
 
29
- d = malloc(sizeof(int) * (s1_len) * (s2_len));
29
+ d = malloc(sizeof(typeof(d)) * (s1_len) * (s2_len));
30
30
 
31
31
  for (i = 0; i < s1_len; i++) {
32
32
  d[i] = i; // d[i, 0] = i
@@ -40,11 +40,11 @@ int levenshtein_distance(VALUE str1, VALUE str2) {
40
40
  if (s[i-1] == t[j-1]) {
41
41
  d[j * s1_len + i] = d[(j-1) * s1_len + (i-1)];
42
42
  } else {
43
- d[j * s1_len + i] = min(
43
+ d[j * s1_len + i] = 1 + min_three(
44
44
  d[j * s1_len + (i-1)],
45
45
  d[(j-1) * s1_len + i],
46
46
  d[(j-1) * s1_len + (i-1)]
47
- ) + 1;
47
+ );
48
48
  }
49
49
  }
50
50
  }
@@ -54,7 +54,7 @@ int levenshtein_distance(VALUE str1, VALUE str2) {
54
54
  }
55
55
 
56
56
  static VALUE lev_dist(VALUE self, VALUE str1, VALUE str2) {
57
- return INT2FIX(levenshtein_distance( str1, str2 ));
57
+ return LONG2FIX(levenshtein_distance( str1, str2 ));
58
58
  }
59
59
 
60
60
  static VALUE mAlgorithms;
@@ -44,7 +44,7 @@ static bst* bst_each(bst *tree, void (*each)(bst *tree, bst_node *node, void *ar
44
44
  return tree;
45
45
  }
46
46
 
47
- static int id_compare_operator;
47
+ static VALUE id_compare_operator;
48
48
 
49
49
  static int bst_compare_function(VALUE a, VALUE b) {
50
50
  if (a == b) return 0;
@@ -200,7 +200,7 @@ static VALUE deque_each_backward(VALUE self) {
200
200
 
201
201
  static VALUE deque_init(int argc, VALUE *argv, VALUE self)
202
202
  {
203
- int len, i;
203
+ long len, i;
204
204
  VALUE ary;
205
205
 
206
206
  if(argc == 0) {
@@ -287,7 +287,7 @@ static rbtree* rbt_each(rbtree *tree, void (*each)(rbtree *tree, rbtree_node *no
287
287
 
288
288
  // Methods to be called in Ruby
289
289
 
290
- static int id_compare_operator;
290
+ static VALUE id_compare_operator;
291
291
 
292
292
  static int rbtree_compare_function(VALUE a, VALUE b) {
293
293
  if (a == b) return 0;
@@ -230,7 +230,7 @@ static splaytree* splay_each(splaytree *tree, void (*each)(splaytree *tree, spla
230
230
 
231
231
  // Methods to be called in Ruby
232
232
 
233
- static int id_compare_operator;
233
+ static VALUE id_compare_operator;
234
234
 
235
235
  static int splaytree_compare_function(VALUE a, VALUE b) {
236
236
  if (a == b) return 0;
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.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-19 00:00:00.000000000Z
12
+ date: 2012-04-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70335276597400 !ruby/object:Gem::Requirement
16
+ requirement: &70163289605640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70335276597400
24
+ version_requirements: *70163289605640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: echoe
27
- requirement: &70335276596820 !ruby/object:Gem::Requirement
27
+ requirement: &70163289605060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70335276596820
35
+ version_requirements: *70163289605060
36
36
  description: A library of algorithms and data structures (containers).
37
37
  email: kanwei@gmail.com
38
38
  executables: []