Documentation ¶
Index ¶
- type Bucket
- func (b *Bucket[T]) Add(item T) error
- func (b *Bucket[T]) All() []T
- func (b *Bucket[T]) Clear()
- func (b *Bucket[T]) Finalize() *Bucket[T]
- func (b *Bucket[T]) One(query *Query) (T, error)
- func (b *Bucket[T]) Remove(query *Query) error
- func (b *Bucket[T]) Some(query *Query) []T
- func (b *Bucket[T]) WithIndex(name string, index core.Index, derivator core.Derivator) *Bucket[T]
- type Query
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket[T comparable] struct { // contains filtered or unexported fields }
Bucket is a generic container for a collection of items. The type of the items is generic, denoted by T. It is thread-safe. Each item gets a unique integer ID. It contains many indexes, each of which maps the 's key to the value's ID. When an item is added to the bucket, it is indexed by the indexes given by the user as a map It supports the following operations: - Add(T) error: adds an item to the bucket. - All() []T: gets all items from the bucket. - One(*Query) (T, error): retrievs the single item from the bucket that matches the provided query. - Some(*Query) []T: retrieves all items from the bucket that match the provided query. - Remove(*Query) error: removes the single item from the bucket that matches the provided query. - Clear(): removes all items and recorded indices from the bucket. - WithIndex(name, Index, Derivator) *Bucket: adds an index to the bucket. - Finalize() *Bucket: finalizes the bucket as ready for use.
func (*Bucket[T]) Add ¶
add adds the given item to the bucket. It returns an error if the item is nil. It returns an error if the item is already in the bucket.
func (*Bucket[T]) All ¶
func (b *Bucket[T]) All() []T
Retrieve all items from the bucket. It returns an empty slice if the bucket is empty.
func (*Bucket[T]) One ¶
Retrieve the single item from the bucket that matches the given filters. It returns an error if no filters are given. It returns an error if no item matches the given filters. It returns an error if more than one item matches the given filters.
func (*Bucket[T]) Remove ¶
remove removes the given item from the bucket. It returns an error if the item doesn't exist. It returns an error if the item is in the bucket more than once.