mind

package module
v0.0.0-...-600aab1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 13 Imported by: 0

README

Mind

Build Status License Stars

Mind (Multi Index List) finding list items faster by using indexes.

This allows queries / filters to be improved, as is also the case with databases.

⚠️ Mind is in a very early stage of development and can change!
Advantage

The fast access can be achieved by using different methods, like;

  • hash tables
  • indexing
  • ...
Disadvantage
  • it is more memory required. In addition to the user data, data for the hash, index are also stored.
  • the write operation are slower, because for every wirte operation is an another one (for storing the index data) necessary
Example
package main

import (
	"fmt"

	"github.com/lima1909/mind"
)

type Car struct {
	name string
	age  uint8
}

func (c *Car) Name() string { return c.name }
func (c *Car) Age() uint8   { return c.age }

func main() {

	l := mind.NewList[Car]()

	err := l.CreateIndex("name", mind.NewMapIndex((*Car).Name))
	if err != nil {
		panic(err)
	}
	err = l.CreateIndex("age", mind.NewSortedIndex((*Car).Age))
	if err != nil {
		panic(err)
	}

	l.Insert(Car{name: "Dacia", age: 2})
	l.Insert(Car{name: "Opel", age: 12})
	l.Insert(Car{name: "Mercedes", age: 5})
	l.Insert(Car{name: "Dacia", age: 22})

	qr, err := l.QueryStr(`name = "Opel" or name = "Dacia" or age > 10`)
	if err != nil {
		panic(err)
	}

	fmt.Println(qr.Values())

	// Output:
	// [{Dacia 2} {Opel 12} {Dacia 22}]
}

Documentation

Index

Constants

View Source
const (

	// Structural & Literals
	OpUndefined Op = opStructural | iota
	OpEOF
	OpLParen
	OpRParen
	OpIdent
	OpComma
	OpString
	OpNumberInt
	OpNumberFloat
	OpBool

	// Logical
	OpAnd Op = opLogical | iota
	OpOr
	OpNot

	// Relation
	OpEq         Op = opRelational | (1 << 0)
	OpNeq           = opRelational | (1 << 1)
	OpLt            = opRelational | (1 << 2)
	OpLe            = opRelational | (1 << 3)
	OpGt            = opRelational | (1 << 4)
	OpGe            = opRelational | (1 << 5)
	OpBetween       = opRelational | (1 << 6)
	OpIn            = opRelational | (1 << 7)
	OpStartsWith    = opRelational | (1 << 8)
)
View Source
const IDIndexFieldName = "id"
View Source
const IDMapIndexName = "IDMapIndex"
View Source
const MapIndexName = "MapIndex"
View Source
const SortedIndexName = "SortedIndex"

Variables

This section is empty.

Functions

func ValueFromAny

func ValueFromAny[T any](value any) (T, error)

Types

type BinaryExpr

type BinaryExpr struct {
	Op    ExprKind // exprOr, exprAnd, exprAndNot
	Left  Expr
	Right Expr
}

type BitSet

type BitSet[V Value] struct {
	// contains filtered or unexported fields
}

func NewBitSet

func NewBitSet[V Value]() *BitSet[V]

NewBitSet creates a new BitSet

func NewBitSetFrom

func NewBitSetFrom[V Value](values ...V) *BitSet[V]

NewBitSetFrom creates a new BitSet from given values

func NewBitSetWithCapacity

func NewBitSetWithCapacity[V Value](bits int) *BitSet[V]

NewBitSetWithCapacity creates a new BitSet with starting capacity

func NewEmptyBitSet

func NewEmptyBitSet[V Value]() *BitSet[V]

NewEmptyBitSet creates a new BitSet with len and cap = 0

func (*BitSet[V]) And

func (b *BitSet[V]) And(other *BitSet[V])

And is the logical AND of two BitSet In this BitSet is the result, this means the values will be overwritten!

func (*BitSet[V]) AndNot

func (b *BitSet[V]) AndNot(other *BitSet[V])

AndNot removes all elements from the current set that exist in another set. Known as "Bit Clear" or "Set Difference"

