Skip to content

Commit

Permalink
comment
Browse files Browse the repository at this point in the history
  • Loading branch information
gaissmai committed Jan 27, 2025
1 parent c771cbf commit a588580
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lpm_lookuptbl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package bart

import "github.com/gaissmai/bart/internal/bitset"

// lpmLookupTbl is the backtracking sequence as bitstring.
// lpmLookupTbl is the backtracking sequence in the complete binary tree as bitstring.
//
// for idx := 1; idx > 0; idx >>= 1 { b.Set(idx) }
//
// one shot bitset intersection algorithm:
// allows a one shot bitset intersection algorithm:
//
// func (n *node[V]) lpmTest(idx uint) bool {
// return n.prefixes.IntersectsAny(lpmLookupTbl[idx])
// }
//
// insted of a sequence of single bitset tests:
// instead of a sequence of single bitset tests:
//
// func (n *node[V]) lpmTest(idx uint) bool {
// for ; idx > 0; idx >>= 1 {
Expand Down
7 changes: 5 additions & 2 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,12 @@ func (n *node[V]) purgeAndCompress(parentStack []*node[V], childPath []byte, is4
// at this depth and returns (baseIdx, value, true) if a matching
// longest prefix exists, or ok=false otherwise.
//
// backtracking is fast, it's just a bitset test and, if found, one popcount.
// max steps in backtracking is the stride length.
// The prefixes in the stride form a complete binary tree (CBT) using the baseIndex function.
// In contrast to the ART algorithm, I do not use an allotment approach but map
// the backtracking in the CBT by a bitset operation with a precalculated backtracking path
// for the respective idx.
func (n *node[V]) lpmGet(idx uint) (baseIdx uint, val V, ok bool) {
// top is the idx of the longest-prefix-match
if top, ok := n.prefixes.IntersectionTop(lpmLookupTbl[idx]); ok {
return top, n.prefixes.MustGet(top), true
}
Expand Down

0 comments on commit a588580

Please sign in to comment.