summaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/table/table.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@gmail.com>2019-10-25 20:33:59 +0900
committerFUJITA Tomonori <fujita.tomonori@gmail.com>2019-10-25 20:38:33 +0900
commitb4e2d9e440a4eb6d3091a7c586d2e55b69ec968a (patch)
tree68af74b393dda96a33d47a995b8c3f12680e51e2 /internal/pkg/table/table.go
parent6e81f596b1e924337470417cf1e3faa3260308da (diff)
table: replace radix with crit-bit algo for longer-prefixes search
faster and less memory usage. Now go-radix has gone. Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Diffstat (limited to 'internal/pkg/table/table.go')
-rw-r--r--internal/pkg/table/table.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/internal/pkg/table/table.go b/internal/pkg/table/table.go
index 40eab0f7..bfcf2059 100644
--- a/internal/pkg/table/table.go
+++ b/internal/pkg/table/table.go
@@ -22,7 +22,7 @@ import (
"strings"
"unsafe"
- "github.com/armon/go-radix"
+ "github.com/k-sone/critbitgo"
"github.com/osrg/gobgp/pkg/packet/bgp"
log "github.com/sirupsen/logrus"
)
@@ -212,14 +212,13 @@ func (t *Table) GetLongerPrefixDestinations(key string) ([]*Destination, error)
if err != nil {
return nil, err
}
- k := CidrToRadixkey(prefix.String())
- r := radix.New()
+ r := critbitgo.NewNet()
for _, dst := range t.GetDestinations() {
- r.Insert(AddrToRadixkey(dst.nlri), dst)
+ r.Add(nlriToIPNet(dst.nlri), dst)
}
- r.WalkPrefix(k, func(s string, v interface{}) bool {
+ r.WalkPrefix(prefix, func(_ *net.IPNet, v interface{}) bool {
results = append(results, v.(*Destination))
- return false
+ return true
})
default:
for _, dst := range t.GetDestinations() {