Skip to content

Commit

Permalink
update weightedrand module to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mroth committed Nov 13, 2022
1 parent 3fb0d01 commit 54fe109
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ element to be selected are not equal, but rather defined by relative "weights"
```go
import (
/* ...snip... */
"github.com/mroth/weightedrand"
"github.com/mroth/weightedrand/v2"
)

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

## Requirements

weightedrand >= v2 requires go1.18 or greater. For support on earlier versions
of go, use weightedrand [v1](https://github.com/mroth/weightedrand/tree/v1).

## Credits

To better understand the algorithm used in this library (as well as the one used
Expand Down
8 changes: 4 additions & 4 deletions examples/compbench/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/jmcvetta/randutil"
"github.com/mroth/weightedrand"
"github.com/mroth/weightedrand/v2"
)

const BMMinChoices = 10
Expand Down Expand Up @@ -98,9 +98,9 @@ func BenchmarkSingle(b *testing.B) {
})
}

func mockChoices(tb testing.TB, n int) []weightedrand.Choice {
func mockChoices(tb testing.TB, n int) []weightedrand.Choice[rune, uint] {
tb.Helper()
choices := make([]weightedrand.Choice, 0, n)
choices := make([]weightedrand.Choice[rune, uint], 0, n)
for i := 0; i < n; i++ {
s := '🥑'
w := rand.Intn(10)
Expand All @@ -110,7 +110,7 @@ func mockChoices(tb testing.TB, n int) []weightedrand.Choice {
return choices
}

func convertChoices(tb testing.TB, cs []weightedrand.Choice) []randutil.Choice {
func convertChoices(tb testing.TB, cs []weightedrand.Choice[rune, uint]) []randutil.Choice {
tb.Helper()
res := make([]randutil.Choice, len(cs))
for i, c := range cs {
Expand Down
6 changes: 3 additions & 3 deletions examples/compbench/go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/mroth/weightedrand/examples/compbench

go 1.15
go 1.18

require (
github.com/jmcvetta/randutil v0.0.0-20150817122601-2bb1b664bcff
github.com/mroth/weightedrand v0.0.0
github.com/mroth/weightedrand/v2 v2.0.0
)

replace github.com/mroth/weightedrand => ../..
replace github.com/mroth/weightedrand/v2 => ../..
2 changes: 1 addition & 1 deletion examples/frequency/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"math/rand"
"time"

"github.com/mroth/weightedrand"
"github.com/mroth/weightedrand/v2"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/mroth/weightedrand
module github.com/mroth/weightedrand/v2

go 1.18

0 comments on commit 54fe109

Please sign in to comment.