MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / Compact

Method Compact

structure/trie/trie.go:99–107  ·  view source on GitHub ↗

Compact will remove unecessay nodes, reducing the capacity, returning true if node n itself should be removed.

()

Source from the content-addressed store, hash-verified

97
98// Compact will remove unecessay nodes, reducing the capacity, returning true if node n itself should be removed.
99func (n *Node) Compact() (remove bool) {
100
101 for r, c := range n.children {
102 if c.Compact() {
103 delete(n.children, r)
104 }
105 }
106 return !n.isLeaf && len(n.children) == 0
107}

Callers 3

TestTrieRemoveFunction · 0.95

Calls

no outgoing calls

Tested by 3

TestTrieRemoveFunction · 0.76