indexed

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FirstInRange

func FirstInRange[R any](me relation[R], gte, lt R) (ret g.Option[R])

func Iter2

func Iter2[K, V any](me tableInterface[Pair[K, V]]) iter.Seq2[K, V]

func IterFirst

func IterFirst[K, V any](me tableInterface[Pair[K, V]]) iter.Seq[K]

func IterRange

func IterRange[R any](me relation[R], gte, lt R) iter.Seq[R]

func IterSecond

func IterSecond[K, V any](me tableInterface[Pair[K, V]]) iter.Seq[V]

func MapPairIterLeft

func MapPairIterLeft[K, V any](i iter.Seq[Pair[K, V]]) iter.Seq[K]

func MapPairIterRight

func MapPairIterRight[K, V any](i iter.Seq[Pair[K, V]]) iter.Seq[V]

Types

type CompareFunc

type CompareFunc[T any] func(a, b T) int

type Index

type Index[R any] interface {
	SelectFirstIf(gte R, filter func(r R) bool) g.Option[R]
	SelectFirstWhere(gte R, filter func(r R) bool) g.Option[R]
	GetFirst() (R, bool)
	// contains filtered or unexported methods
}

func NewFullIndex

func NewFullIndex[R comparable](from tableInterface[R], cmpFunc CompareFunc[R], minRecord R) (index Index[R])

A full index that doesn't require mapping records.

func NewFullMappedIndex

func NewFullMappedIndex[F, T comparable](
	from tableInterface[F],
	cmpFunc CompareFunc[T],
	mapFunc func(F) T,
	minRecord T,
) Index[T]

An index on a mapped form of the upstream data. What about cross-table and partial indexes?

type Iter

type Iter[R any] iter.Seq[R]

func IterClusteredWhere

func IterClusteredWhere[R any](t relation[R], gte R, where func(r R) bool) Iter[R]

Iters from a point, assuming that where can only be true consecutively from that point and nowhere else.

func (Iter[R]) First

func (me Iter[R]) First() (_ g.Option[R])

type Map

type Map[K, V Record] struct {
	Table2[K, V]
	// contains filtered or unexported fields
}

A table where the record has a key and value. Currently maps onto Table2 using Pair, but perhaps requiring the record implements a KeyValue interface would be better. K and V are Record to propagate the comparable requirement for now. TODO: We could use an actual map, and implement relation. Another thing we can do is actually use btree.Map's value, I'm not sure if btree is smarter about that.

func (*Map[K, V]) Alter

func (me *Map[K, V]) Alter(key K, updateFunc func(V, bool) (V, bool))

func (Map) Change

func (me Map) Change(old, new g.Option[R])

When you know the existing state and the destination state. Most efficient.

func (Map) Changed

func (me Map) Changed(old, new g.Option[R])

func (Map) Contains

func (me Map) Contains(r R) bool

Should this only return a single value ever? Should we check?

func (*Map[K, V]) ContainsKey

func (me *Map[K, V]) ContainsKey(k K) bool

func (Map) CreateOrReplace

func (me Map) CreateOrReplace(r R)

func (*Map[K, V]) Delete

func (me *Map[K, V]) Delete(k K) (removed bool)

func (*Map[K, V]) Get

func (me *Map[K, V]) Get(k K) (v V, ok bool)

func (Map) GetCmp

func (me Map) GetCmp() CompareFunc[R]

func (Map) GetFirst

func (me Map) GetFirst() (r R, ok bool)

func (Map) GetGte

func (me Map) GetGte(r R) (ret g.Option[R])

Gets the first record greater than or equal. Hope to avoid allocation for iterator.

func (*Map[K, V]) Init

func (me *Map[K, V]) Init(cmp func(a, b K) int)

func (Map) Iter

func (me Map) Iter(yield func(R) bool)

func (Map) IterFrom

func (me Map) IterFrom(start R) iter.Seq[R]

func (Map) IterFromWhile

func (me Map) IterFromWhile(gte R, while func(R) bool) iter.Seq[R]

func (Map) Len

func (me Map) Len() int

Not count because that could imply more than O(1) work.

func (Map) MinRecord

func (me Map) MinRecord() (_ R)

Returns the minimal record of type R, which may not be the same as the zero value for the record. Convenient to avoid having to look up complex types for small expressions. Could be a global function. Should definitely be if this is invoked through an interface. Panics if the min record wasn't set. The concept of MinRecord might be flawed if there are conditions in the ordering of values in a record. In that case the user may have to modify "intermediate" fields in order to set a GTE record that's appropriate midway in the table.

func (Map) OnChange

func (me Map) OnChange(t triggerFunc[R])

func (*Map[K, V]) OnValueChange

func (me *Map[K, V]) OnValueChange(do mapTriggerFunc[K, V])

func (Map) SelectFirstIf

func (me Map) SelectFirstIf(gte R, filter func(r R) bool) (ret g.Option[R])

func (Map) SelectFirstWhere

func (me Map) SelectFirstWhere(gte R, where func(r R) bool) (ret g.Option[R])

func (*Map[K, V]) SetMinRecord

func (me *Map[K, V]) SetMinRecord(min K)

Maps don't compare on the value, so we can leave them as zeroes.

func (*Map[K, V]) Update

func (me *Map[K, V]) Update(key K, updateFunc func(V) V) (res UpdateResult)

func (*Map[K, V]) UpdateOrCreate

func (me *Map[K, V]) UpdateOrCreate(k K, updateFunc func(old V) V) (created bool)

Update the function otherwise create it, in both cases using the update function provided.

type Pair

type Pair[K, V any] struct {
	Left  K
	Right V
}

func NewPair

func NewPair[K, V any](left K, right V) Pair[K, V]

func (Pair[K, V]) Flip

func (me Pair[K, V]) Flip() Pair[V, K]

type Record

type Record comparable

Comparable for value-comparison on update function. I think it might be a reasonable requirement. I could add others for the Table2 style, and Map, and allow some global functions to require conforming record types.

type Table

type Table[R comparable] struct {
	// contains filtered or unexported fields
}

func (*Table) Change

func (me *Table) Change(old, new g.Option[R])

When you know the existing state and the destination state. Most efficient.

func (*Table) Changed

func (me *Table) Changed(old, new g.Option[R])

func (*Table) Contains

func (me *Table) Contains(r R) bool

Should this only return a single value ever? Should we check?

func (*Table) Create

func (me *Table) Create(r R) (created bool)

func (*Table) CreateOrReplace

func (me *Table) CreateOrReplace(r R)

func (*Table) Delete

func (me *Table) Delete(r R) (removed bool)

func (*Table) GetCmp

func (me *Table) GetCmp() CompareFunc[R]

func (*Table) GetFirst

func (me *Table) GetFirst() (r R, ok bool)

func (*Table) GetGte

func (me *Table) GetGte(r R) (ret g.Option[R])

Gets the first record greater than or equal. Hope to avoid allocation for iterator.

func (*Table) Init

func (me *Table) Init(cmp func(a, b R) int)

func (*Table) Iter

func (me *Table) Iter(yield func(R) bool)

func (*Table) IterFrom

func (me *Table) IterFrom(start R) iter.Seq[R]

func (*Table) IterFromWhile

func (me *Table) IterFromWhile(gte R, while func(R) bool) iter.Seq[R]

func (*Table) Len

func (me *Table) Len() int

Not count because that could imply more than O(1) work.

func (*Table) MinRecord

func (me *Table) MinRecord() (_ R)

Returns the minimal record of type R, which may not be the same as the zero value for the record. Convenient to avoid having to look up complex types for small expressions. Could be a global function. Should definitely be if this is invoked through an interface. Panics if the min record wasn't set. The concept of MinRecord might be flawed if there are conditions in the ordering of values in a record. In that case the user may have to modify "intermediate" fields in order to set a GTE record that's appropriate midway in the table.

func (*Table) OnChange

func (me *Table) OnChange(t triggerFunc[R])

func (*Table) SelectFirstIf

func (me *Table) SelectFirstIf(gte R, filter func(r R) bool) (ret g.Option[R])

func (*Table) SelectFirstWhere

func (me *Table) SelectFirstWhere(gte R, where func(r R) bool) (ret g.Option[R])

func (*Table) SetMinRecord

func (me *Table) SetMinRecord(min R)

func (*Table) Update

func (me *Table) Update(r R, updateFunc func(r R) R) (existed bool)

type Table2

type Table2[K, V comparable] struct {
	*Table[Pair[K, V]]
}

func (Table2) Change

func (me Table2) Change(old, new g.Option[R])

When you know the existing state and the destination state. Most efficient.

func (Table2) Changed

func (me Table2) Changed(old, new g.Option[R])

func (Table2) Contains

func (me Table2) Contains(r R) bool

Should this only return a single value ever? Should we check?

func (*Table2[K, V]) Create

func (me *Table2[K, V]) Create(first K, second V) bool

func (Table2) CreateOrReplace

func (me Table2) CreateOrReplace(r R)

func (Table2) Delete

func (me Table2) Delete(r R) (removed bool)

func (Table2) GetCmp

func (me Table2) GetCmp() CompareFunc[R]

func (Table2) GetFirst

func (me Table2) GetFirst() (r R, ok bool)

func (Table2) GetGte

func (me Table2) GetGte(r R) (ret g.Option[R])

Gets the first record greater than or equal. Hope to avoid allocation for iterator.

func (*Table2[K, V]) Init

func (me *Table2[K, V]) Init(cmpFunc CompareFunc[Pair[K, V]])

func (Table2) Iter

func (me Table2) Iter(yield func(R) bool)

func (Table2) IterFrom

func (me Table2) IterFrom(start R) iter.Seq[R]

func (Table2) IterFromWhile

func (me Table2) IterFromWhile(gte R, while func(R) bool) iter.Seq[R]

func (*Table2[K, V]) IterKeysFrom

func (me *Table2[K, V]) IterKeysFrom(start K) iter.Seq[K]

func (Table2) Len

func (me Table2) Len() int

Not count because that could imply more than O(1) work.

func (Table2) MinRecord

func (me Table2) MinRecord() (_ R)

Returns the minimal record of type R, which may not be the same as the zero value for the record. Convenient to avoid having to look up complex types for small expressions. Could be a global function. Should definitely be if this is invoked through an interface. Panics if the min record wasn't set. The concept of MinRecord might be flawed if there are conditions in the ordering of values in a record. In that case the user may have to modify "intermediate" fields in order to set a GTE record that's appropriate midway in the table.

func (Table2) OnChange

func (me Table2) OnChange(t triggerFunc[R])

func (Table2) SelectFirstIf

func (me Table2) SelectFirstIf(gte R, filter func(r R) bool) (ret g.Option[R])

func (Table2) SelectFirstWhere

func (me Table2) SelectFirstWhere(gte R, where func(r R) bool) (ret g.Option[R])

func (Table2) SetMinRecord

func (me Table2) SetMinRecord(min R)

func (Table2) Update

func (me Table2) Update(r R, updateFunc func(r R) R) (existed bool)

type UpdateResult

type UpdateResult struct {
	Exists  bool
	Changed bool
}

Jump to

Keyboard shortcuts

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