Example: [1, 2, 110, 2345] AndNot [2, 110] => [1, 2345]

func (*BitSet[V]) Clear

func (b *BitSet[V]) Clear()

Clear removes all bits

func (*BitSet[V]) Contains

func (b *BitSet[V]) Contains(value V) bool

Contains check, is the value saved in the BitSet

func (*BitSet[V]) Copy

func (b *BitSet[V]) Copy() *BitSet[V]

Copy copy the complete BitSet.

func (*BitSet[V]) CopyInto

func (b *BitSet[V]) CopyInto(buf []uint64) *BitSet[V]

CopyInto copies the current BitSet into the provided buffer. It returns a new BitSet wrapper sharing the provided buffer. Assumption: cap(buf) >= len(b.data), if not, then panic.

func (*BitSet[V]) Count

func (b *BitSet[V]) Count() int

Counts how many values are in the BitSet, bits are set.

func (*BitSet[V]) IsEmpty

func (b *BitSet[V]) IsEmpty() bool

IsEmpty there are no bits set, means Count() == 0

func (*BitSet[V]) Len

func (b *BitSet[V]) Len() int

Len returns the len of the bit slice

func (*BitSet[V]) Max

func (b *BitSet[V]) Max() int

Max return the max value where an Bit is set [1, 3, 100] => 100 if no max found, return -1

func (*BitSet[V]) MaxSetIndex

func (b *BitSet[V]) MaxSetIndex() int

MaxSetIndex return the max index where an Bit is set

func (*BitSet[V]) Min

func (b *BitSet[V]) Min() int

Min return the min value where an Bit is set [1, 3, 100] => 1 if no max found, return -1

func (*BitSet[V]) Or

func (b *BitSet[V]) Or(other *BitSet[V])

Or is the logical OR of two BitSet

func (*BitSet[V]) Range

func (b *BitSet[V]) Range(from, to V, visit func(v V) bool)

Range iterates over set bits between 'from' and 'to' (inclusive). It calls 'visit' for each found bit. If 'visit' returns false, iteration stops.

func (*BitSet[V]) Set

func (b *BitSet[V]) Set(value V)

Set inserts or updates the key in the BitSet

func (*BitSet[V]) Shrink

func (b *BitSet[V]) Shrink()

Shrink trims the bitset to ensure that len(b.data) always points to the last truly useful word.

Operation Can Grow? Can Shrink? OR Yes No XOR Yes Yes AND No Yes AND NOT No Yes

func (*BitSet[V]) ToSlice

func (b *BitSet[V]) ToSlice() []V

ToSlice create a new slice which contains all saved values

func (*BitSet[V]) UnSet

func (b *BitSet[V]) UnSet(value V) bool

UnSet removes the key from the BitSet. Clear the bit value to 0.

func (*BitSet[V]) Values

func (b *BitSet[V]) Values(yield func(V) bool)

Values iterate over the complete BitSet and call the yield function, for every value

func (*BitSet[V]) ValuesBatch

func (b *BitSet[V]) ValuesBatch(yield func([]V) bool)

func (*BitSet[V]) Xor

func (b *BitSet[V]) Xor(other *BitSet[V])

XOr is the logical XOR of two BitSet

type Expr

type Expr interface {
	// contains filtered or unexported methods
}

type ExprKind

type ExprKind uint8
const (
	ExprTerm ExprKind = iota
	ExprOr
	ExprAnd
	ExprAndNot
	ExprNot
)

type Filter

type Filter[LI Value] interface {
	Match(op Op, value any) (*BitSet[LI], error)
	MatchMany(op Op, values ...any) (*BitSet[LI], error)
}

Filter returns the BitSet or an error by a given Relation and Value

type Filter32

type Filter32 = Filter[uint32]

Filter32 the List only supports uint32 List-Indices

type FilterByName

type FilterByName[LI Value] = func(string) (Filter[LI], error)

FilterByName finds the Filter by a given field-name

type FilterByName32

type FilterByName32 = FilterByName[uint32]

FilterByName32 supports only uint32 List-Indices

type FreeList

type FreeList[T any] struct {
	// contains filtered or unexported fields
}

FreeList don't delete an Item, instead mark it as not occupied. With one of the Compact Methods, you can remove thes palceholders and make the list smaller.

func NewFreeList

func NewFreeList[T any]() FreeList[T]

func (*FreeList[T]) CompactLinear

func (l *FreeList[T]) CompactLinear(onMove func(oldIndex, newIndex int))

CompactLinear removes not used slote. If an Index has changed, yout get this Info with the Callback: onMove

func (*FreeList[T]) CompactUnstable

func (l *FreeList[T]) CompactUnstable()

CompactUnstable removes not used slots. Unstable means, the Indices breaks.

func (*FreeList[T]) Count

func (l *FreeList[T]) Count() int

Count returns the count of the occupied slots

func (*FreeList[T]) Get

func (l *FreeList[T]) Get(index int) (T, bool)

Get the Item on the given index, or the zero value and false, if it not exist. index must be >=0 and < len(slots), otherwise return Get zero value and false and do nothing.

func (*FreeList[T]) Insert

func (l *FreeList[T]) Insert(item T) int

Insert an Item to the end of the List or use a free slot, to add this item

func (*FreeList[T]) Iter

func (l *FreeList[T]) Iter() iter.Seq2[int, T]

Iter create an Iterator, to iterate over all saved Indices and Items

func (*FreeList[T]) Remove

func (l *FreeList[T]) Remove(index int) bool

Remove mark the Item on the given index as deleted. index must be >=0 and < len(slots), otherwise return Remove false and do nothing.

func (*FreeList[T]) Set

func (l *FreeList[T]) Set(index int, newItem T) (T, bool)

Set replaced the Item on the given index, with the given Item. Return the old Item and true. If the given index has no Item, then will the return the zero Value of T and false. index must be >=0 and < len(slots), otherwise return Set zero value and false and do nothing.

type FromField

type FromField[OBJ any, V any] = func(*OBJ) V

FromField is a function, which returns a value from an given object. example: Person{name string} func (p *Person) Name() { return p.name } (*Person).Name is the FieldGetFn

func FromName

func FromName[OBJ any, V any](fieldName string) FromField[OBJ, V]

FromName returns per reflection the propery (field) value from the given object.

func FromValue

func FromValue[V any]() FromField[V, V]

FromValue returns a Getter that simply returns the value itself. Use this when your list contains the raw values you want to index.

type Handle

type Handle struct {
	// contains filtered or unexported fields
}

type Index

type Index[OBJ any, LI Value] interface {
	Set(*OBJ, LI)
	UnSet(*OBJ, LI)
	Filter[LI]
}

Index is interface for handling the mapping of an Value: V to an List-Index: LI The Value V comes from a func(*OBJ) V

type Index32

type Index32[T any] = Index[T, uint32]

Index32 the List only supports uint32 List-Indices

func NewMapIndex

func NewMapIndex[OBJ any, V any](fromField FromField[OBJ, V]) Index32[OBJ]

func NewSortedIndex

func NewSortedIndex[OBJ any, V cmp.Ordered](fieldGetFn FromField[OBJ, V]) Index32[OBJ]

type InvalidArgsLenError

type InvalidArgsLenError struct {
	// contains filtered or unexported fields
}

func (InvalidArgsLenError) Error

func (e InvalidArgsLenError) Error() string

type InvalidNameError

type InvalidNameError struct {
	// contains filtered or unexported fields
}

func (InvalidNameError) Error

func (e InvalidNameError) Error() string

type InvalidOperationError

type InvalidOperationError struct {
	// contains filtered or unexported fields
}

func (InvalidOperationError) Error

func (e InvalidOperationError) Error() string

type InvalidValueTypeError

type InvalidValueTypeError[V any] struct {
	// contains filtered or unexported fields
}

func (InvalidValueTypeError[V]) Error

func (e InvalidValueTypeError[V]) Error() string

type List

type List[T any, ID comparable] struct {
	// contains filtered or unexported fields
}

List is a list (slice), which is extended by Indices for fast finding Items in the list.

func NewList

func NewList[T any]() *List[T, struct{}]

NewList create a new List

func NewListWithID

func NewListWithID[T any, ID comparable](fieldIDGetFn func(*T) ID) *List[T, ID]

NewList create a new List with an ID-Index

func (*List[T, ID]) Contains

func (l *List[T, ID]) Contains(id ID) bool

ContainsID check, is this ID found in the list.

func (*List[T, ID]) Count

func (l *List[T, ID]) Count() int

Count the Items, which in this list exist

func (*List[T, ID]) CreateIndex

func (l *List[T, ID]) CreateIndex(fieldName string, index Index32[T]) error

CreateIndex create a new Index:

  • fieldName: a name for a field of the saved Item
  • fieldGetFn: a function, which returns the value of an field
  • Index: a impl of the Index interface

Hint: empty field-name or the field-name ID are not allowed!

func (*List[T, ID]) Get

func (l *List[T, ID]) Get(id ID) (T, error)

Get returns an item by the given ID. This works ONLY, if an ID is defined (with calling: NewListWithID) errors: - wrong datatype - ID not found - no ID defined

func (*List[T, ID]) Insert

func (l *List[T, ID]) Insert(item T) int

Insert add the given Item to the list, There is NO check, for existing this Item in the list, it will ALWAYS inserting!

func (*List[T, ID]) Query

func (l *List[T, ID]) Query(query Query32) (QueryResult[T, ID], error)

Query execute the given Query.

func (*List[T, ID]) QueryStr

func (l *List[T, ID]) QueryStr(queryStr string) (QueryResult[T, ID], error)

func (*List[T, ID]) Remove

func (l *List[T, ID]) Remove(id ID) (bool, error)

Remove an item by the given ID. This works ONLY, if an ID is defined (with calling: NewListWithID) errors: - wrong datatype - ID not found - no ID defined

func (*List[T, ID]) RemoveIndex

func (l *List[T, ID]) RemoveIndex(fieldName string)

RemoveIndex removed a the Index with the given field-name (what the name of the Index is) With the field-name: ID you can remove the ID-Index

func (*List[T, ID]) Update

func (l *List[T, ID]) Update(item T) error

Update replaces an item and consistently updates all registered indexes.

type MapIndex

type MapIndex[OBJ any, V any, LI Value] struct {
	// contains filtered or unexported fields
}

MapIndex is a mapping of any value to the Index in the List. This index only supported Queries with the Equal Ralation!

func (*MapIndex[OBJ, V, LI]) Match

func (mi *MapIndex[OBJ, V, LI]) Match(op Op, value any) (*BitSet[LI], error)

func (*MapIndex[OBJ, V, LI]) MatchMany

func (mi *MapIndex[OBJ, V, LI]) MatchMany(op Op, values ...any) (*BitSet[LI], error)

MatchMany is not supported by MapIndex, so that always returns an error

func (*MapIndex[OBJ, V, LI]) Set

func (mi *MapIndex[OBJ, V, LI]) Set(obj *OBJ, lidx LI)

func (*MapIndex[OBJ, V, LI]) UnSet

func (mi *MapIndex[OBJ, V, LI]) UnSet(obj *OBJ, lidx LI)

type NoIdIndexDefinedError

type NoIdIndexDefinedError struct{}

func (NoIdIndexDefinedError) Error

func (e NoIdIndexDefinedError) Error() string

type NotExpr

type NotExpr struct{ Child Expr }

type Op

type Op uint16

func (Op) IsLogical

func (o Op) IsLogical() bool

func (Op) IsRelational

func (o Op) IsRelational() bool

func (Op) String

func (o Op) String() string

type OverflowError

type OverflowError struct {
	// contains filtered or unexported fields
}

func (OverflowError) Error

func (o OverflowError) Error() string

type PageInfo

type PageInfo struct {
	Offset uint32
	Limit  uint32
	Count  int
	Total  int
}

type Query

type Query[LI Value] func(l FilterByName[LI], allIDs *BitSet[LI]) (bs *BitSet[LI], canMutate bool, err error)

Query is a filter function, find the correct Index an execute the Index.Get method and returns a BitSet pointer

func And

