gaissmai / bart

The Balanced Routing Table is an adaptation of D. Knuth's ART algorithm combined with popcount level compression and backtracking. It is somewhat slower than ART, but requires considerably less memory.
MIT License
26 stars 3 forks source link

how to get prefix by ip? #59

Closed farwydi closed 2 months ago

farwydi commented 2 months ago

Hello You recently removed the prefix return value from the lookup function.

How can I now get the prefix from the IP?

old:

Lookup(ip netip.Addr) (lpm netip.Prefix, val V, ok bool)

new:

Lookup(ip netip.Addr) (val V, ok bool)

I see only this option

bart.Table[netip.Prefix]
tobez commented 2 months ago

I would imagine

(lpm, val, ok) := t.LookupPrefixLPM(netip.PrefixFrom(ip, ip.BitLen())

should do the trick, no?

EDIT: take the fact that ip.Prefix returns two values into account. EDIT2: just use PrefixFrom()

gaissmai commented 2 months ago

use LookupPrefixLPM and read the docstring

If LookupPrefixLPM is to be used for IP addresses, they must be converted to /32 or /128 prefixes.

gaissmai commented 2 months ago

what is your use case? The fastest method is to add the prefix to the payload and unwrap it from the returned value.

I added LookupLPM in the devel branch, but building the lpm out of the trie is expensive (20-30% slower than Lookup)

gaissmai commented 2 months ago

no feedback, closing the issue