Created
July 7, 2022 17:53
-
-
Save honi/dd1206d4bfe16672f145155662dab004 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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