Documentation ¶
Index ¶
- type Bucket
- func (b *Bucket[T]) Add(item T, query *Query) error
- func (b *Bucket[T]) All(query *Query) []T
- func (b *Bucket[T]) Clear()
- func (b *Bucket[T]) Count(query *Query) int
- func (b *Bucket[T]) Exists(query *Query) (bool, error)
- func (b *Bucket[T]) Finalize() *Bucket[T]
- func (b *Bucket[T]) Get(query *Query) (T, error)
- func (b *Bucket[T]) Remove(query *Query) error
- func (b *Bucket[T]) WithIndex(name string, index indexing.Index) *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() Operation: adds an item to the bucket. - Get() Operation: gets an item from the bucket. - Remove() Operation: removes an item from the bucket. - Clear() Operation: clears the bucket. - Count() int: counts the number of items in the bucket. - Exists() Operation: checks if an item exists in the bucket. - All() Operation: gets all items from the bucket. - WithIndex(name, Index) *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 ¶
all gets all items from the bucket With no filters, it returns all items. With filters, it returns all items that match the given filters. It returns an empty slice if no items match the given filters. It never returns an error.
func (*Bucket[T]) Count ¶ added in v1.0.2
Count counts all items in the bucket. With no filters, it counts all items. With filters, it counts all items that match the given filters. It returns 0 if no items match the given filters. It never returns an error.
func (*Bucket[T]) Exists ¶
exists checks if an item exists in the bucket. 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. It returns no error if exactly one item matches the given filters. It returns true if exactly one item matches the given filters. It returns false if no item matches the given filters. It returns false if more than one item matches the given filters.
func (*Bucket[T]) Get ¶
get gets the 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 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. It always returns an empty slice.