thresholdmap

package
v0.0.0-...-25ef478 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2023 License: Apache-2.0, BSD-2-Clause Imports: 3 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// LowerThresholdMode interprets the keys of the ThresholdMap as lower thresholds which means that querying the map
	// will return the value of the largest node whose key is <= than the queried value.
	LowerThresholdMode = true

	// UpperThresholdMode interprets the keys of the ThresholdMap as upper thresholds which means that querying the map
	// will return the value of the smallest node whose key is >= than the queried value.
	UpperThresholdMode = false
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element struct {
	*redblacktree.Node
}

Element is a wrapper for the Node used in the underlying red-black RedBlackTree.

func (*Element) Key

func (e *Element) Key() interface{}

Key returns the Key of the Element.

func (*Element) Value

func (e *Element) Value() interface{}

Value returns the Value of the Element.

type Iterator

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

Iterator is an object that allows to iterate over the ThresholdMap by providing methods to walk through the map in a deterministic order.

func NewIterator

func NewIterator(startingElement *Element) *Iterator

NewIterator is the constructor of the Iterator that takes the starting Element as its parameter.

func (*Iterator) HasNext

func (i *Iterator) HasNext() bool

HasNext returns true if there is another Element after the previously retrieved Element that can be requested via the Next method.

func (*Iterator) HasPrev

func (i *Iterator) HasPrev() bool

HasPrev returns true if there is another Element before the previously retrieved Element that can be requested via the Prev method.

func (*Iterator) Next

func (i *Iterator) Next() *Element

Next returns the next Element in the Iterator and advances the internal pointer. The method panics if there is no next Element that can be retrieved (always use HasNext to check if another Element can be requested).

func (*Iterator) Prev

func (i *Iterator) Prev() *Element

Prev returns the previous Element in the Iterator and moves back the internal pointer. The method panics if there is no previous Element that can be retrieved (always use HasPrev to check if another Element can be requested).

func (*Iterator) Reset

func (i *Iterator) Reset()

Reset resets the Iterator to its initial Element.

func (*Iterator) State

func (i *Iterator) State() IteratorState

State returns the current IteratorState that the Iterator is in.

type IteratorState

type IteratorState int

IteratorState represents the state of the Iterator that is used to track where in the set of contained Elements the pointer is currently located.

const (
	// InitialState is the state of the Iterator before the first Element has been retrieved.
	InitialState IteratorState = iota

	// IterationStartedState is the state of the Iterator after the first Element has been retrieved and before we have
	// reached either the first or the last Element.
	IterationStartedState

	// LeftEndReachedState is the state of the Iterator after we have reached the smallest Element.
	LeftEndReachedState

	// RightEndReachedState is the state of the Iterator after we have reached the largest Element.
	RightEndReachedState
)

type Mode

type Mode bool

Mode encodes different modes of function for the ThresholdMap that specifies if the defines keys act as upper or lower thresholds.

type ThresholdMap

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

ThresholdMap is a data structure that allows to map keys bigger or lower than a certain threshold to a given value.

func New

func New(mode Mode, optionalComparator ...genericcomparator.Type) *ThresholdMap

New returns a ThresholdMap that operates in the given Mode and that can also receive an optional comparator function to support custom key types.

func (*ThresholdMap) Ceiling

func (t *ThresholdMap) Ceiling(key interface{}) (floorKey interface{}, floorValue interface{}, exists bool)

Ceiling returns the smallest key that is >= the given key, it's value and a boolean flag indicating if it exists.

func (*ThresholdMap) Clear

func (t *ThresholdMap) Clear()

Clear removes all Elements from the map.

func (*ThresholdMap) Delete

func (t *ThresholdMap) Delete(key interface{}) (element *Element, success bool)

Delete removes a threshold from the map.

func (*ThresholdMap) DeleteElement

func (t *ThresholdMap) DeleteElement(element *Element)

DeleteElement removes the given Element from the map.

func (*ThresholdMap) Empty

func (t *ThresholdMap) Empty() bool

Empty returns true of the map has no thresholds.

func (*ThresholdMap) Floor

func (t *ThresholdMap) Floor(key interface{}) (floorKey interface{}, floorValue interface{}, exists bool)

Floor returns the largest key that is <= the given key, it's value and a boolean flag indicating if it exists.

func (*ThresholdMap) ForEach

func (t *ThresholdMap) ForEach(iterator func(node *Element) bool)

ForEach provides a callback based iterator that iterates through all Elements in the map.

func (*ThresholdMap) Get

func (t *ThresholdMap) Get(key interface{}) (value interface{}, exists bool)

Get returns the value of the next higher or lower existing threshold (depending on the mode) and a flag that indicates if there is a threshold that covers the given value.

func (*ThresholdMap) GetElement

func (t *ThresholdMap) GetElement(key interface{}) *Element

GetElement returns the Element that is used to store the next higher or lower threshold (depending on the mode) belonging to the given key (or nil if none exists).

func (*ThresholdMap) Iterator

func (t *ThresholdMap) Iterator(optionalStartingNode ...*Element) *Iterator

Iterator returns an Iterator object that can be used to manually iterate through the Elements in the map. It accepts an optional starting Element where the iteration begins.

func (*ThresholdMap) Keys

func (t *ThresholdMap) Keys() []interface{}

Keys returns a list of thresholds that have been set in the map.

func (*ThresholdMap) MaxElement

func (t *ThresholdMap) MaxElement() *Element

MaxElement returns the largest threshold in the map (or nil if the map is empty).

func (*ThresholdMap) MinElement

func (t *ThresholdMap) MinElement() *Element

MinElement returns the smallest threshold in the map (or nil if the map is empty).

func (*ThresholdMap) Set

func (t *ThresholdMap) Set(key interface{}, value interface{})

Set adds a new threshold that maps all keys >= or <= (depending on the Mode) the value given by key to a certain value.

func (*ThresholdMap) Size

func (t *ThresholdMap) Size() int

Size returns the amount of thresholds that are stored in the map.

func (*ThresholdMap) Values

func (t *ThresholdMap) Values() []interface{}

Values returns a list of values that are associated to the thresholds in the map.

Jump to

Keyboard shortcuts

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