Skip to content

Commit

Permalink
Merge pull request #234 from bio-routing/fix/pfxdedup
Browse files Browse the repository at this point in the history
Fix/pfxdedup
  • Loading branch information
hikhvar authored Oct 31, 2019
2 parents 9a2f84b + 2f52452 commit 02bfd00
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions net/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
gonet "net"
"strconv"
"strings"
"unsafe"

"github.com/bio-routing/bio-rd/net/api"
"github.com/google/btree"
Expand All @@ -26,11 +25,16 @@ func (p *Prefix) Dedup() *Prefix {

// Less compares prefixes for use in btree.Btree
func (p *Prefix) Less(other btree.Item) bool {
if uintptr(unsafe.Pointer(p.addr)) < uintptr(unsafe.Pointer(other.(*Prefix).addr)) {
switch p.addr.Compare(other.(*Prefix).addr) {
case 0:
return p.pfxlen < other.(*Prefix).pfxlen
case -1:
return true
case 1:
return false
}

return p.pfxlen < other.(*Prefix).pfxlen
return false
}

// DedupWithIP gets a copy of Prefix from the cache and dedups the IP part
Expand Down

0 comments on commit 02bfd00

Please sign in to comment.