Last active
September 14, 2022 03:33
-
-
Save 1gravity/5ee679ea64a15ed755e7b781aae476b3 to your computer and use it in GitHub Desktop.
Trie Optimized Insert
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
fun insert(key: String, value: Value) { | |
key.fold(root) { node, char -> | |
node.children[char] ?: Node<Value>().also { node.children[char] = it } | |
}.value = value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment