Skip to content
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

crash test #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (t *Trie) Find(key string) (*Node, bool) {
}
node = node.Children()[nul]

if !node.term {
if node == nil || !node.term {
return nil, false
}

Expand All @@ -87,13 +87,17 @@ func (t *Trie) Find(key string) (*Node, bool) {

// Removes a key from the trie, ensuring that
// all bitmasks up to root are appropriately recalculated.
func (t *Trie) Remove(key string) {
func (t *Trie) Remove(key string) bool {
var (
i int
rs = []rune(key)
node = findNode(t.Root(), []rune(key))
)

if node == nil {
return false
}

t.size--
for n := node.Parent(); n != nil; n = n.Parent() {
i++
Expand All @@ -103,6 +107,8 @@ func (t *Trie) Remove(key string) {
break
}
}

return true
}

// Returns all the keys currently stored in the trie.
Expand Down Expand Up @@ -145,7 +151,8 @@ func (n *Node) NewChild(val rune, bitmask uint64, meta interface{}, term bool) *

func (n *Node) RemoveChild(r rune) {
delete(n.children, r)
for nd := n.parent; nd != nil; nd = nd.parent {

for nd := n; nd != nil; nd = nd.parent {
nd.mask ^= nd.mask
nd.mask |= uint64(1) << uint64(nd.val-'a')
for _, c := range nd.children {
Expand Down