func And[LI Value](a Query[LI], b Query[LI], other ...Query[LI]) Query[LI]

And combines 2 or more queries with an logical And

func AndNot

func AndNot[LI Value](base Query[LI], sub Query[LI]) Query[LI]

AndNot performs: baseQuery AND NOT(subQuery) example: status = 'active' AND type != 'guest'

func Not

func Not[LI Value](q Query[LI]) Query[LI]

Not Not(Query)

func Or

func Or[LI Value](a Query[LI], b Query[LI], other ...Query[LI]) Query[LI]

Or combines 2 or more queries with an logical Or

type Query32

type Query32 = Query[uint32]

Query32 supports only uint32 List-Indices

func All

func All() Query32

All means returns all Items, no filtering

func Eq

func Eq(fieldName string, val any) Query32

Eq fieldName = val

func Ge

func Ge(fieldName string, val any) Query32

Ge Greater Equal fieldName >= val

func Gt

func Gt(fieldName string, val any) Query32

Gt Greater fieldName > val

func ID

func ID(val any) Query32

ID id = val

func In

func In(fieldName string, vals ...any) Query32

In combines Eq with an Or In("name", "Paul", "Egon") => name == "Paul" Or name == "Egon"

func IsNil

func IsNil[V any](fieldName string) Query32

IsNil is a Query which checks for a given type the nil value

func Le

func Le(fieldName string, val any) Query32

Le Less Equal fieldName <= val

func Lt

func Lt(fieldName string, val any) Query32

Lt Less fieldName < val

func NotEq

func NotEq(fieldName string, val any) Query32

NotEq is a shorcut for Not(Eq(...))

func Parse

func Parse(input string) (Query32, error)

func WithPrefix

func WithPrefix(fieldName string, val string) Query32

Eq fieldName = val

type QueryResult

type QueryResult[T any, ID comparable] struct {
	// contains filtered or unexported fields
}

func (*QueryResult[T, ID]) Count

func (q *QueryResult[T, ID]) Count() int

func (*QueryResult[T, ID]) IsEmpty

func (q *QueryResult[T, ID]) IsEmpty() bool

func (*QueryResult[T, ID]) Pagination

func (q *QueryResult[T, ID]) Pagination(offset, limit uint32) ([]T, PageInfo)

func (*QueryResult[T, ID]) RemoveAll

func (q *QueryResult[T, ID]) RemoveAll()

func (*QueryResult[T, ID]) Sort

func (q *QueryResult[T, ID]) Sort(less func(*T, *T) bool) []T

func (*QueryResult[T, ID]) Values

func (q *QueryResult[T, ID]) Values() []T

type SkipList

type SkipList[K cmp.Ordered, V any] struct {
	// contains filtered or unexported fields
}

func NewSkipList

func NewSkipList[K cmp.Ordered, V any]() SkipList[K, V]

NewSkipList creates a new SkipList

func (*SkipList[K, V]) Delete

func (sl *SkipList[K, V]) Delete(key K) bool

Delete removes the value for a given key If the key was not found: false, otherwise true, if the key was deleted.

func (*SkipList[K, V]) FindFromSortedKeys

func (sl *SkipList[K, V]) FindFromSortedKeys(visit VisitFn[K, V], keys ...K)

FindFromSortedKeys calls visit for all finding keys. Important: they keys slice MUST be sorted!

func (*SkipList[K, V]) FirstValue

func (sl *SkipList[K, V]) FirstValue() (V, bool)

FirstValue returns the value associated with the smallest key or the zero value and false, if the list is empty.

func (*SkipList[K, V]) Get

func (sl *SkipList[K, V]) Get(key K) (V, bool)

Get returns value and whether it exists

func (*SkipList[K, V]) Greater

func (sl *SkipList[K, V]) Greater(key K, visit VisitFn[K, V])

Greater calls visit for all keys > the given key

func (*SkipList[K, V]) GreaterEqual

func (sl *SkipList[K, V]) GreaterEqual(key K, visit VisitFn[K, V])

GreaterEqual calls visit for all keys >= the given key

func (*SkipList[K, V]) LastValue

