collection

package
v0.0.0-...-b1352b5 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapping

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

Mapping wraps a map and adds utility functions

func NewMapping

func NewMapping[K comparable, V any]() Mapping[K, V]

Constructor for KVStore

func (*Mapping[K, V]) Del

func (kv *Mapping[K, V]) Del(k K)

Delete an entry. Panic if the entry was not found

func (*Mapping[K, V]) Exists

func (kv *Mapping[K, V]) Exists(ks ...K) bool

Returns `true` if all the passed entries exists

func (*Mapping[K, V]) InnerMap

func (kv *Mapping[K, V]) InnerMap() map[K]V

Returns the innerMap

func (*Mapping[K, V]) InsertNew

func (kv *Mapping[K, V]) InsertNew(key K, value V)

InsertNew inserts a new value and panics if it was contained already

func (*Mapping[K, V]) IterateFunc

func (kv *Mapping[K, V]) IterateFunc(f func(k K, v V))

Iterates a function over all elements of the map

func (*Mapping[K, V]) ListAllKeys

func (kv *Mapping[K, V]) ListAllKeys() []K

Returns the list of all the keys

func (*Mapping[K, V]) ListValues

func (kv *Mapping[K, V]) ListValues() []V

ToSlice lists all entries in a slice of tuple

func (*Mapping[K, V]) MustExists

func (kv *Mapping[K, V]) MustExists(keys ...K)

Panic if the given entry does not exists

func (*Mapping[K, V]) MustGet

func (kv *Mapping[K, V]) MustGet(key K) V

Attempts to retrieve a value from a given key. Panics if it fails

func (*Mapping[K, V]) TryDel

func (kv *Mapping[K, V]) TryDel(k K) bool

Delete an entry. NOOP if the entry was not found

func (*Mapping[K, V]) TryGet

func (kv *Mapping[K, V]) TryGet(key K) (V, bool)

Attempts to retrieve a value from a given key. Returns nil if it failed

func (*Mapping[K, V]) Update

func (kv *Mapping[K, V]) Update(key K, value V)

Update a key possibly overwriting any existing entry

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

A set is an unordered collection addressed by keys, which supports

func NewSet

func NewSet[K comparable]() Set[K]

Constructor for KVStore

func (Set[K]) Exists

func (kv Set[K]) Exists(ks ...K) bool

Returns `true` if the entry exists

func (*Set[K]) Insert

func (kv *Set[K]) Insert(k K) bool

Inserts regarless of whether the entry was already present of not. Returns whether the entry was present already.

type VecVec

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

VecVec is a wrapper around double vecs The inner slice is append only

func NewVecVec

func NewVecVec[T any](length ...int) VecVec[T]

Constructor for double vecs. Can optionally give it an initial length (by default set to zero)

func (*VecVec[T]) AppendToInner

func (v *VecVec[T]) AppendToInner(pos int, t ...T)

Append one or more values to the given subslice. Will extend the larger size to match the requested position if necessary

func (*VecVec[T]) Inner

func (v *VecVec[T]) Inner() [][]T

Returns the inner double-slice

func (*VecVec[T]) Len

func (v *VecVec[T]) Len() int

Returns the inner double-slice

func (*VecVec[T]) LenOf

func (v *VecVec[T]) LenOf(pos int) int

Returns the length of an inner slice, also allocate the slice if it was not allocated, it will reserve it.

func (*VecVec[T]) MustGet

func (v *VecVec[T]) MustGet(pos int) []T

Returns a subslice. Panic if the subslice was not allocated

func (*VecVec[T]) Reserve

func (v *VecVec[T]) Reserve(newLen int)

Allocates up to a given rounds number

Jump to

Keyboard shortcuts

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