Skip to content

Go 1.22 #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, windows-2022, macos-12, macos-14]
go: [ '1.21', '1.22' ]
os: [ubuntu-24.04, windows-2022, macos-14]
go: [ '1.22', '1.23' ]
exclude:
# Only latest Go version for Windows and MacOS.
- os: windows-2022
go: '1.21'
- os: macos-12
go: '1.21'
go: '1.22'
- os: macos-14
go: '1.21'
# Exclude latest Go version for Ubuntu as Coverage uses it.
- os: ubuntu-22.04
go: '1.22'
# Exclude latest Go version for Ubuntu as Coverage uses it.
- os: ubuntu-24.04
go: '1.23'
fail-fast: false
steps:
- name: Setup go
Expand All @@ -47,7 +45,7 @@ jobs:

cover:
name: Coverage
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04

env:
CGO_ENABLED: 1
Expand All @@ -60,7 +58,7 @@ jobs:
uses: actions/setup-go@v5
with:
cache: true
go-version: 1.22
go-version: 1.23

- name: Test and write coverage profile
run: go test -coverprofile=coverage.txt -covermode=atomic ./...
Expand All @@ -76,7 +74,7 @@ jobs:

lint:
name: lint
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
Expand Down
14 changes: 7 additions & 7 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func BenchmarkSortByWeight_fnv_1000(b *testing.B) {

func benchmarkSort(b *testing.B, n int, object []byte) uint64 {
servers := make([]hashableUint64, n)
for i := uint64(0); i < uint64(len(servers)); i++ {
servers[i] = hashableUint64(i)
for i := range servers {
servers[i] = hashableUint64(uint64(i))
}

oHash := hashableUint64(WrapBytes(object).Hash())
Expand All @@ -38,7 +38,7 @@ func benchmarkSort(b *testing.B, n int, object []byte) uint64 {
b.ReportAllocs()

var x uint64
for i := 0; i < b.N; i++ {
for range b.N {
Sort(servers, oHash)
x += servers[0].Hash()
}
Expand All @@ -48,9 +48,9 @@ func benchmarkSort(b *testing.B, n int, object []byte) uint64 {
func benchmarkSortByWeight(b *testing.B, n int, object []byte) uint64 {
servers := make([]hashableUint64, n)
weights := make([]float64, n)
for i := uint64(0); i < uint64(len(servers)); i++ {
weights[i] = float64(uint64(n)-i) / float64(n)
servers[i] = hashableUint64(i)
for i := range servers {
weights[i] = float64(uint64(n-i)) / float64(n)
servers[i] = hashableUint64(uint64(i))
}

oHash := hashableUint64(WrapBytes(object).Hash())
Expand All @@ -59,7 +59,7 @@ func benchmarkSortByWeight(b *testing.B, n int, object []byte) uint64 {
b.ReportAllocs()

var x uint64
for i := 0; i < b.N; i++ {
for range b.N {
SortWeighted(servers, weights, oHash)
x += servers[0].Hash()
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nspcc-dev/hrw/v2

go 1.21
go 1.22

require (
github.com/stretchr/testify v1.9.0
Expand Down
6 changes: 3 additions & 3 deletions hrw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ func TestDistribution(t *testing.T) {
key = make([]byte, 16)
)

for i = 0; i < size; i++ {
for i = range size {
nodes[i] = i
}

for i = 0; i < keys; i++ {
for i = range keys {
binary.BigEndian.PutUint64(key, i+size)
nodesHashed := wrapUint64(nodes[:])
Sort(nodesHashed, WrapBytes(key))
Expand All @@ -119,7 +119,7 @@ func TestDistribution(t *testing.T) {
key = make([]byte, 16)
)

for i = 0; i < keys; i++ {
for i = range keys {
binary.BigEndian.PutUint64(key, i+size)
hash := WrapBytes(key).Hash()
counts[hash]++
Expand Down
Loading