Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gaissmai committed Nov 8, 2024
1 parent 4beaabf commit 21c1ea8
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 216 deletions.
2 changes: 1 addition & 1 deletion deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (t *Table[V]) EachLookupPrefix(pfx netip.Prefix, yield func(pfx netip.Prefi
n = stack[depth]

// microbenchmarking
if len(n.prefixes) == 0 {
if n.prefixes.count() == 0 {
continue
}

Expand Down
26 changes: 13 additions & 13 deletions dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (n *node[V]) dumpRec(w io.Writer, path [16]byte, depth int, is4 bool) {
// the node may have childs, the rec-descent monster starts
for i, addr := range n.allChildAddrs(addrBacking) {
octet := byte(addr)
child := n.children[i]
child := n.children.vals[i]
path[depth] = octet

child.dumpRec(w, path, depth+1, is4)
Expand All @@ -98,16 +98,16 @@ func (n *node[V]) dump(w io.Writer, path [16]byte, depth int, is4 bool) {
fmt.Fprintf(w, "\n%s[%s] depth: %d path: [%s] / %d\n",
indent, n.hasType(), depth, ipStridePath(path, depth, is4), bits)

if nPfxLen := len(n.prefixes); nPfxLen != 0 {
if nPfxCount := n.prefixes.count(); nPfxCount != 0 {
// make backing array, no heap allocs
idxBackingArray := [maxNodePrefixes]uint{}
allIndices := n.allStrideIndexes(idxBackingArray[:])

// print the baseIndices for this node.
fmt.Fprintf(w, "%sindexs(#%d): %v\n", indent, nPfxLen, allIndices)
fmt.Fprintf(w, "%sindexs(#%d): %v\n", indent, nPfxCount, allIndices)

// print the prefixes for this node
fmt.Fprintf(w, "%sprefxs(#%d):", indent, nPfxLen)
fmt.Fprintf(w, "%sprefxs(#%d):", indent, nPfxCount)

for _, idx := range allIndices {
octet, pfxLen := idxToPfx(idx)
Expand All @@ -117,16 +117,16 @@ func (n *node[V]) dump(w io.Writer, path [16]byte, depth int, is4 bool) {
fmt.Fprintln(w)

// print the values for this node
fmt.Fprintf(w, "%svalues(#%d):", indent, nPfxLen)
fmt.Fprintf(w, "%svalues(#%d):", indent, nPfxCount)

for _, val := range n.prefixes {
for _, val := range n.prefixes.vals {
fmt.Fprintf(w, " %v", val)
}

fmt.Fprintln(w)
}

if childs := len(n.children); childs != 0 {
if childs := n.children.count(); childs != 0 {
// print the childs for this node
fmt.Fprintf(w, "%schilds(#%d):", indent, childs)

Expand Down Expand Up @@ -197,22 +197,22 @@ func (nt nodeType) String() string {

// hasType returns the nodeType.
func (n *node[V]) hasType() nodeType {
lenPefixes := len(n.prefixes)
lenChilds := len(n.children)
prefixCount := n.prefixes.count()
childCount := n.children.count()

if lenPefixes == 0 && lenChilds != 0 {
if prefixCount == 0 && childCount != 0 {
return intermediateNode
}

if lenPefixes == 0 && lenChilds == 0 {
if prefixCount == 0 && childCount == 0 {
return nullNode
}

if lenPefixes != 0 && lenChilds == 0 {
if prefixCount != 0 && childCount == 0 {
return leafNode
}

if lenPefixes != 0 && lenChilds != 0 {
if prefixCount != 0 && childCount != 0 {
return fullNode
}

Expand Down
Loading

0 comments on commit 21c1ea8

Please sign in to comment.