1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-18 05:25:23 +00:00

sort.Interface for CIDR list

This commit is contained in:
Darien Raymond 2018-11-01 08:44:11 +01:00
parent 65aae7b1d0
commit ee74256aac
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -6,6 +6,41 @@ import (
"v2ray.com/core/common/net"
)
type CIDRList []*CIDR
func (l *CIDRList) Len() int {
return len(*l)
}
func (l *CIDRList) Less(i int, j int) bool {
ci := (*l)[i]
cj := (*l)[j]
if len(ci.Ip) < len(cj.Ip) {
return true
}
if len(ci.Ip) > len(cj.Ip) {
return false
}
for k := 0; k < len(ci.Ip); k++ {
if ci.Ip[k] < cj.Ip[k] {
return true
}
if ci.Ip[k] > cj.Ip[k] {
return false
}
}
return ci.Prefix < cj.Prefix
}
func (l *CIDRList) Swap(i int, j int) {
(*l)[i], (*l)[j] = (*l)[j], (*l)[i]
}
type Rule struct {
Tag string
Condition Condition