list.go 335 Bytes
Newer Older
Petar Maymounkov's avatar
Petar Maymounkov committed
1 2 3
package trie

import (
tavit ohanian's avatar
tavit ohanian committed
4
	"gitlab.dms3.io/p2p/go-p2p-xor/key"
Petar Maymounkov's avatar
Petar Maymounkov committed
5 6 7 8 9 10 11 12 13 14 15 16 17
)

// List returns a list of all keys in the trie.
func (trie *Trie) List() []key.Key {
	switch {
	case trie.IsEmptyLeaf():
		return nil
	case trie.IsNonEmptyLeaf():
		return []key.Key{trie.Key}
	default:
		return append(trie.Branch[0].List(), trie.Branch[1].List()...)
	}
}