tyler-trie 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/ext/trie/trie.c +12 -1
- data/spec/trie_spec.rb +15 -0
- metadata +2 -2
data/VERSION.yml
CHANGED
data/ext/trie/trie.c
CHANGED
@@ -95,7 +95,7 @@ static VALUE trie_add(VALUE self, VALUE args) {
|
|
95
95
|
|
96
96
|
VALUE key;
|
97
97
|
key = RARRAY(args)->ptr[0];
|
98
|
-
|
98
|
+
int32 value = size == 2 ? NUM2INT(RARRAY(args)->ptr[1]) : TRIE_DATA_ERROR;
|
99
99
|
|
100
100
|
const TrieChar *sb_key = stringToTrieChar(key);
|
101
101
|
|
@@ -117,6 +117,16 @@ static VALUE trie_delete(VALUE self, VALUE key) {
|
|
117
117
|
return Qnil;
|
118
118
|
}
|
119
119
|
|
120
|
+
static VALUE trie_save(VALUE self) {
|
121
|
+
SBTrie *sb_trie;
|
122
|
+
Data_Get_Struct(self, SBTrie, sb_trie);
|
123
|
+
|
124
|
+
if(sb_trie_save(sb_trie) == -1)
|
125
|
+
return Qnil;
|
126
|
+
else
|
127
|
+
return Qtrue;
|
128
|
+
}
|
129
|
+
|
120
130
|
static VALUE walk_all_paths(VALUE children, SBTrieState *state, char *prefix) {
|
121
131
|
int c;
|
122
132
|
for(c = 1; c < TRIE_CHAR_MAX; c++) {
|
@@ -326,6 +336,7 @@ void Init_trie() {
|
|
326
336
|
rb_define_method(cTrie, "children", trie_children, 1);
|
327
337
|
rb_define_method(cTrie, "walk_to_terminal", trie_walk_to_terminal, -2);
|
328
338
|
rb_define_method(cTrie, "root", trie_root, 0);
|
339
|
+
rb_define_method(cTrie, "save", trie_save, 0);
|
329
340
|
|
330
341
|
cTrieNode = rb_define_class("TrieNode", rb_cObject);
|
331
342
|
rb_define_alloc_func(cTrieNode, trie_node_alloc);
|
data/spec/trie_spec.rb
CHANGED
@@ -53,6 +53,11 @@ describe Trie do
|
|
53
53
|
@trie.add('chicka',123).should == true
|
54
54
|
@trie.get('chicka').should == 123
|
55
55
|
end
|
56
|
+
|
57
|
+
it 'adds values greater than 16-bit allows' do
|
58
|
+
@trie.add('chicka', 72_000).should == true
|
59
|
+
@trie.get('chicka').should == 72_000
|
60
|
+
end
|
56
61
|
end
|
57
62
|
|
58
63
|
describe :delete do
|
@@ -109,6 +114,16 @@ describe Trie do
|
|
109
114
|
@trie.root.should_not == @trie.root
|
110
115
|
end
|
111
116
|
end
|
117
|
+
|
118
|
+
describe :save do
|
119
|
+
it 'saves the trie to disk such that another trie can be spawned which will read succesfully' do
|
120
|
+
@trie.add('omgwtf',123)
|
121
|
+
@trie.save
|
122
|
+
|
123
|
+
trie2 = Trie.new(TRIE_PATH)
|
124
|
+
trie2.get('omgwtf').should == 123
|
125
|
+
end
|
126
|
+
end
|
112
127
|
end
|
113
128
|
|
114
129
|
describe TrieNode do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tyler-trie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler McMullen
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-11 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|