本文整理汇总了Golang中sort.StringSlice.Less方法的典型用法代码示例。如果您正苦于以下问题:Golang StringSlice.Less方法的具体用法?Golang StringSlice.Less怎么用?Golang StringSlice.Less使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sort.StringSlice
的用法示例。
在下文中一共展示了StringSlice.Less方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Less
func (d destinations) Less(i, j int) bool {
switch d[i].routeFamily {
case bgp.RF_FS_IPv4_UC, bgp.RF_FS_IPv6_UC, bgp.RF_FS_IPv4_VPN, bgp.RF_FS_IPv6_VPN, bgp.RF_FS_L2_VPN:
var s, t *bgp.FlowSpecNLRI
switch d[i].routeFamily {
case bgp.RF_FS_IPv4_UC:
s = &d[i].nlri.(*bgp.FlowSpecIPv4Unicast).FlowSpecNLRI
t = &d[j].nlri.(*bgp.FlowSpecIPv4Unicast).FlowSpecNLRI
case bgp.RF_FS_IPv6_UC:
s = &d[i].nlri.(*bgp.FlowSpecIPv6Unicast).FlowSpecNLRI
t = &d[j].nlri.(*bgp.FlowSpecIPv6Unicast).FlowSpecNLRI
case bgp.RF_FS_IPv4_VPN:
s = &d[i].nlri.(*bgp.FlowSpecIPv4VPN).FlowSpecNLRI
t = &d[j].nlri.(*bgp.FlowSpecIPv4VPN).FlowSpecNLRI
case bgp.RF_FS_IPv6_VPN:
s = &d[i].nlri.(*bgp.FlowSpecIPv6VPN).FlowSpecNLRI
t = &d[j].nlri.(*bgp.FlowSpecIPv6VPN).FlowSpecNLRI
case bgp.RF_FS_L2_VPN:
s = &d[i].nlri.(*bgp.FlowSpecL2VPN).FlowSpecNLRI
t = &d[j].nlri.(*bgp.FlowSpecL2VPN).FlowSpecNLRI
}
if r, _ := bgp.CompareFlowSpecNLRI(s, t); r >= 0 {
return true
} else {
return false
}
default:
strings := sort.StringSlice{d[i].nlri.String(), d[j].nlri.String()}
return strings.Less(0, 1)
}
}
示例2: Less
func (p paths) Less(i, j int) bool {
if p[i].Nlri.String() == p[j].Nlri.String() {
if p[i].Best {
return true
}
}
strings := sort.StringSlice{cidr2prefix(p[i].Nlri.String()),
cidr2prefix(p[j].Nlri.String())}
return strings.Less(0, 1)
}
示例3: Less
// Less is part of sort.Interface. It is implemented by calling the "by" closure in the sorter.
func (s sortedVoices) Less(i, j int) bool {
var strs sort.StringSlice = []string{
s[i].instrument.Name(),
s[j].instrument.Name(),
}
return strs.Less(0, 1)
// sort.Strings(a)
}
示例4: Less
func (s *SortByNoiseAndText) Less(i, j int) bool {
if s.items[i].Noise < s.items[j].Noise {
return false
} else if s.items[i].Noise > s.items[j].Noise {
return true
} else if len(s.items[i].Runes) < len(s.items[j].Runes) {
return false
} else if len(s.items[i].Runes) > len(s.items[j].Runes) {
return true
} else {
ss := sort.StringSlice{s.items[i].Name, s.items[j].Name}
return ss.Less(0, 1)
}
}
示例5: Less
func (p peers) Less(i, j int) bool {
p1 := p[i].Conf.RemoteIp
p2 := p[j].Conf.RemoteIp
p1Isv4 := !strings.Contains(p1, ":")
p2Isv4 := !strings.Contains(p2, ":")
if p1Isv4 != p2Isv4 {
if p1Isv4 {
return true
}
return false
}
addrlen := 128
if p1Isv4 {
addrlen = 32
}
strings := sort.StringSlice{cidr2prefix(fmt.Sprintf("%s/%d", p1, addrlen)),
cidr2prefix(fmt.Sprintf("%s/%d", p2, addrlen))}
return strings.Less(0, 1)
}
示例6: Less
func (n neighbors) Less(i, j int) bool {
p1 := n[i].Config.NeighborAddress
p2 := n[j].Config.NeighborAddress
p1Isv4 := !strings.Contains(p1, ":")
p2Isv4 := !strings.Contains(p2, ":")
if p1Isv4 != p2Isv4 {
if p1Isv4 {
return true
}
return false
}
addrlen := 128
if p1Isv4 {
addrlen = 32
}
strings := sort.StringSlice{cidr2prefix(fmt.Sprintf("%s/%d", p1, addrlen)),
cidr2prefix(fmt.Sprintf("%s/%d", p2, addrlen))}
return strings.Less(0, 1)
}
示例7: Less
func (t tries) Less(i, j int) bool {
strings := sort.StringSlice{string(t[i].prefix), string(t[j].prefix)}
return strings.Less(0, 1)
}