datastructure

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[T comparable](s []T, e T) bool

func Filter

func Filter[T any](s []T, f func(T) bool) (res []T)

func Map

func Map[T, V any](s []T, f func(T) V) (res []V)

func SumAny

func SumAny[T any, V any](s []T, f func(T, V) V, initialVal V) V

func SumFloat

func SumFloat[T any](s []T, f func(T) float64) float64

Types

type Buffer

type Buffer[T comparable, U any] map[T]U

func ProvideBuffer

func ProvideBuffer[T comparable, U any](ops ...BufferOptionFunc) Buffer[T, U]

func (*Buffer[T, U]) Get

func (t *Buffer[T, U]) Get(id T) *U

func (*Buffer[T, U]) GetKeys

func (t *Buffer[T, U]) GetKeys() []T

func (*Buffer[T, U]) GetValues added in v0.0.5

func (t *Buffer[T, U]) GetValues() []U

func (*Buffer[T, U]) IsObjectInBuffer

func (t *Buffer[T, U]) IsObjectInBuffer(id T) bool

func (*Buffer[T, U]) Pop

func (t *Buffer[T, U]) Pop(id T) *U

func (*Buffer[T, U]) Store

func (t *Buffer[T, U]) Store(id T, object U)

type BufferOptionFunc

type BufferOptionFunc func(option *bufferOption)

func WithBufferMetrics

func WithBufferMetrics(meter metric.Meter, metricName string, opts ...metric.Int64ObservableCounterOption) BufferOptionFunc

type Observable added in v0.0.14

type Observable[T any] interface {
	AddObserver(Observer[T])
	RemoveObserver(Observer[T])
	NotifyObserver(context.Context, T) error
}

type Observer added in v0.0.14

type Observer[T any] interface {
	OnEvent(context.Context, T) error
}

type Queue

type Queue[Data any] struct {
	// contains filtered or unexported fields
}

Queue is a FIFO (First in Last out) queue data structure

func ProvideQueue

func ProvideQueue[Data any](ops ...QueueOptionFunc) Queue[Data]

func (*Queue[Data]) Empty

func (q *Queue[Data]) Empty() bool

func (*Queue[Data]) Pop

func (q *Queue[Data]) Pop() (*Data, bool)

func (*Queue[Data]) PopWithFilter

func (q *Queue[Data]) PopWithFilter(filter func(Data) bool) (*Data, bool)

func (*Queue[Data]) Push

func (q *Queue[Data]) Push(d Data)

func (*Queue[Data]) ReadQueue

func (q *Queue[Data]) ReadQueue() []Data

func (*Queue[Data]) RemoveWithCondition

func (q *Queue[Data]) RemoveWithCondition(removeCondition func(data Data) bool)

type QueueOptionFunc

type QueueOptionFunc func(option *queueOption)

func WithQueueMetrics

func WithQueueMetrics(meter metric.Meter, metricName string, opts ...metric.Int64ObservableCounterOption) QueueOptionFunc

func WithQueueSize

func WithQueueSize(size int) QueueOptionFunc

type RoundRobin

type RoundRobin[T any] interface {
	Next() T
}

func ProvideRoundRobin

func ProvideRoundRobin[T any](data ...T) (RoundRobin[T], error)

type Stack

type Stack[T any] []T

Stack implement the stack data structure. First come, Last out.

func (*Stack[T]) IsEmpty

func (s *Stack[T]) IsEmpty() bool

IsEmpty check if stack is empty

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (*T, bool)

Pop Remove and return top element of stack. Return false if stack is empty.

func (*Stack[T]) Push

func (s *Stack[T]) Push(str T)

Push a new value onto the stack

Directories

Path Synopsis
Package mock_datastructure is a generated GoMock package.
Package mock_datastructure is a generated GoMock package.

Jump to

Keyboard shortcuts

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