Skip to content

Ternary search tree panic on prefix search #16

@Salve

Description

@Salve

https://github.com/timtadh/data-structures/blob/master/trie/tst.go#L173

This line panics if the prefix being searched for is longer than the capacity of the key being checked, e.g. this panics:

	tst := trie.New()
	tst.Put([]byte("abc"), nil)
	_, _, _ = tst.PrefixFind([]byte("abcxxxxxxxxxxxxxxxxxxxx"))()
panic: runtime error: slice bounds out of range [:23] with capacity 8
...
github.com/timtadh/data-structures/trie.(*TST).PrefixFind(0xc000092760?, {0xc000092749, 0x17, 0x3?})
	/go/pkg/mod/github.com/timtadh/[email protected]/trie/tst.go:173 +0x297
...

Since the slice operation succeeds if the index is larger than the length but smaller than the capacity this doesn't always occur for prefixes that are slightly longer than the found leaf node.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions