wordtriez 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/hat-trie/text.c +7 -4
- data/lib/wordtriez.rb +1 -1
- data/test/wordtriez_test.rb +7 -7
- metadata +1 -1
data/ext/hat-trie/text.c
CHANGED
@@ -107,11 +107,11 @@ void add_ngrams(hattrie_t* trie, int upto_n, char* text, uint8_t incr_existing_k
|
|
107
107
|
add_ngrams_with_suffix(trie, upto_n, text, blank_suffix, incr_existing_keys_only);
|
108
108
|
}
|
109
109
|
|
110
|
-
inline void incr_value(
|
110
|
+
static inline void incr_value(
|
111
111
|
hattrie_t* trie,
|
112
112
|
char* buffer,
|
113
113
|
char* buffer_pre,
|
114
|
-
char*
|
114
|
+
char* key,
|
115
115
|
size_t len,
|
116
116
|
size_t suffix_len,
|
117
117
|
uint8_t incr_existing_keys_only)
|
@@ -119,13 +119,16 @@ inline void incr_value(
|
|
119
119
|
value_t* value = NULL;
|
120
120
|
|
121
121
|
assert(buffer_pre - len >= buffer);
|
122
|
-
|
122
|
+
|
123
123
|
if (incr_existing_keys_only) {
|
124
|
-
value = hattrie_tryget(trie,
|
124
|
+
value = hattrie_tryget(trie, key, len);
|
125
125
|
if (value) {
|
126
|
+
memcpy(buffer_pre - len, key, len);
|
127
|
+
value = hattrie_get(trie, buffer_pre - len, len + suffix_len);
|
126
128
|
(*value)++;
|
127
129
|
}
|
128
130
|
} else {
|
131
|
+
memcpy(buffer_pre - len, key, len);
|
129
132
|
value = hattrie_get(trie, buffer_pre - len, len + suffix_len);
|
130
133
|
(*value)++;
|
131
134
|
}
|
data/lib/wordtriez.rb
CHANGED
data/test/wordtriez_test.rb
CHANGED
@@ -38,11 +38,11 @@ class WordtriezTest < Test::Unit::TestCase
|
|
38
38
|
assert_equal nil, t['万塘路一锅鸡']
|
39
39
|
assert_equal v2, t['万塘路']
|
40
40
|
|
41
|
-
a = t.
|
41
|
+
a = t.search ''
|
42
42
|
assert_equal [['万塘路', v2]], a
|
43
43
|
|
44
44
|
t['马当路'] = 3
|
45
|
-
a = t.
|
45
|
+
a = t.search '万塘'
|
46
46
|
assert_equal [['路', v2]], a
|
47
47
|
end
|
48
48
|
|
@@ -58,11 +58,11 @@ class WordtriezTest < Test::Unit::TestCase
|
|
58
58
|
end
|
59
59
|
assert_equal as.size * bs.size, t.size
|
60
60
|
|
61
|
-
a = t.
|
61
|
+
a = t.search 'a'
|
62
62
|
assert_equal bs.to_a, a.map(&:first).sort
|
63
63
|
|
64
64
|
a = []
|
65
|
-
t.
|
65
|
+
t.search 'b', sort: true, limit: 3 do |k, v|
|
66
66
|
a << k
|
67
67
|
end
|
68
68
|
assert_equal 3, a.size
|
@@ -105,7 +105,7 @@ class WordtriezTest < Test::Unit::TestCase
|
|
105
105
|
sequences.each do |seq, id|
|
106
106
|
t.change_all(:suffix, seq){ id }
|
107
107
|
end
|
108
|
-
assert_equal 2, t.
|
108
|
+
assert_equal 2, t.search('CGGT').map(&:last).flatten.first
|
109
109
|
end
|
110
110
|
|
111
111
|
def test_nul_char_in_keys
|
@@ -214,12 +214,12 @@ class WordtriezTest < Test::Unit::TestCase
|
|
214
214
|
assert_equal '一锅鸡', lcs
|
215
215
|
end
|
216
216
|
|
217
|
-
def
|
217
|
+
def test_should_not_segfault_when_search
|
218
218
|
t = Wordtriez.new
|
219
219
|
# bursts when 16384
|
220
220
|
16_385.times{ |i| t["a#{i}"] = i }
|
221
221
|
expected_postfices = 16_385.times.map &:to_s
|
222
|
-
actual_postfices = t.
|
222
|
+
actual_postfices = t.search("a").map(&:first)
|
223
223
|
assert_equal expected_postfices.sort, actual_postfices.sort
|
224
224
|
end
|
225
225
|
end
|