-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove method fails for single / root key #4
Comments
It seems if you only have one key, the remove fails. Good catch, I'll push a fix up soon. |
I slightly modified the code with
|
I think I'd change the above to something like: if n == t.root {
t.root = &Node{}
}
if len(....) {
... If you wouldn't mind putting together a PR and adding a test to catch the bug I'd definitely pull it in. |
func (t *Trie) Remove(key string) {
var (
i int
rs = []rune(key)
node = findNode(t.Root(), []rune(key))
)
t.size--
for n := node.Parent(); n != nil; n = n.Parent() {
i++
if len(n.Children()) > 1 {
r := rs[len(rs)-i]
n.RemoveChild(r)
break
}
}
} this will core dump when node is nil(key that isn't exist will crash) |
Derek -- I will put a PR together for this |
See this http://play.golang.org/p/of8h4uJ5jR
After calling Remove, the trie still finds the key.
The text was updated successfully, but these errors were encountered: