| 1 | package Net::BART::LPM; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Net::BART::BitSet256; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Exporter 'import'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | our $VERSION = '0.01'; | |||||||||
| 9 | |||||||||||
| 10 | 1 | our @EXPORT_OK = qw(@LOOKUP_TBL); | |||||||||
| 11 | |||||||||||
| 12 | # Precomputed lookup table: for each base index [0..255], LOOKUP_TBL[idx] | ||||||||||
| 13 | # is a BitSet256 with idx and all its ancestors in the complete binary tree set. | ||||||||||
| 14 | # | ||||||||||
| 15 | # Ancestors are found by repeatedly right-shifting the index: | ||||||||||
| 16 | # idx -> idx>>1 -> idx>>2 -> ... -> 1 | ||||||||||
| 17 | # | ||||||||||
| 18 | # Used for O(1) longest-prefix-match at each trie node: | ||||||||||
| 19 | # intersection_top(node.prefixes.bitset, LOOKUP_TBL[octet_to_idx(octet)]) | ||||||||||
| 20 | |||||||||||
| 21 | 1 | our @LOOKUP_TBL; | |||||||||
| 22 | |||||||||||
| 23 | 1 | ▶ | sub _generate_lookup_tbl { | ||||||||
|
Subroutine
_generate_lookup_tbl: called CC=3 SCAR=11.0
| |||||||||||
| 24 | 1 | for my $idx (0 .. 255) { | |||||||||
| 25 | 256 | my $bs = Net::BART::BitSet256->new; | |||||||||
| 26 | 256 | my $i = $idx; | |||||||||
| 27 | 256 | ▶ | while ($i > 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 1793 | $bs->set($i); | |||||||||
| 29 | 1793 | $i >>= 1; | |||||||||
| 30 | } | ||||||||||
| 31 | 256 | $LOOKUP_TBL[$idx] = $bs; | |||||||||
| 32 | } | ||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 1 | _generate_lookup_tbl(); | |||||||||
| 36 | |||||||||||
| 37 | 1 | 1; | |||||||||