@@ -3,7 +3,7 @@ package hostutils
33import (
44 "bytes"
55 "fmt"
6- "golang.org/x/exp/ slices"
6+ "slices"
77 "strconv"
88)
99
@@ -47,8 +47,8 @@ func Pack(hosts []string) []string {
4747 for _ , host := range regHosts {
4848 uniqHosts = append (uniqHosts , parseHost (host ))
4949 }
50- slices .SortFunc (uniqHosts , func (a , b * host ) bool {
51- return a .Less (b )
50+ slices .SortFunc (uniqHosts , func (a , b * host ) int {
51+ return a .CompareTo (b )
5252 })
5353
5454 result := make ([]string , 0 , len (uniqHosts ))
@@ -224,41 +224,42 @@ func (h *host) appendToken(token string, digitMode bool) {
224224}
225225
226226func (h * host ) Less (rhs * host ) bool {
227+ return h .CompareTo (rhs ) < 0
228+ }
229+
230+ func (h * host ) CompareTo (rhs * host ) int {
227231 m := min (len (h .NonDigits ), len (rhs .NonDigits ))
228232 for i := 0 ; i < m ; i ++ {
229233 if h .NonDigits [i ] < rhs .NonDigits [i ] {
230- return true
234+ return - 1
231235 }
232236 if h .NonDigits [i ] > rhs .NonDigits [i ] {
233- return false
237+ return 1
234238 }
235239 }
236240 if len (h .NonDigits ) < len (rhs .NonDigits ) {
237- return true
241+ return - 1
238242 }
239243 if len (h .NonDigits ) > len (rhs .NonDigits ) {
240- return false
244+ return 1
241245 }
242246
243247 m = min (len (h .Digits ), len (rhs .Digits ))
244248 for i := m - 1 ; i >= 0 ; i -- {
245249 if h .Digits [i ].Digit < rhs .Digits [i ].Digit {
246- return true
250+ return - 1
247251 }
248252 if h .Digits [i ].Digit > rhs .Digits [i ].Digit {
249- return false
253+ return 1
250254 }
251255 if h .Digits [i ].Value < rhs .Digits [i ].Value {
252- return true
256+ return - 1
253257 }
254258 if h .Digits [i ].Value > rhs .Digits [i ].Value {
255- return false
259+ return 1
256260 }
257261 }
258- if len (h .Digits ) < len (rhs .Digits ) {
259- return true
260- }
261- return false
262+ return len (h .Digits ) - len (rhs .Digits )
262263}
263264
264265func isDigit (c rune ) bool {
0 commit comments