ordered_index

package
v0.0.0-...-e0ee87b Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const Multiply = false

Variables

View Source
var Comparator = func(a, b Key) int { return 0 }
View Source
var KeyFunc = func(v Value) Key { return v }

Functions

This section is empty.

Types

type FinalIndex

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

generic class

type FinalNode

type FinalNode struct {
	GetSuperNode func() interface{}
	GetFinalNode func() interface{}
}

generic class

type Iterator

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

Iterator holding the iterator's state

func (*Iterator) Begin

func (iterator *Iterator) Begin()

Begin resets the iterator to its initial state (one-before-first) Call Next() to fetch the first element if any.

func (*Iterator) Delete

func (iterator *Iterator) Delete()

Delete remove the node which pointed by the iterator Modifies the state of the iterator.

func (*Iterator) End

func (iterator *Iterator) End()

End moves the iterator past the last element (one-past-the-end). Call Prev() to fetch the last element if any.

func (Iterator) HasNext

func (iterator Iterator) HasNext() bool

func (*Iterator) HasPrev

func (iterator *Iterator) HasPrev() bool

func (Iterator) IsBegin

func (iterator Iterator) IsBegin() bool

func (Iterator) IsEnd

func (iterator Iterator) IsEnd() bool

func (Iterator) Key

func (iterator Iterator) Key() Key

Key returns the current element's key. Does not modify the state of the iterator.

func (*Iterator) Next

func (iterator *Iterator) Next() bool

Next moves the iterator to the next element and returns true if there was a next element in the container. If Next() returns true, then next element's key and value can be retrieved by Key() and Value(). If Next() was called for the first time, then it will point the iterator to the first element if it exists. Modifies the state of the iterator.

func (*Iterator) Prev

func (iterator *Iterator) Prev() bool

Prev moves the iterator to the previous element and returns true if there was a previous element in the container. If Prev() returns true, then previous element's key and value can be retrieved by Key() and Value(). Modifies the state of the iterator.

func (Iterator) Value

func (iterator Iterator) Value() Value

Value returns the current element's value. Does not modify the state of the iterator.

type Key

type Key = int

type OrderedIndex

type OrderedIndex struct {
	Root Pointer `*OrderedIndexNode`
	// contains filtered or unexported fields
}

OrderedIndex holds elements of the red-black tree

func (*OrderedIndex) Begin

func (tree *OrderedIndex) Begin() Iterator

func (*OrderedIndex) Clear

func (tree *OrderedIndex) Clear()

Clear removes all nodes from the tree.

func (*OrderedIndex) Empty

func (tree *OrderedIndex) Empty() bool

Empty returns true if tree does not contain any nodes

func (*OrderedIndex) End

func (tree *OrderedIndex) End() Iterator

func (*OrderedIndex) Erase

func (tree *OrderedIndex) Erase(iter Iterator) (itr Iterator)

func (*OrderedIndex) Erases

func (tree *OrderedIndex) Erases(first, last Iterator)

func (*OrderedIndex) Find

func (tree *OrderedIndex) Find(key Key) Iterator

Get searches the node in the tree by key and returns its value or nil if key is not found in tree. Second return parameter is true if key was found, otherwise false. Key should adhere to the comparator's type assertion, otherwise method panics.

func (*OrderedIndex) Insert

func (tree *OrderedIndex) Insert(v Value) (Iterator, bool)

func (*OrderedIndex) Iterator

func (tree *OrderedIndex) Iterator() Iterator

Iterator returns a stateful iterator whose elements are key/value pairs.

func (*OrderedIndex) Keys

func (tree *OrderedIndex) Keys() []Key

Keys returns all keys in-order

func (*OrderedIndex) Left

func (tree *OrderedIndex) Left() *OrderedIndexNode

Left returns the left-most (min) node or nil if tree is empty.

func (*OrderedIndex) LowerBound

func (tree *OrderedIndex) LowerBound(key Key) Iterator

LowerBound returns an iterator pointing to the first element that is not less than the given key. Complexity: O(log N).

func (*OrderedIndex) Modify

func (tree *OrderedIndex) Modify(iter Iterator, mod func(*Value)) bool

func (*OrderedIndex) Remove

func (tree *OrderedIndex) Remove(key Key)

Remove remove the node from the tree by key. Key should adhere to the comparator's type assertion, otherwise method panics.

func (*OrderedIndex) Right

func (tree *OrderedIndex) Right() *OrderedIndexNode

Right returns the right-most (max) node or nil if tree is empty.

func (*OrderedIndex) Size

func (tree *OrderedIndex) Size() int

Size returns number of nodes in the tree.

func (*OrderedIndex) String

func (tree *OrderedIndex) String() string

String returns a string representation of container

func (*OrderedIndex) UpperBound

func (tree *OrderedIndex) UpperBound(key Key) Iterator

UpperBound returns an iterator pointing to the first element that is greater than the given key. Complexity: O(log N).

func (*OrderedIndex) Values

func (tree *OrderedIndex) Values() []Value

Values returns all values in-order based on the key.

type OrderedIndexNode

type OrderedIndexNode struct {
	Key Key

	Left   Pointer `*OrderedIndexNode`
	Right  Pointer `*OrderedIndexNode`
	Parent Pointer `*OrderedIndexNode`
	// contains filtered or unexported fields
}

OrderedIndexNode is a single element within the tree

func NewOrderedIndexNode

func NewOrderedIndexNode(key Key, color color) (n *OrderedIndexNode)

func (*OrderedIndexNode) String

func (node *OrderedIndexNode) String() string

type SuperIndex

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

generic class

func NewSuperIndex

func NewSuperIndex() *SuperIndex

type SuperNode

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

generic class

type Value

type Value = int

template type OrderedIndex(FinalIndex,FinalNode,SuperIndex,SuperNode,Value,Key,KeyFunc,Comparator,Multiply,Allocator)

Jump to

Keyboard shortcuts

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