internal

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MurmurHash3Sum

func MurmurHash3Sum(data []byte, seed uint32) uint32

func NewLockedRand

func NewLockedRand() *rand.Rand

NewLockedRand is just like NewRand except the returned value uses a mutex to enable safe usage from concurrent goroutines.

Despite having mutex overhead, this is better than using the global rand because you don't have to worry about other code linked into the same program that might be abusing the global rand:

  1. It is possible for code to call rand.Seed, which could cause issues with the quality of the pseudo-random number sequence.
  2. It is possible for code to make *heavy* use of the global rand, which can mean extensive lock contention on its mutex, which will slow down clients trying to generate a random number.

By creating a new locked *rand.Rand, nothing else will be using it and contending over the mutex except other code that has access to the same instance.

func NewMurmurHash3

func NewMurmurHash3(seed uint32) hash.Hash32

func NewRand

func NewRand() *rand.Rand

NewRand returns a properly seeded *rand.Rand. The seed is computed using the "hash/maphash" package, which can be used concurrently and is lock-free. Effectively, we're using runtime.fastrand to seed a new rand.Rand.

Types

type Clock

type Clock interface {
	After(d time.Duration) <-chan time.Time
	Sleep(d time.Duration)
	Now() time.Time
	Since(t time.Time) time.Duration
	NewTicker(d time.Duration) Ticker
	NewTimer(d time.Duration) Timer
	AfterFunc(d time.Duration, f func()) Timer
}

Clock is an interface that is compatible with the jonboulle/clockwork package. The intent is that clockwork package only be a dependency for tests, not for non-test code.

func NewRealClock

func NewRealClock() Clock

NewRealClock returns a Clock implementation where all methods delegate to the corresponding function in the time package.

type MurmurHash3

type MurmurHash3 struct {
	// contains filtered or unexported fields
}

func (*MurmurHash3) BlockSize

func (h *MurmurHash3) BlockSize() int

func (*MurmurHash3) Reset

func (h *MurmurHash3) Reset()

func (*MurmurHash3) Size

func (h *MurmurHash3) Size() int

func (*MurmurHash3) Sum

func (h *MurmurHash3) Sum(b []byte) []byte

func (*MurmurHash3) Sum32

func (h *MurmurHash3) Sum32() uint32

func (*MurmurHash3) Write

func (h *MurmurHash3) Write(data []byte) (int, error)

type Ticker

type Ticker interface {
	Chan() <-chan time.Time
	Reset(d time.Duration)
	Stop()
}

Ticker is an interface covering the behavior of a time.Ticker.

type Timer

type Timer interface {
	Chan() <-chan time.Time
	Reset(d time.Duration) bool
	Stop() bool
}

Timer is an interface covering the behavior of a time.Timer.

Directories

Path Synopsis
Package balancertesting provides some helper functions and types that can be useful when testing custom load balancer implementations.
Package balancertesting provides some helper functions and types that can be useful when testing custom load balancer implementations.
Package clocktest exists to allow interoperability with our Clock interface and the Clockwork FakeClock.
Package clocktest exists to allow interoperability with our Clock interface and the Clockwork FakeClock.
Package conns contains internal helpers relating to conn.Conns values.
Package conns contains internal helpers relating to conn.Conns values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL