maps

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KeyValueHasher

func KeyValueHasher[K comparable, V any](hasher hash.Hasher[K]) hash.Hasher[KeyValue[K, V]]

KeyValueHasher creates a new hasher for KeyValue pairs using the provided hasher for the key type.

func WithBucketAmount

func WithBucketAmount(amount uint64) options.Option[Options]

WithBucketAmount sets the amount of buckets that the set will use

func WithBucketFunction

func WithBucketFunction(calc func(capacity uint64) uint64) options.Option[Options]

WithBucketAmount sets the amount of buckets that the set will use

func WithBucketSize

func WithBucketSize(size uint64) options.Option[Options]

WithBucketSize sets the size of buckets that the set will use

func WithCacheTarget

func WithCacheTarget[T any](target cpu.CacheKind) options.Option[Options]

WithCacheTarget sets the cache target for the set

func WithItemLocks

func WithItemLocks(pool *locks.Pool) options.Option[Options]

WithItemLocks sets the locks that the set will use

func WithMaxBucketSize

func WithMaxBucketSize(size uint64) options.Option[Options]

WithMaxBucketSize sets the size of buckets if it is larger than the a certain size

Types

type Bucketted

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

BuckettedSet is a set of items, that uses a pre-defined amount of buckets, each item generates an hash, from which a bucket can be specified

func NewBuckettedMap

func NewBuckettedMap[K, V comparable](capacity uint64, keyhasher hash.Hasher[K], opts ...options.Option[Options]) (*Bucketted[K, V], error)

NewBuckettedMap creates a new Bucketted with the specified capacity, hasher, and options. The Bucketted is a concurrent map that uses a bucketing strategy to reduce contention.

func (*Bucketted[K, V]) Append

func (m *Bucketted[K, V]) Append(other collections.Rangeable[KeyValue[K, V]])

Append adds all items from the specified Rangeable to the Bucketted.

func (*Bucketted[K, V]) AppendParralel

func (m *Bucketted[K, V]) AppendParralel(other collections.ParralelRangeable[KeyValue[K, V]])

AppendParralel adds all items from the specified ParralelRangeable to the Bucketted.

func (*Bucketted[K, V]) Get

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

Get retrieves the value for the specified key from the Bucketted.

func (*Bucketted[K, V]) GoString

func (s *Bucketted[K, V]) GoString() string

func (*Bucketted[K, V]) Grow

func (m *Bucketted[K, V]) Grow(new_capacity uint64)

Grow will increase the capacity of the set

func (*Bucketted[K, V]) KeyValues

func (s *Bucketted[K, V]) KeyValues() iter.Seq2[K, V]

KeyValues will return a sequence of all items in the set

func (*Bucketted[K, V]) Keys

func (s *Bucketted[K, V]) Keys() iter.Seq[K]

Keys will return a sequence of all items in the set

func (*Bucketted[K, V]) Range

func (s *Bucketted[K, V]) Range(yield func(item KeyValue[K, V]) bool)

Range will iterate over all items in the set

func (*Bucketted[K, V]) RangeParralel

func (s *Bucketted[K, V]) RangeParralel(yield func(item KeyValue[K, V]) bool)

RangeParralel will iterate over all items in the set in parallel

func (*Bucketted[K, V]) Read

func (s *Bucketted[K, V]) Read() iter.Seq[KeyValue[K, V]]

Read will return a sequence of all items in the set

func (*Bucketted[K, V]) Set

func (m *Bucketted[K, V]) Set(key K, item V) bool

Set will add or update the value for the specified key in the Bucketted. It returns true if the value was added, false if it was updated.

func (*Bucketted[K, V]) String

func (s *Bucketted[K, V]) String() string

func (*Bucketted[K, V]) Values

func (s *Bucketted[K, V]) Values() iter.Seq[V]

Values will return a sequence of all items in the set

type Fixed

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

Fixed is a fixed size slice, that can be used to store a fixed amount of items

func NewFixed

func NewFixed[K, V comparable](amount uint64) Fixed[K, V]

func (*Fixed[K, V]) Cap

func (s *Fixed[K, V]) Cap() int

func (*Fixed[K, V]) Get

func (s *Fixed[K, V]) Get(item KeyValue[K, V]) (KeyValue[K, V], bool)

func (*Fixed[K, V]) Len

func (s *Fixed[K, V]) Len() int

func (*Fixed[K, V]) Read

func (s *Fixed[K, V]) Read() iter.Seq[KeyValue[K, V]]

