Documentation
¶
Index ¶
- Constants
- type CommonIndex
- func (i *CommonIndex[T]) Clear()
- func (i *CommonIndex[T]) Delete(key interface{}) error
- func (i *CommonIndex[T]) DeleteID(id int)
- func (i *CommonIndex[T]) Exists(key interface{}) bool
- func (i *CommonIndex[T]) Get(key interface{}) ([]int, error)
- func (i *CommonIndex[T]) Remove(key interface{}, id int) error
- func (i *CommonIndex[T]) Set(key interface{}, id int) error
- type Index
- type Indexer
- type Indices
- type Set
- type UniqueIndex
Constants ¶
const (
Unknown int = -1
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommonIndex ¶
type CommonIndex[T comparable] struct { // contains filtered or unexported fields }
CommonIndex is a common implementation of Index. It is thread-safe. It is used by Bucket to provide indexes for its items. It supports the following operations:
- Get(T) ([]int, error)
- Set(T, int) error
- Remove(T, int) error
- Delete(key) error
- Clear()
- Exists(T) bool
func NewCommonIndex ¶
func NewCommonIndex[T comparable]() *CommonIndex[T]
NewCommonIndex creates a new CommonIndex.
func (*CommonIndex[T]) Delete ¶
func (i *CommonIndex[T]) Delete(key interface{}) error
Delete deletes the item with the given key.
func (*CommonIndex[T]) DeleteID ¶ added in v1.0.2
func (i *CommonIndex[T]) DeleteID(id int)
DeleteID deletes the item with the given ID.
func (*CommonIndex[T]) Exists ¶
func (i *CommonIndex[T]) Exists(key interface{}) bool
Exists returns true if the item with the given key exists.
func (*CommonIndex[T]) Get ¶
func (i *CommonIndex[T]) Get(key interface{}) ([]int, error)
Get returns the ID of the item with the given key. If the item does not exist, it returns Unknown.
func (*CommonIndex[T]) Remove ¶
func (i *CommonIndex[T]) Remove(key interface{}, id int) error
Remove removes the ID of the item with the given key.
func (*CommonIndex[T]) Set ¶
func (i *CommonIndex[T]) Set(key interface{}, id int) error
Set sets the ID of the item with the given key.
type Index ¶
type Index interface { Get(key interface{}) ([]int, error) Set(key interface{}, id int) error Remove(key interface{}, id int) error Delete(key interface{}) error DeleteID(id int) Clear() Exists(key interface{}) bool }
Index is a generic interface for an index that maps a generic key to one or more IDs It is thread-safe. It is used by Bucket to provide indexes for its items. It supports the following operations:
- Get(T) ([]int, error)
- Set(T, int) error
- Remove(T, int) error
- Delete(key) error
- Clear()
- Exists(T) bool
(where T is the type of the key
and int is the type of the ID and []int is the type of the IDs and error is the type of the error and bool is the type of the boolean
)
type Indexer ¶
Indexer is an index resolver. It is used to resolve a list of IDs that match a list of keys. It uses a map to store indexes by string keys. It is thread-safe. It is used by the Bucket to resolve the IDs of the objects that match a list of keys. It supports both unique and common indexes. It follows the builder pattern. It supports the following operations: - Set(int, map[string]interface{}): sets the IDs of the objects that match the given keys. - Resolve(...key): resolves the IDs of the objects that match the given keys. - Unset(id): removes the given ID from the indexes. - WithIndex(name, index): adds the given index to the indexer. - Clear(): clears the indexer.
func (*Indexer) Resolve ¶
Resolve resolves the IDs of the objects that match the given keys. It returns an error if any of the indexes returns an error.
func (*Indexer) Set ¶
Set sets the IDs of the objects that match the given keys. It returns an error if any of the indexes returns an error.
type Indices ¶
type Indices map[string]interface{}
Indices is a map of index names to interfaces. It is used to provide indexes for an item when it is added to a bucket.
type UniqueIndex ¶
type UniqueIndex[T comparable] struct { *CommonIndex[T] }
UniqueIndex is a unique index. It is thread-safe. It is used by Bucket to provide indexes for its items. It supports the following operations:
- Get(T) ([]int, error)
- Set(T, int) error
- Remove(T, int) error
- Delete(key) error
- Clear()
- Exists(T) bool
func NewUniqueIndex ¶
func NewUniqueIndex[T comparable]() *UniqueIndex[T]
NewUniqueIndex creates a new UniqueIndex.
func (*UniqueIndex[T]) Set ¶
func (i *UniqueIndex[T]) Set(key interface{}, id int) error
Set sets the ID of the item with the given key.