// Search the specified subtree for the specified key std::unique_ptr<Word> DiskBTree::findFrom(uint32_t id, std::string key) { if (id == 0) return nullptr; auto x = load(id); auto i = 0; while (i < x->KeyCount && key.compare(x->Keys[i]->key) > 0) { i++; comparisons++; } std::unique_ptr<Word> res; if (i < x->KeyCount && key.compare(x->Keys[i]->key) == 0) { comparisons += 2; // One for the last check of the while loop, and one for the if statement res = std::make_unique<Word>(x->Keys[i]->key, x->Keys[i]->count); } else if(!x->isLeaf) { res = findFrom(x->Children[i-1], key); } return res; }
SimpleString SimpleString::subStringFromTill(char startChar, char lastExcludedChar) const { size_t beginPos = find(startChar); if (beginPos == npos) return ""; size_t endPos = findFrom(beginPos, lastExcludedChar); if (endPos == npos) return subString(beginPos); return subString(beginPos, endPos - beginPos); }
SimpleString SimpleString::subStringFromTill(char startChar, char lastExcludedChar) const { int beginPos = find(startChar); if (beginPos < 0) return ""; int endPos = findFrom((size_t)beginPos, lastExcludedChar); if (endPos == -1) return subString((size_t)beginPos, size()); return subString((size_t)beginPos, (size_t) (endPos - beginPos)); }
size_t SimpleString::find(char ch) const { return findFrom(0, ch); }