func (*Fixed[K, V]) Set

func (s *Fixed[K, V]) Set(item KeyValue[K, V]) bool

Fixed Add the given item to the set, if equivalant item was overriden, or empty space filled, true is returned

func (*Fixed[K, V]) Update

func (s *Fixed[K, V]) Update(item KeyValue[K, V]) bool

type GrowableMap

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

GrowableMap is a set that grows as needed.

func NewGrowableMap

func NewGrowableMap[K, V comparable](hasher hash.Hasher[K], opts ...options.Option[Options]) (*GrowableMap[K, V], error)

NewGrowableMap creates a new instance of GrowableMap with the provided hasher and options. The hasher is used to hash the elements in the set, and options can be used to configure the set.

func NewGrowableMapFrom

func NewGrowableMapFrom[K, V comparable](hasher hash.Hasher[K], base Options) (*GrowableMap[K, V], error)

func (*GrowableMap[K, V]) Find

func (s *GrowableMap[K, V]) Find(item KeyValue[K, V]) (KeyValue[K, V], bool)

func (*GrowableMap[K, V]) GetOrAdd

func (s *GrowableMap[K, V]) GetOrAdd(key K, value V) (KeyValue[K, V], bool)

GetOrAdd returns the item if it exists in the set, otherwise it adds it and returns it.

func (*GrowableMap[K, V]) GetOrAddKV

func (s *GrowableMap[K, V]) GetOrAddKV(item KeyValue[K, V]) (KeyValue[K, V], bool)

GetOrAdd returns the item if it exists in the set, otherwise it adds it and returns it.

func (*GrowableMap[K, V]) GoString

func (s *GrowableMap[K, V]) GoString() string

func (*GrowableMap[K, V]) NewKeyValue

func (s *GrowableMap[K, V]) NewKeyValue(key K, value V) KeyValue[K, V]

func (*GrowableMap[K, V]) Range

func (s *GrowableMap[K, V]) Range(yield func(item KeyValue[K, V]) bool)

Range calls the yield function for each item in the set.

func (*GrowableMap[K, V]) Read

func (s *GrowableMap[K, V]) Read() iter.Seq[KeyValue[K, V]]

Read returns an iterator that reads the items in the set.

func (*GrowableMap[K, V]) String

func (s *GrowableMap[K, V]) String() string

func (*GrowableMap[K, V]) UpdateOrAdd

func (s *GrowableMap[K, V]) UpdateOrAdd(key K, value V) bool

UpdateOrAdd updates the item if it exists in the set, otherwise it adds it. Returns true if it had to add it instead of update.

func (*GrowableMap[K, V]) UpdateOrAddKV

func (s *GrowableMap[K, V]) UpdateOrAddKV(item KeyValue[K, V]) bool

UpdateOrAdd updates the item if it exists in the set, otherwise it adds it. Returns true if it had to add it instead of update.

type KeyValue

type KeyValue[K comparable, V any] struct {
	Hash  uint64 // The hash of the key marked for empty checks. See [hashmark.MarkedHash]
	Key   K
	Value V
}

func EmptyKeyValue

func EmptyKeyValue[K comparable, V any]() KeyValue[K, V]

EmptyKeyValue creates a new KeyValue instance with empty key and value.

func NewKey

func NewKey[K comparable, V any](hash uint64, key K) KeyValue[K, V]

NewKey creates a new KeyValue instance with the given key.

func NewKeyValue

func NewKeyValue[K comparable, V any](hash uint64, key K, value V) KeyValue[K, V]

NewKeyValue creates a new KeyValue instance with the given key and value.

func (KeyValue[K, V]) GetHash

func (kv KeyValue[K, V]) GetHash() uint64

func (KeyValue[K, V]) GetKey

func (kv KeyValue[K, V]) GetKey() K

Key returns the key of the KeyValue pair.

func (KeyValue[K, V]) GetValue

func (kv KeyValue[K, V]) GetValue() V

Value returns the value of the KeyValue pair.

func (KeyValue[K, V]) IsEmpty

func (kv KeyValue[K, V]) IsEmpty() bool

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options is the base struct for all sets.

func CreateOptions

func CreateOptions[T any](opts ...options.Option[Options]) (Options, error)

CreateOptions creates a new instance of SetBase with the default bucket size.

func (Options) BucketAmount

func (o Options) BucketAmount(capacity uint64) uint64

Jump to

Keyboard shortcuts

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