@@ -121,7 +121,7 @@ class SuRFBuilder {
121
121
inline bool isCharCommonPrefix (const label_t c, const level_t level) const ;
122
122
inline bool isLevelEmpty (const level_t level) const ;
123
123
inline void moveToNextItemSlot (const level_t level);
124
- void insertKeyByte (const char c, const level_t level, const bool is_start_of_node);
124
+ void insertKeyByte (const char c, const level_t level, const bool is_start_of_node, const bool is_term );
125
125
inline void storeSuffix (const level_t level, const word_t suffix);
126
126
127
127
// Compute sparse_start_level_ according to the pre-defined
@@ -210,13 +210,14 @@ level_t SuRFBuilder::insertKeyBytesToTrieUntilUnique(const std::string& key, con
210
210
211
211
level_t level = start_level;
212
212
bool is_start_of_node = false ;
213
+ bool is_term = false ;
213
214
// If it is the start of level, the louds bit needs to be set.
214
215
if (isLevelEmpty (level))
215
216
is_start_of_node = true ;
216
217
217
218
// After skipping the common prefix, the first following byte
218
219
// shoud be in an the node as the previous key.
219
- insertKeyByte (key[level], level, is_start_of_node);
220
+ insertKeyByte (key[level], level, is_start_of_node, is_term );
220
221
level++;
221
222
if (level > next_key.length ()
222
223
|| !isSameKey (key.substr (0 , level), next_key.substr (0 , level)))
@@ -226,15 +227,17 @@ level_t SuRFBuilder::insertKeyBytesToTrieUntilUnique(const std::string& key, con
226
227
// new node.
227
228
is_start_of_node = true ;
228
229
while (level < key.length () && level < next_key.length () && key[level] == next_key[level]) {
229
- insertKeyByte (key[level], level, is_start_of_node);
230
+ insertKeyByte (key[level], level, is_start_of_node, is_term );
230
231
level++;
231
232
}
232
233
233
234
// The last byte inserted makes key unique in the trie.
234
- if (level < key.length ())
235
- insertKeyByte (key[level], level, is_start_of_node);
236
- else
237
- insertKeyByte (kTerminator , level, is_start_of_node);
235
+ if (level < key.length ()) {
236
+ insertKeyByte (key[level], level, is_start_of_node, is_term);
237
+ } else {
238
+ is_term = true ;
239
+ insertKeyByte (kTerminator , level, is_start_of_node, is_term);
240
+ }
238
241
level++;
239
242
240
243
return level;
@@ -268,7 +271,7 @@ inline void SuRFBuilder::moveToNextItemSlot(const level_t level) {
268
271
}
269
272
}
270
273
271
- void SuRFBuilder::insertKeyByte (const char c, const level_t level, const bool is_start_of_node) {
274
+ void SuRFBuilder::insertKeyByte (const char c, const level_t level, const bool is_start_of_node, const bool is_term ) {
272
275
// level should be at most equal to tree height
273
276
if (level >= getTreeHeight ())
274
277
addLevel ();
@@ -284,6 +287,7 @@ void SuRFBuilder::insertKeyByte(const char c, const level_t level, const bool is
284
287
setBit (louds_bits_[level], getNumItems (level) - 1 );
285
288
node_counts_[level]++;
286
289
}
290
+ is_last_item_terminator_[level] = is_term;
287
291
288
292
moveToNextItemSlot (level);
289
293
}
0 commit comments