Skip to content
Closed
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
18 changes: 11 additions & 7 deletions trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,17 @@ func (t *Trie) delete(n node, prefix, key []byte) (bool, node, error) {
// value that is left in n or -2 if n contains at least two
// values.
pos := -1
for i, cld := range &n.Children {
if cld != nil {
if pos == -1 {
pos = i
} else {
pos = -2
break
if nn != nil {
pos = -2
} else {
Comment on lines +418 to +420
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this hard to intuitively verify. I think it might be easier to follow if you break here, so replace this with

if nn != nil{	
	// n still contains at least two values and cannot be reduced.
	return true, n, nil
}

As far as I can tell, that^ change should be equivalent with your change. However, looking at it, I still don't see why this is necessarily true/correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if nn != nil, nn must be a child of n, which means that n itself doesn't need to be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And before the deletion, there must be another child of n.

for i, cld := range &n.Children {
if cld != nil {
if pos == -1 {
pos = i
} else {
pos = -2
break
}
}
}
}
Expand Down