miekg / bitradix Goto Github PK
View Code? Open in Web Editor NEWA radix tree that branches on the bits in a key
A radix tree that branches on the bits in a key
During the use of the bitradix library, I encountered several problems using masks smaller than 0, there is maybe a problem in how the first bit is handled or how the root of the tree is initialized.
mask == 0
I added a default route 0.0.0.0/0 and checked serveral routes. Routes with the first bit set to 1 will fail:
AddRoute 0.0.0.0/0 (00000000000000000000000000000000), AS 10
(-1): 00000000000000000000000000000000/0 -> %!d(<nil>)
( 0): 00000000000000000000000000000000/0 -> 10
( 1): 00000000000000000000000000000000/0 -> %!d(<nil>)
Search 230.0.0.1/32 11100110000000000000000000000001/32
Expected 10, got %!d(<nil>) for 230.0.0.1/32s
Search 10.20.1.2/32 00001010000101000000000100000010/32
Search 10.21.0.1/32 00001010000101010000000000000001/32
Search 192.168.2.3/32 11000000101010000000001000000011/32
Expected 10, got %!d(<nil>) for 192.168.2.3/32s
mask == 1
Also a split range case produces a strange tree:
AddRoute 0.0.0.0/1 (00000000000000000000000000000000), AS 10
AddRoute 128.0.0.0/1 (10000000000000000000000000000000), AS 20
(-1): 00000000000000000000000000000000/1 -> 10
( 0): 00000000000000000000000000000000/0 -> %!d(<nil>)
( 1): 10000000000000000000000000000000/1 -> 20
Search 10.20.1.2/32 00001010000101000000000100000010/32
Expected 10, got %!d(<nil>) for 10.20.1.2/32s
Search 10.21.0.1/32 00001010000101010000000000000001/32
Expected 10, got %!d(<nil>) for 10.21.0.1/32s
Search 192.168.2.3/32 11000000101010000000001000000011/32
Search 230.0.0.1/32 11100110000000000000000000000001/32
mask >= 2
(works as expected)
AddRoute 0.0.0.0/2 (00000000000000000000000000000000), AS 10
AddRoute 64.0.0.0/2 (01000000000000000000000000000000), AS 20
AddRoute 128.0.0.0/2 (10000000000000000000000000000000), AS 30
AddRoute 255.0.0.0/2 (11000000000000000000000000000000), AS 41
(-1): 00000000000000000000000000000000/0 -> %!d(<nil>)
( 0): 00000000000000000000000000000000/0 -> %!d(<nil>)
( 1): 00000000000000000000000000000000/0 -> %!d(<nil>)
( 0): 00000000000000000000000000000000/2 -> 10
( 1): 01000000000000000000000000000000/2 -> 20
( 0): 10000000000000000000000000000000/2 -> 30
( 1): 11000000000000000000000000000000/2 -> 41
Search 10.44.2.2/32 00001010001011000000001000000010/32
Search 100.44.231.1/32 01100100001011001110011100000001/32
Search 140.44.0.3/32 10001100001011000000000000000011/32
Search 210.44.1.1/32 11010010001011000000000100000001/32
Does anyone have an idea how to solve this problem?
If routes have the same key but different ranges, the first route will be removed from the tree (or overwritten), but if and only if the range of the previous rule was larger than the range of the newer rule:
OK
AddRoute 10.0.0.0/14 (00001010000000000000000000000000), AS 11
AddRoute 10.20.0.0/14 (00001010000101000000000000000000), AS 20
AddRoute 10.0.0.2/8 (00001010000000000000000000000000), AS 10
NOT OK
This case produces wrong values for routes matching only the route with a larger range.:
AddRoute 10.0.0.2/8 (00001010000000000000000000000000), AS 10
AddRoute 10.0.0.0/14 (00001010000000000000000000000000), AS 11
AddRoute 10.20.0.0/14 (00001010000101000000000000000000), AS 20
(-1): 00000000000000000000000000000000/0 -> %!d(<nil>)
( 0): 00001010000000000000000000000000/14 -> 11
( 1): 00000000000000000000000000000000/0 -> %!d(<nil>)
( 0): 00001010000101000000000000000000/14 -> 20
Search 10.1.0.1/32 00001010000000010000000000000001/32
Search 10.20.1.2/32 00001010000101000000000100000010/32
Search 10.19.0.1/32 00001010000100110000000000000001/32
Expected 10, got 0 for 10.19.0.1/32 -- (10.19.0.1/32 should be in AS 10 - 10.0.0.2/8 but was 0)
Was the insert() function designed to work like this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.