Skip to content

Commit c9c8986

Browse files
committed
bug fix in buider
1 parent f6b0103 commit c9c8986

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

include/surf_builder.hpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class SuRFBuilder {
121121
inline bool isCharCommonPrefix(const label_t c, const level_t level) const;
122122
inline bool isLevelEmpty(const level_t level) const;
123123
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);
125125
inline void storeSuffix(const level_t level, const word_t suffix);
126126

127127
// Compute sparse_start_level_ according to the pre-defined
@@ -210,13 +210,14 @@ level_t SuRFBuilder::insertKeyBytesToTrieUntilUnique(const std::string& key, con
210210

211211
level_t level = start_level;
212212
bool is_start_of_node = false;
213+
bool is_term = false;
213214
// If it is the start of level, the louds bit needs to be set.
214215
if (isLevelEmpty(level))
215216
is_start_of_node = true;
216217

217218
// After skipping the common prefix, the first following byte
218219
// 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);
220221
level++;
221222
if (level > next_key.length()
222223
|| !isSameKey(key.substr(0, level), next_key.substr(0, level)))
@@ -226,15 +227,17 @@ level_t SuRFBuilder::insertKeyBytesToTrieUntilUnique(const std::string& key, con
226227
// new node.
227228
is_start_of_node = true;
228229
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);
230231
level++;
231232
}
232233

233234
// 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+
}
238241
level++;
239242

240243
return level;
@@ -268,7 +271,7 @@ inline void SuRFBuilder::moveToNextItemSlot(const level_t level) {
268271
}
269272
}
270273

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) {
272275
// level should be at most equal to tree height
273276
if (level >= getTreeHeight())
274277
addLevel();
@@ -284,6 +287,7 @@ void SuRFBuilder::insertKeyByte(const char c, const level_t level, const bool is
284287
setBit(louds_bits_[level], getNumItems(level) - 1);
285288
node_counts_[level]++;
286289
}
290+
is_last_item_terminator_[level] = is_term;
287291

288292
moveToNextItemSlot(level);
289293
}

0 commit comments

Comments
 (0)