Skip to content

Commit 54fe109

Browse files
committed
update weightedrand module to v2
1 parent 3fb0d01 commit 54fe109

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ element to be selected are not equal, but rather defined by relative "weights"
1616
```go
1717
import (
1818
/* ...snip... */
19-
"github.com/mroth/weightedrand"
19+
"github.com/mroth/weightedrand/v2"
2020
)
2121

2222
func main() {
@@ -73,6 +73,11 @@ right choice! If you are only picking from the same distribution once,
7373
`randutil` will be faster. `weightedrand` optimizes for repeated calls at the
7474
expense of some initialization time and memory storage.
7575

76+
## Requirements
77+
78+
weightedrand >= v2 requires go1.18 or greater. For support on earlier versions
79+
of go, use weightedrand [v1](https://github.com/mroth/weightedrand/tree/v1).
80+
7681
## Credits
7782

7883
To better understand the algorithm used in this library (as well as the one used

examples/compbench/bench_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010

1111
"github.com/jmcvetta/randutil"
12-
"github.com/mroth/weightedrand"
12+
"github.com/mroth/weightedrand/v2"
1313
)
1414

1515
const BMMinChoices = 10
@@ -98,9 +98,9 @@ func BenchmarkSingle(b *testing.B) {
9898
})
9999
}
100100

101-
func mockChoices(tb testing.TB, n int) []weightedrand.Choice {
101+
func mockChoices(tb testing.TB, n int) []weightedrand.Choice[rune, uint] {
102102
tb.Helper()
103-
choices := make([]weightedrand.Choice, 0, n)
103+
choices := make([]weightedrand.Choice[rune, uint], 0, n)
104104
for i := 0; i < n; i++ {
105105
s := '🥑'
106106
w := rand.Intn(10)
@@ -110,7 +110,7 @@ func mockChoices(tb testing.TB, n int) []weightedrand.Choice {
110110
return choices
111111
}
112112

113-
func convertChoices(tb testing.TB, cs []weightedrand.Choice) []randutil.Choice {
113+
func convertChoices(tb testing.TB, cs []weightedrand.Choice[rune, uint]) []randutil.Choice {
114114
tb.Helper()
115115
res := make([]randutil.Choice, len(cs))
116116
for i, c := range cs {

examples/compbench/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module github.com/mroth/weightedrand/examples/compbench
22

3-
go 1.15
3+
go 1.18
44

55
require (
66
github.com/jmcvetta/randutil v0.0.0-20150817122601-2bb1b664bcff
7-
github.com/mroth/weightedrand v0.0.0
7+
github.com/mroth/weightedrand/v2 v2.0.0
88
)
99

10-
replace github.com/mroth/weightedrand => ../..
10+
replace github.com/mroth/weightedrand/v2 => ../..

examples/frequency/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"math/rand"
77
"time"
88

9-
"github.com/mroth/weightedrand"
9+
"github.com/mroth/weightedrand/v2"
1010
)
1111

1212
func main() {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module github.com/mroth/weightedrand
1+
module github.com/mroth/weightedrand/v2
22

33
go 1.18

0 commit comments

Comments
 (0)