Documentation ¶
Overview ¶
Package aghalg contains common generic algorithms and data structures.
TODO(a.garipov): Move parts of this into golibs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CoalesceSlice ¶ added in v0.107.12
func CoalesceSlice[E any, S []E](values ...S) (res S)
CoalesceSlice returns the first non-zero value. It is named after function COALESCE in SQL. If values or all its elements are empty, it returns nil.
Types ¶
type NullBool ¶ added in v0.107.8
type NullBool uint8
NullBool is a nullable boolean. Use these in JSON requests and responses instead of pointers to bool.
func BoolToNullBool ¶ added in v0.107.8
BoolToNullBool converts a bool into a NullBool.
func (NullBool) MarshalJSON ¶ added in v0.107.8
MarshalJSON implements the json.Marshaler interface for NullBool.
func (NullBool) String ¶ added in v0.107.8
String implements the fmt.Stringer interface for NullBool.
func (*NullBool) UnmarshalJSON ¶ added in v0.107.8
UnmarshalJSON implements the json.Unmarshaler interface for *NullBool.
type RingBuffer ¶ added in v0.107.39
type RingBuffer[T any] struct { // contains filtered or unexported fields }
RingBuffer is the implementation of ring buffer data structure.
func NewRingBuffer ¶ added in v0.107.39
func NewRingBuffer[T any](size uint) (rb *RingBuffer[T])
NewRingBuffer initializes the new instance of ring buffer. size must be greater or equal to zero.
func (*RingBuffer[T]) Append ¶ added in v0.107.39
func (rb *RingBuffer[T]) Append(e T)
Append appends an element to the buffer.
func (*RingBuffer[T]) Clear ¶ added in v0.107.39
func (rb *RingBuffer[T]) Clear()
Clear clears the buffer.
func (*RingBuffer[T]) Len ¶ added in v0.107.39
func (rb *RingBuffer[T]) Len() (l uint)
Len returns a length of the buffer.
func (*RingBuffer[T]) Range ¶ added in v0.107.39
func (rb *RingBuffer[T]) Range(cb func(T) (cont bool))
Range calls cb for each element of the buffer. If cb returns false it stops.
func (*RingBuffer[T]) ReverseRange ¶ added in v0.107.39
func (rb *RingBuffer[T]) ReverseRange(cb func(T) (cont bool))
ReverseRange calls cb for each element of the buffer in reverse order. If cb returns false it stops.
type SortedMap ¶ added in v0.107.46
type SortedMap[K comparable, V any] struct { // contains filtered or unexported fields }
SortedMap is a map that keeps elements in order with internal sorting function. Must be initialised by the NewSortedMap.
func NewSortedMap ¶ added in v0.107.46
func NewSortedMap[K comparable, V any](cmp func(a, b K) (res int)) SortedMap[K, V]
NewSortedMap initializes the new instance of sorted map. cmp is a sort function to keep elements in order.
TODO(s.chzhen): Use cmp.Compare in Go 1.21.
func (*SortedMap[K, V]) Clear ¶ added in v0.107.46
func (m *SortedMap[K, V]) Clear()
Clear removes all elements from the sorted map.
func (*SortedMap[K, V]) Del ¶ added in v0.107.46
func (m *SortedMap[K, V]) Del(key K)
Del removes the value by key from the sorted map.
type UniqChecker ¶
type UniqChecker[T constraints.Ordered] map[T]int64
UniqChecker allows validating uniqueness of comparable items.
TODO(a.garipov): The Ordered constraint is only really necessary in Validate. Consider ways of making this constraint comparable instead.
func (UniqChecker[T]) Add ¶
func (uc UniqChecker[T]) Add(elems ...T)
Add adds a value to the validator. v must not be nil.
func (UniqChecker[T]) Merge ¶
func (uc UniqChecker[T]) Merge(other UniqChecker[T]) (merged UniqChecker[T])
Merge returns a checker containing data from both uc and other.
func (UniqChecker[T]) Validate ¶
func (uc UniqChecker[T]) Validate() (err error)
Validate returns an error enumerating all elements that aren't unique.