util

package
v0.0.0-...-ee0e00b Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrListEmpty = errors.New("list is empty")
	ErrListFull  = errors.New("list is full")
)

Errors that can be returned by the util package.

Functions

func Diff

func Diff[T constraints.Integer](a, b T) T

func Map

func Map[T any, U any](ts []T, mapper func(T) U) []U

Map applies the given mapper function to each element of the given slice.

func Max

func Max[T constraints.Ordered](a, b T) T

Max returns the maximum of the two values. This is a convenience function for the constraints.Ordered interface.

func Min

func Min[T constraints.Ordered](a, b T) T

Min returns the minimum of the two values. This is a convenience function for the constraints.Ordered interface.

func NextPowerOfTwo

func NextPowerOfTwo(i uint64) uint64

NextPowerOfTwo returns i if it is a power of 2, otherwise the next power of two greater than i.

Types

type ArrayDeque

type ArrayDeque[T any] struct {
	// contains filtered or unexported fields
}

ArrayDeque is a double-ended queue implemented using an array.

func NewArrayDeque

func NewArrayDeque[T any](capacity int) *ArrayDeque[T]

NewArrayDeque creates a new ArrayDeque with the given capacity.

func (*ArrayDeque[T]) Back

func (dq *ArrayDeque[T]) Back() *T

Back returns the last element of the deque or a nil pointer.

func (*ArrayDeque[T]) Capacity

func (dq *ArrayDeque[T]) Capacity() int

Capacity returns the maximum number of elements that can be stored in the deque.

func (*ArrayDeque[T]) Front

func (dq *ArrayDeque[T]) Front() *T

Front returns the first element of the deque or a nil pointer.

func (*ArrayDeque[T]) Len

func (dq *ArrayDeque[T]) Len() int

Len returns the number of elements in the deque.

func (*ArrayDeque[T]) PopBack

func (dq *ArrayDeque[T]) PopBack() (T, error)

PopBack removes the last element from the deque and returns it.

func (*ArrayDeque[T]) PopFront

func (dq *ArrayDeque[T]) PopFront() (T, error)

PopFront removes the first element from the deque and returns it.

func (*ArrayDeque[T]) PushBack

func (dq *ArrayDeque[T]) PushBack(v T) error

PushBack adds an element to the back of the deque.

func (*ArrayDeque[T]) PushFront

func (dq *ArrayDeque[T]) PushFront(v T) error

PushFront adds an element to the front of the deque.

type BlocksDeque

type BlocksDeque[T any] struct {
	// contains filtered or unexported fields
}

BlocksDeque is a double-ended queue that is implemented using a linked list of blocks.

func NewBlocksDeque

func NewBlocksDeque[T any](blocksize int) *BlocksDeque[T]

NewBlocksDeque creates a new BlocksDeque.

func (*BlocksDeque[T]) Back

func (dq *BlocksDeque[T]) Back() *T

Back returns the last element of the deque or a nil pointer.

func (*BlocksDeque[T]) Capacity

func (dq *BlocksDeque[T]) Capacity() int

Capacity returns the maximum number of elements that can be stored in the deque.

func (*BlocksDeque[T]) Front

func (dq *BlocksDeque[T]) Front() *T

Front returns the first element of the deque or a nil pointer.

func (*BlocksDeque[T]) Len

func (dq *BlocksDeque[T]) Len() int

Len returns the number of elements in the deque.

func (*BlocksDeque[T]) PopBack

func (dq *BlocksDeque[T]) PopBack() (T, error)

PopBack removes the last element from the deque and returns it.

func (*BlocksDeque[T]) PopFront

func (dq *BlocksDeque[T]) PopFront() (T, error)

PopFront removes the first element from the deque and returns it.

func (*BlocksDeque[T]) PushBack

func (dq *BlocksDeque[T]) PushBack(v T) error

PushBack adds an element to the back of the deque.

func (*BlocksDeque[T]) PushFront

func (dq *BlocksDeque[T]) PushFront(v T) error

PushFront adds an element to the front of the deque.

type Deque

type Deque[T any] interface {
	// Back returns the last element of the deque or a nil pointer.
	Back() *T
	// Front returns the first element of the deque or a nil pointer.
	Front() *T
	// Len returns the number of elements in the deque.
	Len() int
	// PushBack adds an element to the back of the deque.
	PushBack(v T) error
	// PushFront adds an element to the front of the deque.
	PushFront(v T) error
	// PopBack removes the last element from the deque and returns it.
	PopBack() (T, error)
	// PopFront removes the first element from the deque and returns it.
	PopFront() (T, error)
	// Capacity returns the maximum number of elements that can be stored in the deque.
	Capacity() int // -1 for unbounded
}

Deque is a double-ended queue.

type ListDeque

type ListDeque[T any] struct {
	// contains filtered or unexported fields
}

ListDeque is a double-ended queue that is implemented using a linked list.

func NewListDeque

func NewListDeque[T any]() *ListDeque[T]

NewListDeque creates a new ListDeque.

func (*ListDeque[T]) Back

func (dq *ListDeque[T]) Back() *T

Back returns the last element of the deque or a nil pointer.

func (*ListDeque[T]) Capacity

func (dq *ListDeque[T]) Capacity() int

Capacity returns the maximum number of elements that can be stored in the deque.

func (*ListDeque[T]) Front

func (dq *ListDeque[T]) Front() *T

Front returns the first element of the deque or a nil pointer.

func (*ListDeque[T]) Len

func (dq *ListDeque[T]) Len() int

Len returns the number of elements in the deque.

func (*ListDeque[T]) PopBack

