Documentation ¶
Index ¶
- Constants
- func FNV64(key []byte) uint64
- func Max[T constraints.Ordered](a, b T) T
- func Min[T constraints.Ordered](a, b T) T
- func SliceEquals[T comparable](a, b []T) bool
- type AllocatorRef
- type IntMap
- type NoLock
- type OptLock
- type Pool
- type Queue
- type RWSpinLock
- type RingBuffer
- type Set
- type SlabAllocator
- type SpinLock
Constants ¶
const ( // Offset64 is the offset for FNV64 Offset64 = 14695981039346656037 // Prime64 is the prime for FNV64 Prime64 = 1099511628211 )
Variables ¶
This section is empty.
Functions ¶
func Max ¶
func Max[T constraints.Ordered](a, b T) T
Max function for any type. Returns the bigger value of a and b. Returns b if equal.
func Min ¶
func Min[T constraints.Ordered](a, b T) T
Min function for any type. Returns the smaller value of a and b. Returns b if equal.
func SliceEquals ¶
func SliceEquals[T comparable](a, b []T) bool
SliceEquals returns if two slices are equal
Types ¶
type AllocatorRef ¶
type AllocatorRef[T any] struct { // contains filtered or unexported fields }
AllocatorRef is a reference to an allocated object allocated by a SlabAllocator. The object is guaranteed to be valid until the AllocatorRef is freed. The value of the object is undefined after its Freed. The value is not zeroed.
func (*AllocatorRef[T]) Get ¶
func (ref *AllocatorRef[T]) Get() *T
Get returns the object referenced by the AllocatorRef.
type IntMap ¶
type IntMap[V any] struct { // contains filtered or unexported fields }
IntMap is an int to any map which might provide performance benefits over the std map. Insert and lookup speeds are often slightly faster. Also delete returns the value it held avoiding aditional lookups in some situations.
func (*IntMap[V]) Delete ¶
Delete removes a value from this map returns value,true or 0, false if the key wasnt in this map
type NoLock ¶
type NoLock byte
NoLock satisfies sync.Locker interface without locking
type OptLock ¶
type OptLock uint32
OptLock type is used for an optimistic concurrency design. The lock provides a Read/Write facility. Writers are not prevented from acquiring the lock while readers are holding it. Readers must verify that the lock is still valid after reading their data.
Readers must first acquire the state by calling RLock() and then verify that the state is still valid after reading by calling RVerify().
Writers must first acquire the state by calling Lock() and release their lock after writing by calling Unlock().
The null value of the lock is usable.
Data protected by the lock must not panic when reads and writes happen concurrently even if those actions result in invalid data. The std map therefore cant be protected by the lock.
func (*OptLock) Lock ¶
func (lock *OptLock) Lock()
Lock acquires the write lock. This operation blocks until the lock is acquired using exponential backoff.
func (*OptLock) RLock ¶
RLock acquires the read lock. It returns the state and if the lock was acquired. After reading readers must verify that the state is still valid by calling RVerify().
type Pool ¶
type Pool[T any] struct { // contains filtered or unexported fields }
Pool stores a set of items. It can returned a pooled or a new one when an item is retrieved. A pool might be synced for parallel access see NewSyncPool.
func NewPool ¶
NewPool creates a new Pool which is not safe to access from multiple goroutines. For a safe implementation us NewSyncPool
func NewSyncPool ¶
NewSyncPool creates a new Pool which is safe to access from multiple goroutines simultaneously.
The Pool requires locking for this and might therefore be slower for
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Queue type for an unbound FIFO queue
func (*Queue[T]) Peek ¶
Peek reads the last element from the queue without changing the queue. Returns the element and true if an element is present and returns the nilvalue and false if no element is left.
type RWSpinLock ¶
type RWSpinLock int32
RWSpinLock type is a read/write lock. It is more efficient than sync.RWMutex but has less safety checks.
func (*RWSpinLock) Lock ¶
func (lock *RWSpinLock) Lock()
Lock locks the RWSpinLock for writing. It blocks until no readers are reading.
func (*RWSpinLock) RLock ¶
func (lock *RWSpinLock) RLock()
RLock locks the RWSpinLock for reading. Blocks if the lock is held for writing until the lock is unlocked.
func (*RWSpinLock) RUnlock ¶
func (lock *RWSpinLock) RUnlock()
RUnlock unlocks the RWSpinLock for reading.
func (*RWSpinLock) Unlock ¶
func (lock *RWSpinLock) Unlock()
Unlock unlocks the RWSpinLock for writing.
type RingBuffer ¶
type RingBuffer[T any] struct { // contains filtered or unexported fields }
A RingBuffer is a FIFO queue with a fixed size. If the buffer is full, the oldest element is overwritten.
func NewRingBuffer ¶
func NewRingBuffer[T any](capacity uint64) RingBuffer[T]
NewRingBuffer creates a new RingBuffer. The capacity must be greater than zero.
func (*RingBuffer[T]) Cap ¶
func (ring *RingBuffer[T]) Cap() uint64
Cap returns the maximum number of elements in the buffer.
func (*RingBuffer[T]) Get ¶
func (ring *RingBuffer[T]) Get() (T, bool)
Get reads the last element from the queue removing it. If no item is present an invalid value and false is returned. Otherwise the last item is returned and true.
func (*RingBuffer[T]) Put ¶
func (ring *RingBuffer[T]) Put(value T)
Puts adds an element to the buffer.
func (*RingBuffer[T]) Size ¶
func (ring *RingBuffer[T]) Size() uint64
Size returns the number of elements in the buffer.
type Set ¶
type Set[T comparable] map[T]struct{}
Set type using builtin map as container. A set contains every item at most once.
type SlabAllocator ¶
type SlabAllocator[T any] struct { // contains filtered or unexported fields }
SlabAllocator is a memory allocator that allocates a fixed size block of memory and returns references to the allocated values.
The allocator might grow in size if more memory is needed. It is not threadsafe. Locks and bound checks are not implemented and must be done by the caller if needed.
func NewSlabAllocator ¶
func NewSlabAllocator[T any](size int) SlabAllocator[T]
NewSlabAllocator creates a new SlabAllocator which holds size number of elements.
func (*SlabAllocator[T]) Allocate ¶
func (allocator *SlabAllocator[T]) Allocate() *AllocatorRef[T]
Allocate allocates a new object from the allocator. Might trigger a reallocation if the allocator is exhausted.
func (*SlabAllocator[T]) Free ¶
func (allocator *SlabAllocator[T]) Free(ref *AllocatorRef[T])
Free returns the object to the allocator.
type SpinLock ¶
type SpinLock uint32
SpinLock implements and statisfies sync.Locker using a SpinLock as described here https://en.wikipedia.org/wiki/Spinlock with an exponential backoff described here https://en.wikipedia.org/wiki/Exponential_backoff
The zero-value of the spinlock is valid and can be initialised with SpinLock(0) SpinLock must not be copied after first use.