Skip to content

Commit

Permalink
factor out node.isEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
gaissmai committed Jan 29, 2024
1 parent dd39020 commit 0cb0daf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func newNode[V any]() *node[V] {
}
}

// isEmpty returns true if node has neither prefixes nor children.
func (n *node[V]) isEmpty() bool {
return len(n.prefixes.values) == 0 && len(n.children.nodes) == 0
}

// ################## prefixes ##################################

// rank is the key of the popcount compression algorithm,
Expand Down
7 changes: 3 additions & 4 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,9 @@ func (t *Table[V]) Delete(pfx netip.Prefix) {
break
}

// is this an empty node?
if len(n.prefixes.values) == 0 && len(n.children.nodes) == 0 {

// purge this node from parents childs
// an empty node?
if n.isEmpty() {
// purge this node from parents children
parent := pathStack[depth-1]
parent.children.delete(uint(bs[depth-1]))
}
Expand Down

0 comments on commit 0cb0daf

Please sign in to comment.