func (dq *ListDeque[T]) PopBack() (T, error)

PopBack removes the last element from the deque and returns it.

func (*ListDeque[T]) PopFront

func (dq *ListDeque[T]) PopFront() (T, error)

PopFront removes the first element from the deque and returns it.

func (*ListDeque[T]) PushBack

func (dq *ListDeque[T]) PushBack(v T) error

PushBack adds an element to the back of the deque.

func (*ListDeque[T]) PushFront

func (dq *ListDeque[T]) PushFront(v T) error

PushFront adds an element to the front of the deque.

type SharedFlagSet

type SharedFlagSet[F constraints.Unsigned] struct {
	// contains filtered or unexported fields
}

SharedFlagSet is a set of flags that can be shared between goroutines.

func NewSharedFlagSet

func NewSharedFlagSet[F constraints.Unsigned](init F) *SharedFlagSet[F]

NewSharedFlagSet creates a new SharedFlagSet with the given initial value.

func (*SharedFlagSet[F]) All

func (fs *SharedFlagSet[F]) All() F

All returns the current value of the flag set.

func (*SharedFlagSet[F]) Contains

func (fs *SharedFlagSet[F]) Contains(flags F) bool

Contains returns true if all the given flags are set.

func (*SharedFlagSet[F]) ContainsAny

func (fs *SharedFlagSet[F]) ContainsAny(flags F) bool

ContainsAny returns true if any of the given flags are set.

func (*SharedFlagSet[F]) ContainsExact

func (fs *SharedFlagSet[F]) ContainsExact(mask F, flags F) bool

ContainsExact returns true if the masked bits have exactly the given values.

func (*SharedFlagSet[F]) Set

func (fs *SharedFlagSet[F]) Set(flags F)

Set sets the given flags.

func (*SharedFlagSet[F]) Unset

func (fs *SharedFlagSet[F]) Unset(flags F)

Unset clears the given flags.

func (*SharedFlagSet[F]) Update

func (fs *SharedFlagSet[F]) Update(mask F, set F)

Update updates the flag set with the given flags. The mask flags are cleared, and replaced with the set values.

func (*SharedFlagSet[F]) Wait

func (fs *SharedFlagSet[F]) Wait(state F)

Wait for all the flags in 'state' to be set

func (*SharedFlagSet[F]) WaitAny

func (fs *SharedFlagSet[F]) WaitAny(mask F, current F) F

Wait for any change on the masked bits from the current value

func (*SharedFlagSet[F]) WaitExact

func (fs *SharedFlagSet[F]) WaitExact(mask F, current F) F

WaitExact waits for the masked bits to become exactly current value.

type SynchronizedDeque

type SynchronizedDeque[T any] struct {
	// contains filtered or unexported fields
}

SynchronizedDeque is a double-ended queue that is thread-safe.

func NewSynchronizedDeque

func NewSynchronizedDeque[T any](deque Deque[T]) *SynchronizedDeque[T]

NewSynchronizedDeque creates a new SynchronizedDeque.

func (*SynchronizedDeque[T]) Back

func (dq *SynchronizedDeque[T]) Back() *T

Back returns the last element of the deque or a nil pointer.

func (*SynchronizedDeque[T]) Capacity

func (dq *SynchronizedDeque[T]) Capacity() int

Capacity returns the maximum number of elements that can be stored in the deque.

func (*SynchronizedDeque[T]) Front

func (dq *SynchronizedDeque[T]) Front() *T

Front returns the first element of the deque or a nil pointer.

func (*SynchronizedDeque[T]) Len

func (dq *SynchronizedDeque[T]) Len() int

Len returns the number of elements in the deque.

func (*SynchronizedDeque[T]) PollBack

func (dq *SynchronizedDeque[T]) PollBack() T

PollBack removes the last element from the deque and returns it. If the deque is empty, it will block until an element is available.

func (*SynchronizedDeque[T]) PollFront

func (dq *SynchronizedDeque[T]) PollFront() T

PollFront removes the first element from the deque and returns it. If the deque is empty, it will block until an element is available.

func (*SynchronizedDeque[T]) PopBack

func (dq *SynchronizedDeque[T]) PopBack() (T, error)

PopBack removes the last element from the deque and returns it.

func (*SynchronizedDeque[T]) PopFront

func (dq *SynchronizedDeque[T]) PopFront() (T, error)

PopFront removes the first element from the deque and returns it.

func (*SynchronizedDeque[T]) PushBack

func (dq *SynchronizedDeque[T]) PushBack(v T) error

PushBack adds an element to the back of the deque.

func (*SynchronizedDeque[T]) PushFront

func (dq *SynchronizedDeque[T]) PushFront(v T) error

PushFront adds an element to the front of the deque.

type SynchronizedMap

type SynchronizedMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewSynchronizedMap

func NewSynchronizedMap[K comparable, V any]() *SynchronizedMap[K, V]

func (*SynchronizedMap[K, V]) Add

func (m *SynchronizedMap[K, V]) Add(key K, value V)

func (*SynchronizedMap[K, V]) Get

func (m *SynchronizedMap[K, V]) Get(key K) (V, bool)

func (*SynchronizedMap[K, V]) GetOrInsert

func (m *SynchronizedMap[K, V]) GetOrInsert(key K, creator func() V) V

func (*SynchronizedMap[K, V]) Keys

func (m *SynchronizedMap[K, V]) Keys() []K

func (*SynchronizedMap[K, V]) Remove

func (m *SynchronizedMap[K, V]) Remove(key K)

Jump to

Keyboard shortcuts

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