tyler-trie 0.2.2 → 0.2.3
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 +7 -0
- data/spec/trie_spec.rb +9 -1
- metadata +1 -1
data/VERSION.yml
CHANGED
data/ext/trie/trie.c
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
VALUE cTrie, cTrieNode;
|
8
8
|
|
9
9
|
static TrieChar* stringToTrieChar(VALUE string) {
|
10
|
+
StringValue(string);
|
10
11
|
return (TrieChar*) RSTRING(string)->ptr;
|
11
12
|
}
|
12
13
|
|
@@ -148,6 +149,9 @@ static VALUE walk_all_paths(VALUE children, SBTrieState *state, char *prefix) {
|
|
148
149
|
}
|
149
150
|
|
150
151
|
static VALUE trie_children(VALUE self, VALUE prefix) {
|
152
|
+
if(NIL_P(prefix))
|
153
|
+
return rb_ary_new();
|
154
|
+
|
151
155
|
SBTrie *sb_trie;
|
152
156
|
Data_Get_Struct(self, SBTrie, sb_trie);
|
153
157
|
|
@@ -204,6 +208,9 @@ static VALUE walk_all_paths_with_values(VALUE children, SBTrieState *state, char
|
|
204
208
|
}
|
205
209
|
|
206
210
|
static VALUE trie_children_with_values(VALUE self, VALUE prefix) {
|
211
|
+
if(NIL_P(prefix))
|
212
|
+
return rb_ary_new();
|
213
|
+
|
207
214
|
SBTrie *sb_trie;
|
208
215
|
Data_Get_Struct(self, SBTrie, sb_trie);
|
209
216
|
|
data/spec/trie_spec.rb
CHANGED
@@ -75,7 +75,7 @@ describe Trie do
|
|
75
75
|
children.should include('rocket')
|
76
76
|
end
|
77
77
|
|
78
|
-
it 'returns
|
78
|
+
it 'returns blank array if prefix does not exist' do
|
79
79
|
@trie.children('ajsodij').should == []
|
80
80
|
end
|
81
81
|
|
@@ -85,6 +85,10 @@ describe Trie do
|
|
85
85
|
children.should include('rock')
|
86
86
|
children.should include('rocket')
|
87
87
|
end
|
88
|
+
|
89
|
+
it 'returns blank array if prefix is nil' do
|
90
|
+
@trie.children(nil).should == []
|
91
|
+
end
|
88
92
|
end
|
89
93
|
|
90
94
|
describe :children_with_values do
|
@@ -110,6 +114,10 @@ describe Trie do
|
|
110
114
|
children.should include(['abc',2])
|
111
115
|
children.should include(['abcd',4])
|
112
116
|
end
|
117
|
+
|
118
|
+
it 'returns blank array if prefix is nil' do
|
119
|
+
@trie.children_with_values(nil).should == []
|
120
|
+
end
|
113
121
|
end
|
114
122
|
|
115
123
|
describe :walk_to_terminal do
|