Skip to content

Instantly share code, notes, and snippets.

@honi
Created July 7, 2022 17:53
Show Gist options
  • Save honi/dd1206d4bfe16672f145155662dab004 to your computer and use it in GitHub Desktop.
Save honi/dd1206d4bfe16672f145155662dab004 to your computer and use it in GitHub Desktop.
template<typename T>
vector<string> string_map<T>::keys() const {
vector<string> keys;
keys.reserve(_size);
_root->collectKeys("", &keys);
return keys;
}
template<typename T>
void string_map<T>::Node::collectKeys(const string& prefix, vector<string>* keys) {
if (value != nullptr) {
keys->push_back(prefix);
}
for (int c = 0; c < MAX_CHILDREN; c++) {
if (children[c] != nullptr) {
children[c]->collectKeys(prefix + char(c), keys);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment