storage

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

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 NewBucket

func NewBucket[T comparable]() *Bucket[T]

NewBucket creates a new Bucket.

func (*Bucket[T]) Add

func (b *Bucket[T]) Add(item T, query *Query) error

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(query *Query) []T

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]) Clear

func (b *Bucket[T]) Clear()

clear clears the bucket.

func (*Bucket[T]) Count added in v1.0.2

func (b *Bucket[T]) Count(query *Query) int

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

func (b *Bucket[T]) Exists(query *Query) (bool, error)

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]) Finalize

func (b *Bucket[T]) Finalize() *Bucket[T]

Finalize finalizes the bucket as ready for use.

func (*Bucket[T]) Get

func (b *Bucket[T]) Get(query *Query) (T, error)

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

func (b *Bucket[T]) Remove(query *Query) error

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.

func (*Bucket[T]) WithIndex

func (b *Bucket[T]) WithIndex(name string, index indexing.Index) *Bucket[T]

WithIndex adds an index to the bucket.

type Query

type Query struct {
	Indices indexing.Indices
}

func NewQuery

func NewQuery() *Query

func (*Query) Finalize added in v1.0.2

func (q *Query) Finalize() (indexing.Indices, error)

func (*Query) String added in v1.0.2

func (q *Query) String() string

func (*Query) Where

func (q *Query) Where(name string, value interface{}) *Query

Jump to

Keyboard shortcuts

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