indexing

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: 6 Imported by: 0

Documentation

Index

Constants

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

func (i *CommonIndex[T]) Clear()

Clear clears the index.

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

type Indexer struct {
	sync.RWMutex
	Indexes map[string]Index
}

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 NewIndexer

func NewIndexer() *Indexer

NewIndexer returns a new Indexer.

func (*Indexer) Clear

func (i *Indexer) Clear()

Clear clears the indexer.

func (*Indexer) Resolve

func (i *Indexer) Resolve(indices Indices) []int

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

func (i *Indexer) Set(id int, indices Indices) error

Set sets the IDs of the objects that match the given keys. It returns an error if any of the indexes returns an error.

func (*Indexer) Unset

func (i *Indexer) Unset(id int) error

Unset removes the given ID from the indexes. It returns an error if any of the indexes returns an error.

func (*Indexer) WithIndex

func (i *Indexer) WithIndex(name string, index Index) *Indexer

WithIndex adds the given index to the indexer. It returns the indexer.

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.

func (Indices) String added in v1.0.2

func (i Indices) String() string

type Set

type Set []int

func (Set) Contains

func (s Set) Contains(id int) bool

func (Set) Intersect

func (s Set) Intersect(other Set) Set

func (Set) Len

func (s Set) Len() int

func (Set) Less

func (s Set) Less(i, j int) bool

func (Set) Sort

func (s Set) Sort() Set

func (Set) Swap

func (s Set) Swap(i, j int)

func (Set) Unique

func (s Set) Unique() Set

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.

Jump to

Keyboard shortcuts

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