algorithms 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +6 -0
- data/Rakefile +1 -1
- data/algorithms.gemspec +2 -2
- data/ext/algorithms/string/string.c +9 -9
- data/ext/containers/bst/bst.c +1 -1
- data/ext/containers/deque/deque.c +1 -1
- data/ext/containers/rbtree_map/rbtree.c +1 -1
- data/ext/containers/splaytree_map/splaytree.c +1 -1
- metadata +6 -6
data/CHANGELOG.markdown
CHANGED
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.
|
9
|
+
p.version = "0.5.0"
|
10
10
|
p.retain_gemspec = true
|
11
11
|
p.runtime_dependencies = []
|
12
12
|
p.development_dependencies = ["rspec", "echoe"]
|
data/algorithms.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "algorithms"
|
5
|
-
s.version = "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-
|
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
|
-
|
4
|
-
|
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
|
-
|
13
|
-
|
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(
|
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] =
|
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
|
-
)
|
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
|
57
|
+
return LONG2FIX(levenshtein_distance( str1, str2 ));
|
58
58
|
}
|
59
59
|
|
60
60
|
static VALUE mAlgorithms;
|
data/ext/containers/bst/bst.c
CHANGED
@@ -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
|
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
|
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
|
+
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-
|
12
|
+
date: 2012-04-25 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
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: *
|
24
|
+
version_requirements: *70163289605640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: echoe
|
27
|
-
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: *
|
35
|
+
version_requirements: *70163289605060
|
36
36
|
description: A library of algorithms and data structures (containers).
|
37
37
|
email: kanwei@gmail.com
|
38
38
|
executables: []
|