Skip to content

Commit

Permalink
internal: remove fastrand
Browse files Browse the repository at this point in the history
This package is no longer necessary, as in `math/rand/v2` the
`rand.Uint32` function is equivalent.
  • Loading branch information
RaduBerinde committed Oct 8, 2024
1 parent 50f3858 commit e1b330b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 131 deletions.
4 changes: 2 additions & 2 deletions internal/arenaskl/skl.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ package arenaskl // import "github.com/cockroachdb/pebble/internal/arenaskl"

import (
"math"
"math/rand/v2"
"runtime"
"sync/atomic"
"unsafe"

"github.com/cockroachdb/errors"
"github.com/cockroachdb/pebble/internal/base"
"github.com/cockroachdb/pebble/internal/fastrand"
)

const (
Expand Down Expand Up @@ -337,7 +337,7 @@ func (s *Skiplist) newNode(
}

func (s *Skiplist) randomHeight() uint32 {
rnd := fastrand.Uint32()
rnd := rand.Uint32()

h := uint32(1)
for h < maxHeight && rnd <= probabilities[h] {
Expand Down
17 changes: 0 additions & 17 deletions internal/fastrand/fastrand.go

This file was deleted.

107 changes: 0 additions & 107 deletions internal/fastrand/fastrand_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions internal/invariants/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

package invariants

import "github.com/cockroachdb/pebble/internal/fastrand"
import "math/rand/v2"

// Sometimes returns true percent% of the time if we were built with the
// "invariants" of "race" build tags
func Sometimes(percent int) bool {
return Enabled && fastrand.Uint32()%100 < uint32(percent)
return Enabled && rand.Uint32N(100) < uint32(percent)
}
6 changes: 3 additions & 3 deletions iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"bytes"
"context"
"io"
"math/rand/v2"
"sync"
"unsafe"

"github.com/cockroachdb/errors"
"github.com/cockroachdb/pebble/internal/base"
"github.com/cockroachdb/pebble/internal/bytealloc"
"github.com/cockroachdb/pebble/internal/fastrand"
"github.com/cockroachdb/pebble/internal/humanize"
"github.com/cockroachdb/pebble/internal/invariants"
"github.com/cockroachdb/pebble/internal/keyspan"
Expand Down Expand Up @@ -810,14 +810,14 @@ func (i *Iterator) maybeSampleRead() {
}
bytesRead := uint64(len(i.key) + i.value.Len())
for i.readSampling.bytesUntilReadSampling < bytesRead {
i.readSampling.bytesUntilReadSampling += uint64(fastrand.Uint32n(2 * uint32(samplingPeriod)))
i.readSampling.bytesUntilReadSampling += uint64(rand.Uint32N(2 * uint32(samplingPeriod)))
// The block below tries to adjust for the case where this is the
// first read in a newly-opened iterator. As bytesUntilReadSampling
// starts off at zero, we don't want to sample the first read of
// every newly-opened iterator, but we do want to sample some of them.
if !i.readSampling.initialSamplePassed {
i.readSampling.initialSamplePassed = true
if fastrand.Uint32n(uint32(i.readSampling.bytesUntilReadSampling)) > uint32(bytesRead) {
if rand.Uint32N(uint32(i.readSampling.bytesUntilReadSampling)) > uint32(bytesRead) {
continue
}
}
Expand Down

0 comments on commit e1b330b

Please sign in to comment.