tyler-trie 0.2.2 → 0.2.3

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.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- patch: 2
2
+ patch: 3
3
3
  major: 0
4
4
  minor: 2
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 nil if prefix does not exist' do
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
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.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler McMullen