func (sl *SkipList[K, V]) LastValue() (V, bool)

LastValue returns the value associated with the largest key or the zero value and false, if the list is empty.

func (*SkipList[K, V]) Less

func (sl *SkipList[K, V]) Less(key K, visit VisitFn[K, V])

Less calls visit for all keys < the given key

func (*SkipList[K, V]) LessEqual

func (sl *SkipList[K, V]) LessEqual(key K, visit VisitFn[K, V])

LessEqual calls visit for all keys <= the given key

func (*SkipList[K, V]) MaxKey

func (sl *SkipList[K, V]) MaxKey() (K, bool)

MaxKey returns the last (biggest) Key or the zero value and false, if the list is empty.

func (*SkipList[K, V]) MinKey

func (sl *SkipList[K, V]) MinKey() (K, bool)

MinKey returns the first (smallest) Key or the zero value and false, if the list is empty.

func (*SkipList[K, V]) Put

func (sl *SkipList[K, V]) Put(key K, value V) bool

Put inserts or updates a key with the given value. Returns true if a new node was inserted, false if an existing key was updated.

func (*SkipList[K, V]) Range

func (sl *SkipList[K, V]) Range(from, to K, visit VisitFn[K, V])

Range traverse 'from' until 'to' over Skiplist and calling the visitor

func (*SkipList[K, V]) StringStartsWith

func (sl *SkipList[K, V]) StringStartsWith(prefix K, visit VisitFn[K, V]) bool

StringStartsWith finds all keys with the given prefix. If prefix (K) is not a string, this method panics!

func (*SkipList[K, V]) Traverse

func (sl *SkipList[K, V]) Traverse(visit VisitFn[K, V]) bool

Traverse over the complete Skiplist and calling the visitor the return value false means, not to the end, otherwise true

type SliceSet

type SliceSet[V Value] struct {
	// contains filtered or unexported fields
}

func NewSliceSet

func NewSliceSet[V Value]() *SliceSet[V]

NewSliceSet creates a new SliceSet

func NewSliceSetFrom

func NewSliceSetFrom[V Value](values ...V) *SliceSet[V]

NewSliceSetFrom creates a new SliceSet from given values

func NewSliceSetWithCapacity

func NewSliceSetWithCapacity[V Value](size int) *SliceSet[V]

NewSliceSetWithCapacity creates a new SliceSet with starting capacity

func (*SliceSet[V]) And

func (s *SliceSet[V]) And(other *SliceSet[V])

And computes the logical And, (intersection) of two sorted Set.

func (*SliceSet[V]) AndNot

func (s *SliceSet[V]) AndNot(other *SliceSet[V])

AndNot removes all elements from the current Set that exist in another Set. Known as "Clear" or "Difference"

Example: [1, 2, 110, 2345] AndNot [2, 110] => [1, 2345]

func (*SliceSet[V]) Contains

func (s *SliceSet[V]) Contains(value V) bool

Contains check, is the value saved in the Set

func (*SliceSet[V]) Copy

func (s *SliceSet[V]) Copy() *SliceSet[V]

Copy copy the complete Set.

func (*SliceSet[V]) Count

func (s *SliceSet[V]) Count() int

Counts how many values are in the Set, the len of the Set.

func (*SliceSet[V]) Len

func (s *SliceSet[V]) Len() int

Len how many values are in the Set, the len of the Set.

func (*SliceSet[V]) Max

func (s *SliceSet[V]) Max() int

Max return the max value of this Set [1, 3, 100] => 100 if the set is empty, return -1

func (*SliceSet[V]) MaxSetIndex

func (s *SliceSet[V]) MaxSetIndex() int

MaxSetIndex return the max index the Set

func (*SliceSet[V]) Min

func (s *SliceSet[V]) Min() int

Min return the min value of this Set [1, 3, 100] => 1 if the set is empty, return -1

func (*SliceSet[V]) Or

func (s *SliceSet[V]) Or(other *SliceSet[V])

Or computes the logical OR (union) of two sorted Set.

func (*SliceSet[V]) Set

func (s *SliceSet[V]) Set(value V)

Set inserts or updates the key in the Set

