treemap

package
v0.0.0-...-c626c17 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package treemap implements a map backed by red-black Tree.

Elements are ordered by key in the map.

Structure is not thread safe.

Reference: http://en.wikipedia.org/wiki/Associative_array

Index

Constants

This section is empty.

Variables

View Source
var Compare = func(a, b interface{}) int { return container.IntComparator(a.(int), b.(int)) }
View Source
var Multi = false

Functions

This section is empty.

Types

type Iterator

type Iterator struct {
	rbt.Iterator
}

Iterator holding the Iterator's state

func (Iterator) Key

func (iterator Iterator) Key() K

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

func (Iterator) Value

func (iterator Iterator) Value() V

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

type K

type K int

template type Map(K,V,Compare,Multi)

type Map

type Map struct {
	*rbt.Tree
}

Map holds the elements in a red-black Tree

func CopyFrom

func CopyFrom(tm *Map) *Map

func New

func New() *Map

NewWith instantiates a Tree map with the custom comparator.

func (*Map) Begin

func (m *Map) Begin() Iterator

Begin returns First Iterator whose position points to the first element Return End Iterator when the map is empty

func (*Map) Each

func (m *Map) Each(f func(key K, value V))

Each calls the given function once for each element, passing that element's key and value.

func (*Map) End

func (m *Map) End() Iterator

End returns End Iterator

func (*Map) Find

func (m *Map) Find(f func(key K, value V) bool) (k K, v V)

Find passes each element of the container to the given function and returns the first (key,value) for which the function is true or nil,nil otherwise if no element matches the criteria.

func (*Map) Get

func (m *Map) Get(key K) Iterator

Get searches the element in the map 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 (*Map) Insert

func (m *Map) Insert(key K, value V) Iterator

func (*Map) Iterator

func (m *Map) Iterator() Iterator

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

func (*Map) Keys

func (m *Map) Keys() []K

Keys returns all keys in-order

func (*Map) LowerBound

func (m *Map) LowerBound(key K) Iterator

func (Map) MarshalJSON

func (m Map) MarshalJSON() ([]byte, error)

func (Map) Pack

func (m Map) Pack() (re []byte, err error)

func (*Map) Put

func (m *Map) Put(key K, value V)

Put inserts key-value pair into the map. Key should adhere to the comparator's type assertion, otherwise method panics.

func (*Map) Remove

func (m *Map) Remove(key K)

Remove removes the element from the map by key. Key should adhere to the comparator's type assertion, otherwise method panics.

func (Map) String

func (m Map) String() string

String returns a string representation of container

func (*Map) UnmarshalJSON

func (m *Map) UnmarshalJSON(data []byte) error

FromJSON populates the map from the input JSON representation.

func (*Map) Unpack

func (m *Map) Unpack(in []byte) (int, error)

func (*Map) UpperBound

func (m *Map) UpperBound(key K) Iterator

func (*Map) Values

func (m *Map) Values() []V

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

type V

type V int

Directories

Path Synopsis
Package treemap implements a map backed by red-black Tree.
Package treemap implements a map backed by red-black Tree.

Jump to

Keyboard shortcuts

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