Batch #4792 by youko: 0 byte-identical, 1 confirmed by peer review. - fn_45446 LexiconSerializer::Insert: logic confirmed by peer review Peer-reviewed-by: eAthena, alisonrag, KWDev, Bruwuno Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). Adds to the build: Source/LexiconTrie.cpp
64 lines
1.4 KiB
C++
64 lines
1.4 KiB
C++
#include "Utility/Lexicon/LexiconSerializer.h"
|
|
|
|
// OFFSET: 0x00AC3EB0
|
|
// FUNCTION: fn_45446
|
|
bool LexiconSerializer::Insert(const unsigned char* word, int length) {
|
|
int index = 0;
|
|
if (length == 0) {
|
|
return false;
|
|
}
|
|
|
|
if (this->wordCount == 0) {
|
|
this->root = new LexiconNode;
|
|
this->root->child = nullptr;
|
|
this->root->sibling = nullptr;
|
|
this->root->value = word[0];
|
|
this->root->terminal = 0;
|
|
++this->nodeCount;
|
|
}
|
|
|
|
LexiconNode* node = this->root;
|
|
for (;;) {
|
|
if (node->value != word[index]) {
|
|
LexiconNode** link = &node->sibling;
|
|
node = *link;
|
|
if (node != nullptr && node->value <= word[index]) {
|
|
continue;
|
|
}
|
|
|
|
node = new LexiconNode;
|
|
++this->nodeCount;
|
|
node->value = word[index];
|
|
node->sibling = *link;
|
|
node->child = nullptr;
|
|
node->terminal = 0;
|
|
*link = node;
|
|
}
|
|
|
|
for (;;) {
|
|
if (++index == length) {
|
|
if (node->terminal != 0) {
|
|
return false;
|
|
}
|
|
|
|
node->terminal = 1;
|
|
++this->wordCount;
|
|
return true;
|
|
}
|
|
|
|
LexiconNode** link = &node->child;
|
|
node = *link;
|
|
if (node != nullptr && node->value <= word[index]) {
|
|
break;
|
|
}
|
|
|
|
node = new LexiconNode;
|
|
++this->nodeCount;
|
|
node->value = word[index];
|
|
node->sibling = *link;
|
|
node->child = nullptr;
|
|
node->terminal = 0;
|
|
*link = node;
|
|
}
|
|
}
|
|
}
|