structs

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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]) All

func (r *CircularBuffer[T]) All() iter.Seq2[int, T]

func (*CircularBuffer[T]) Capacity

func (r *CircularBuffer[T]) Capacity() int

Capacity returns buffer capacity.

func (*CircularBuffer[T]) Clear

func (r *CircularBuffer[T]) Clear()

Clear removes all elements.

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

type Range struct {
	Start uint64 `json:"s"`
	End   uint64 `json:"e"`
}

Range представляет диапазон sequence numbers [Start, End] включительно

func (Range) ContainsOther

func (r Range) ContainsOther(o Range) bool

func (Range) ContainsValue

func (r Range) ContainsValue(v uint64) bool

func (Range) Equals

func (r Range) Equals(o Range) bool

func (Range) Len

func (r Range) Len() uint64

func (Range) Merge

func (r Range) Merge(other Range) (Range, error)

func (Range) Split

func (r Range) Split(pivot uint64) (left, right Range)

func (Range) String

func (r Range) String() string

type Set

type Set[T comparable] map[T]empty

Set — простое множество для значений типа T

func NewSet

func NewSet[T comparable](values ...T) Set[T]

NewSet создаёт пустое множество

func (Set[T]) Add

func (s Set[T]) Add(value T)

Add добавляет элемент в множество

func (Set[T]) All

func (s Set[T]) All() iter.Seq[T]

func (Set[T]) Clear

func (s Set[T]) Clear()

Clear очищает множество

func (Set[T]) Clone

func (s Set[T]) Clone() Set[T]

Clone создаёт копию множества

func (Set[T]) Contains

func (s Set[T]) Contains(value T) bool

Has проверяет наличие элемента

func (Set[T]) Delete

func (s Set[T]) Delete(value T)

func (Set[T]) Difference

func (s Set[T]) Difference(other Set[T]) Set[T]

Difference возвращает разность множеств (элементы, которые есть в s, но нет в other)

func (Set[T]) Intersect

func (s Set[T]) Intersect(other Set[T]) Set[T]

Intersect возвращает пересечение двух множеств

func (Set[T]) IsSubsetOf

func (s Set[T]) IsSubsetOf(other Set[T]) bool

IsSubsetOf проверяет, является ли s подмножеством other

func (Set[T]) Remove

func (s Set[T]) Remove(value T)

Remove удаляет элемент из множества

func (Set[T]) Size

func (s Set[T]) Size() int

Size возвращает количество элементов

func (Set[T]) Slice

func (s Set[T]) Slice() []T

Values возвращает все элементы множества

func (Set[T]) Union

func (s Set[T]) Union(other Set[T]) Set[T]

Union объединяет текущее множество с другим

Jump to

Keyboard shortcuts

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