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 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* head,
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
- memcpy(buffer_pre - len, head, len);
122
+
123
123
  if (incr_existing_keys_only) {
124
- value = hattrie_tryget(trie, buffer_pre - len, len + suffix_len);
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
@@ -41,7 +41,7 @@ class Wordtriez
41
41
  _internal_walk(s).each &p
42
42
  end
43
43
 
44
- def search_with_prefix prefix, opts={}, &p
44
+ def search prefix, opts={}, &p
45
45
  opts = opts.dup
46
46
 
47
47
  limit = opts.delete :limit
@@ -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.search_with_prefix ''
41
+ a = t.search ''
42
42
  assert_equal [['万塘路', v2]], a
43
43
 
44
44
  t['马当路'] = 3
45
- a = t.search_with_prefix '万塘'
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.search_with_prefix 'a'
61
+ a = t.search 'a'
62
62
  assert_equal bs.to_a, a.map(&:first).sort
63
63
 
64
64
  a = []
65
- t.search_with_prefix 'b', sort: true, limit: 3 do |k, v|
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.search_with_prefix('CGGT').map(&:last).flatten.first
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 test_should_not_segfault_when_search_with_prefix
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.search_with_prefix("a").map(&:first)
222
+ actual_postfices = t.search("a").map(&:first)
223
223
  assert_equal expected_postfices.sort, actual_postfices.sort
224
224
  end
225
225
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordtriez
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: