groupkey

package
v0.172.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cols []flux.ColMeta, values []values.Value) flux.GroupKey

Types

type Lookup

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

Lookup is a container that maps group keys to a value.

The Lookup container is optimized for appending values in order and iterating over them in the same order. The Lookup will always have a deterministic order for the Range call, but that order may be influenced by the order that inserts happen.

At the current moment, the Lookup maintains the groups in sorted order although future implementations may change that.

To optimize inserts, the lookup is kept in an array of arrays. The first layer keeps a group of sorted key groups and each of these groups maintains their own sorted list of keys. Each time a new key is added, it is appended to the end of one of the key lists. If a key needs to be added in the middle of a list, the list is split into two so that the key can be appended. The index of the last list to be used is maintained so that future inserts can skip past the first search for the key list and an insert can be done in constant time. Similarly, a lookup for a key that was just inserted will also be in constant time with the worst case time being O(n log n).

func NewLookup

func NewLookup() *Lookup

NewLookup constructs a Lookup.

func (*Lookup) Clear

func (l *Lookup) Clear()

Clear will clear the group lookup and reset it to contain nothing.

func (*Lookup) Delete

func (l *Lookup) Delete(key flux.GroupKey) (v interface{}, found bool)

Delete will remove the key from this Lookup. It will return the same thing as a call to Lookup.

func (*Lookup) Lookup

func (l *Lookup) Lookup(key flux.GroupKey) (interface{}, bool)

Lookup will retrieve the value associated with the given key if it exists.

func (*Lookup) LookupOrCreate

func (l *Lookup) LookupOrCreate(key flux.GroupKey, fn func() interface{}) interface{}

LookupOrCreate will retrieve the value associated with the given key or, if it does not exist, will invoke the function to create one and set it in the group lookup.

func (*Lookup) Range

func (l *Lookup) Range(f func(key flux.GroupKey, value interface{}) error) error

Range will iterate over all groups keys in a stable ordering. Range must not be called within another call to Range. It is safe to call Set/Delete while ranging.

func (*Lookup) Set

func (l *Lookup) Set(key flux.GroupKey, value interface{})

Set will set the value for the given key. It will overwrite an existing value.

type RandomAccessLookup

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

RandomAccessLookup is a GroupLookup container that is optimized for random access.

func NewRandomAccessLookup

func NewRandomAccessLookup() *RandomAccessLookup

NewRandomAccessLookup constructs a RandomAccessLookup.

func (*RandomAccessLookup) Clear

func (l *RandomAccessLookup) Clear()

Clear will clear the group lookup and reset it to contain nothing.

func (*RandomAccessLookup) Delete

func (l *RandomAccessLookup) Delete(key flux.GroupKey) (v interface{}, found bool)

Delete will remove the key from this GroupLookup. It will return the same thing as a call to Lookup.

func (*RandomAccessLookup) Lookup

func (l *RandomAccessLookup) Lookup(key flux.GroupKey) (interface{}, bool)

Lookup will retrieve the value associated with the given key if it exists.

func (*RandomAccessLookup) LookupOrCreate

func (l *RandomAccessLookup) LookupOrCreate(key flux.GroupKey, fn func() interface{}) interface{}

LookupOrCreate will retrieve the value associated with the given key or, if it does not exist, will invoke the function to create one and set it in the group lookup.

func (*RandomAccessLookup) Range

func (l *RandomAccessLookup) Range(f func(key flux.GroupKey, value interface{}) error) error

Range will iterate over all groups keys in a stable ordering. Range must not be called within another call to Range. It is safe to call Set/Delete while ranging.

func (*RandomAccessLookup) Set

func (l *RandomAccessLookup) Set(key flux.GroupKey, value interface{})

Set will set the value for the given key. It will overwrite an existing value.

Jump to

Keyboard shortcuts

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