Skip to content
Merged
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
9 changes: 7 additions & 2 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ package cuckoo

import (
"encoding/binary"
"math/rand"
_ "unsafe" // For linking fastrand.

metro "github.com/dgryski/go-metro"
)

// fastrand is a fast thread local random function.
//
//go:linkname fastrandn runtime.fastrandn
func fastrandn(n uint32) uint32

// randi returns either i1 or i2 randomly.
func randi(i1, i2 uint) uint {
if rand.Int31()%2 == 0 {
if fastrandn(2) == 0 {
return i1
}
return i2
Expand Down