Skip to content

Commit 578e13e

Browse files
authored
Bump up golang.org/x/exp (#10)
1 parent 2670f48 commit 578e13e

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 2.0.3 (2024-06-05)
4+
5+
* Bump up `golang.org/x/exp` to `v0.0.0-20240604190554-fc45aab8b7f8`
6+
37
## 2.0.2 (2023-04-18)
48

59
* Fix a bug on sorting, which cause `Pack` don't work as expected

v2/go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ module github.com/Wing924/hostutils/v2
33
go 1.20
44

55
require (
6-
github.com/stretchr/testify v1.2.2
7-
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
6+
github.com/stretchr/testify v1.9.0
7+
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8
88
)
99

1010
require (
1111
github.com/davecgh/go-spew v1.1.1 // indirect
1212
github.com/pmezard/go-difflib v1.0.0 // indirect
13+
gopkg.in/yaml.v3 v3.0.1 // indirect
1314
)

v2/go.sum

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
44
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5-
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
6-
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
7-
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug=
8-
golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
5+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
6+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7+
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 h1:LoYXNGAShUG3m/ehNk4iFctuhGX/+R1ZpfJ4/ia80JM=
8+
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI=
9+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
10+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
11+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
12+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

v2/pack.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package hostutils
33
import (
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

226226
func (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

264265
func isDigit(c rune) bool {

0 commit comments

Comments
 (0)