Documentation
¶
Index ¶
- Variables
- type CircularBuffer
- func (r *CircularBuffer[T]) Add(item T)
- func (r *CircularBuffer[T]) All() iter.Seq2[int, T]
- func (r *CircularBuffer[T]) Capacity() int
- func (r *CircularBuffer[T]) Clear()
- func (r *CircularBuffer[T]) Dequeue() (T, bool)
- func (r *CircularBuffer[T]) Enqueue(item T) bool
- func (r *CircularBuffer[T]) Get(idx int) (T, bool)
- func (r *CircularBuffer[T]) IsEmpty() bool
- func (r *CircularBuffer[T]) IsFull() bool
- func (r *CircularBuffer[T]) Len() int
- func (r *CircularBuffer[T]) Peek() (T, bool)
- func (r *CircularBuffer[T]) PopFirstN(n int)
- func (r *CircularBuffer[T]) PopLastN(n int)
- type Range
- type Set
- func (s Set[T]) Add(value T)
- func (s Set[T]) All() iter.Seq[T]
- func (s Set[T]) Clear()
- func (s Set[T]) Clone() Set[T]
- func (s Set[T]) Contains(value T) bool
- func (s Set[T]) Delete(value T)
- func (s Set[T]) Difference(other Set[T]) Set[T]
- func (s Set[T]) Intersect(other Set[T]) Set[T]
- func (s Set[T]) IsSubsetOf(other Set[T]) bool
- func (s Set[T]) Remove(value T)
- func (s Set[T]) Size() int
- func (s Set[T]) Slice() []T
- func (s Set[T]) Union(other Set[T]) Set[T]
Constants ¶
This section is empty.
Variables ¶
var ErrCannotMerge = errors.New("cannot merge ranges")
Functions ¶
This section is empty.
Types ¶
type CircularBuffer ¶
type CircularBuffer[T any] struct { // contains filtered or unexported fields }
CircularBuffer — generic циклический буфер. behaviour: если overwrite==false, Enqueue возвращает false при заполнении. если overwrite==true, Enqueue перезапишет самый старый элемент.
func NewCircularBuffer ¶
func NewCircularBuffer[T any](capacity int, overwrite bool) *CircularBuffer[T]
New creates a new CircularBuffer with given capacity. capacity must be > 0.
func (*CircularBuffer[T]) Add ¶
func (r *CircularBuffer[T]) Add(item T)
Add forces add with overwrite behavior (convenience). If buffer not full — behaves like Enqueue. If full — overwrites oldest.
func (*CircularBuffer[T]) Capacity ¶
func (r *CircularBuffer[T]) Capacity() int
Capacity returns buffer capacity.
func (*CircularBuffer[T]) Dequeue ¶
func (r *CircularBuffer[T]) Dequeue() (T, bool)
Dequeue removes and returns the oldest element. If empty returns (zero, false).
func (*CircularBuffer[T]) Enqueue ¶
func (r *CircularBuffer[T]) Enqueue(item T) bool
Enqueue tries to add an element. If buffer is full and overwrite==false returns false. If buffer is full and overwrite==true it overwrites the oldest element.
func (*CircularBuffer[T]) Get ¶
func (r *CircularBuffer[T]) Get(idx int) (T, bool)
func (*CircularBuffer[T]) IsEmpty ¶
func (r *CircularBuffer[T]) IsEmpty() bool
IsEmpty reports whether buffer is empty.
func (*CircularBuffer[T]) IsFull ¶
func (r *CircularBuffer[T]) IsFull() bool
IsFull reports whether buffer is full.
func (*CircularBuffer[T]) Len ¶
func (r *CircularBuffer[T]) Len() int
Len returns current number of elements.
func (*CircularBuffer[T]) Peek ¶
func (r *CircularBuffer[T]) Peek() (T, bool)
Peek returns the oldest element without removing it. If empty returns (zero, ErrEmpty).
func (*CircularBuffer[T]) PopFirstN ¶
func (r *CircularBuffer[T]) PopFirstN(n int)
func (*CircularBuffer[T]) PopLastN ¶
func (r *CircularBuffer[T]) PopLastN(n int)
type Range ¶
Range представляет диапазон sequence numbers [Start, End] включительно
func (Range) ContainsOther ¶
func (Range) ContainsValue ¶
type Set ¶
type Set[T comparable] map[T]empty
Set — простое множество для значений типа T
func (Set[T]) Difference ¶
Difference возвращает разность множеств (элементы, которые есть в s, но нет в other)
func (Set[T]) IsSubsetOf ¶
IsSubsetOf проверяет, является ли s подмножеством other