func (*SliceSet[V]) ToBitSet

func (s *SliceSet[V]) ToBitSet() *BitSet[V]

func (*SliceSet[V]) ToSlice

func (s *SliceSet[V]) ToSlice() []V

func (*SliceSet[V]) UnSet

func (s *SliceSet[V]) UnSet(value V) bool

UnSet removes the key from the Set.

func (*SliceSet[V]) Values

func (s *SliceSet[V]) Values(yield func(V) bool)

func (*SliceSet[V]) Xor

func (s *SliceSet[V]) Xor(other *SliceSet[V])

Xor computes the logical XOR of two sorted Set.

type SlotMap

type SlotMap[T any] struct {
	// contains filtered or unexported fields
}

func NewSlotMap

func NewSlotMap[T any]() *SlotMap[T]

func (*SlotMap[T]) Add

func (s *SlotMap[T]) Add(value T) Handle

Add an Item to the end of the List or use a free slot, to add this item. If the Item is insert on a free slot, the index is reused, but the generation will be increments by one.

func (*SlotMap[T]) Compact

func (s *SlotMap[T]) Compact(move func(oldIndex, newIndex uint32))

Compact removes all free slots from the SlotMap. This invalidates existing handles! It returns a map of {OldIndex -> NewIndex} so you can fix your handles.

func (*SlotMap[T]) Get

func (s *SlotMap[T]) Get(h Handle) (T, bool)

Get the Item on the given index, or the zero value and false, if it not exist.

func (*SlotMap[T]) Iter

func (s *SlotMap[T]) Iter() iter.Seq2[Handle, T]

Iter create an Iterator, to iterate over all saved Indices and Items

func (*SlotMap[T]) Len

func (s *SlotMap[T]) Len() int

func (*SlotMap[T]) Remove

func (s *SlotMap[T]) Remove(h Handle) bool

Remove mark the Item on the given index as deleted.

type SortedIndex

type SortedIndex[OBJ any, V cmp.Ordered, LI Value] struct {
	// contains filtered or unexported fields
}

SortedIndex is well suited for Queries with: Range, Min, Max, Greater and Less

func (*SortedIndex[OBJ, V, LI]) Match

func (si *SortedIndex[OBJ, V, LI]) Match(op Op, value any) (*BitSet[LI], error)

func (*SortedIndex[OBJ, V, LI]) MatchMany

func (si *SortedIndex[OBJ, V, LI]) MatchMany(op Op, values ...any) (*BitSet[LI], error)

func (*SortedIndex[OBJ, V, LI]) Set

func (si *SortedIndex[OBJ, V, LI]) Set(obj *OBJ, lidx LI)

func (*SortedIndex[OBJ, V, LI]) UnSet

func (si *SortedIndex[OBJ, V, LI]) UnSet(obj *OBJ, lidx LI)

type TermExpr

type TermExpr struct {
	Field string
	Op    Op
	Value any
}

type TermManyExpr

type TermManyExpr struct {
	Field            string
	Op               Op
	Values           []any
	MinIncl, MaxIncl bool
}

type TrigramIndex

type TrigramIndex struct {
	// contains filtered or unexported fields
}

func NewTrigramIndex

func NewTrigramIndex(s ...string) TrigramIndex

func (*TrigramIndex) Delete

func (ti *TrigramIndex) Delete(li int) bool

func (*TrigramIndex) Get

func (ti *TrigramIndex) Get(query string) *BitSet[uint32]

func (*TrigramIndex) Len

func (ti *TrigramIndex) Len() int

func (*TrigramIndex) Put

func (ti *TrigramIndex) Put(s string, li int)

type UnexpectedTokenError

type UnexpectedTokenError struct {
	// contains filtered or unexported fields
}

func (UnexpectedTokenError) Error

func (e UnexpectedTokenError) Error() string

type Value

type Value interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

type ValueNotFoundError

type ValueNotFoundError struct {
	// contains filtered or unexported fields
}

func (ValueNotFoundError) Error

func (e ValueNotFoundError) Error() string

type VisitFn

type VisitFn[K any, V any] func(key K, val V) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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