Documentation ¶
Index ¶
- Constants
- func CPUTicks() int64
- func Calloc(n int) []byte
- func CallocNoRef(n int) []byte
- func FastRand() uint32
- func Free(b []byte)
- func HistogramBounds(minExponent, maxExponent uint32) []float64
- func KeyToHash(key interface{}) (uint64, uint64)
- func MemHash(data []byte) uint64
- func MemHashString(str string) uint64
- func NanoTime() int64
- func NumAllocBytes() int64
- func StatsPrint()
- type Bloom
- type Buffer
- func (b *Buffer) Allocate(n int) []byte
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Grow(n int)
- func (b *Buffer) Len() int
- func (b *Buffer) Release()
- func (b *Buffer) Reset()
- func (b *Buffer) Slice(offset int) []byte
- func (b *Buffer) SliceAllocate(sz int) []byte
- func (b *Buffer) SliceOffsets(offsets []int) []int
- func (b *Buffer) Write(p []byte) (n int, err error)
- type HistogramData
Constants ¶
const (
// MaxArrayLen is a safe maximum length for slices on this architecture.
MaxArrayLen = 1<<50 - 1
)
Variables ¶
This section is empty.
Functions ¶
func CPUTicks ¶
func CPUTicks() int64
CPUTicks is a faster alternative to NanoTime to measure time duration.
func CallocNoRef ¶
CallocNoRef will not give you memory back without jemalloc.
func HistogramBounds ¶
Creates bounds for an histogram. The bounds are powers of two of the form [2^min_exponent, ..., 2^max_exponent].
func KeyToHash ¶
TODO: Figure out a way to re-use memhash for the second uint64 hash, we
already know that appending bytes isn't reliable for generating a second hash (see Ristretto PR #88). We also know that while the Go runtime has a runtime memhash128 function, it's not possible to use it to generate [2]uint64 or anything resembling a 128bit hash, even though that's exactly what we need in this situation.
func MemHash ¶
MemHash is the hash function used by go map, it utilizes available hardware instructions(behaves as aeshash if aes instruction is available). NOTE: The hash seed changes for every process. So, this cannot be used as a persistent hash.
func MemHashString ¶
MemHashString is the hash function used by go map, it utilizes available hardware instructions (behaves as aeshash if aes instruction is available). NOTE: The hash seed changes for every process. So, this cannot be used as a persistent hash.
func NanoTime ¶
func NanoTime() int64
NanoTime returns the current time in nanoseconds from a monotonic clock.
func NumAllocBytes ¶
func NumAllocBytes() int64
NumAllocBytes returns the number of bytes allocated using calls to z.Calloc. The allocations could be happening via either Go or jemalloc, depending upon the build flags.
func StatsPrint ¶
func StatsPrint()
Types ¶
type Bloom ¶
type Bloom struct { ElemNum uint64 // contains filtered or unexported fields }
Bloom filter
func JSONUnmarshal ¶
JSONUnmarshal takes JSON-Object (type bloomJSONImExport) as []bytes returns bloom32 / bloom64 object.
func NewBloomFilter ¶
NewBloomFilter returns a new bloomfilter.
func (*Bloom) AddIfNotHas ¶
AddIfNotHas only Adds hash, if it's not present in the bloomfilter. Returns true if hash was added. Returns false if hash was already registered in the bloomfilter.
func (Bloom) Has ¶
Has checks if bit(s) for entry hash is/are set, returns true if the hash was added to the Bloom Filter.
func (Bloom) JSONMarshal ¶
JSONMarshal returns JSON-object (type bloomJSONImExport) as []byte.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is equivalent of bytes.Buffer without the ability to read. It uses z.Calloc to allocate memory, which depending upon how the code is compiled could use jemalloc for allocations.
func (*Buffer) Allocate ¶
Allocate is a way to get a slice of size n back from the buffer. This slice can be directly written to. Warning: Allocate is not thread-safe. The byte slice returned MUST be used before further calls to Buffer.
func (*Buffer) Grow ¶
Grow would grow the buffer to have at least n more bytes. In case the buffer is at capacity, it would reallocate twice the size of current capacity + n, to ensure n bytes can be written to the buffer without further allocation.
func (*Buffer) Release ¶
func (b *Buffer) Release()
Release would free up the memory allocated by the buffer. Once the usage of buffer is done, it is important to call Release, otherwise a memory leak can happen.
func (*Buffer) SliceAllocate ¶
SliceAllocate would encode the size provided into the buffer, followed by a call to Allocate, hence returning the slice of size sz. This can be used to allocate a lot of small buffers into this big buffer. Note that SliceAllocate should NOT be mixed with normal calls to Write. Otherwise, SliceOffsets won't work.
func (*Buffer) SliceOffsets ¶
SliceOffsets would return the offsets of all slices written to the buffer. TODO: Perhaps keep the offsets separate in another buffer, and allow access to slices via index.
type HistogramData ¶
type HistogramData struct { Bounds []float64 Count int64 CountPerBucket []int64 Min int64 Max int64 Sum int64 }
HistogramData stores the information needed to represent the sizes of the keys and values as a histogram.
func NewHistogramData ¶
func NewHistogramData(bounds []float64) *HistogramData
NewHistogramData returns a new instance of HistogramData with properly initialized fields.
func (*HistogramData) Copy ¶
func (histogram *HistogramData) Copy() *HistogramData
func (*HistogramData) Mean ¶
func (histogram *HistogramData) Mean() float64
Mean returns the mean value for the histogram.
func (*HistogramData) String ¶
func (histogram *HistogramData) String() string
String converts the histogram data into human-readable string.
func (*HistogramData) Update ¶
func (histogram *HistogramData) Update(value int64)
Update changes the Min and Max fields if value is less than or greater than the current values.