Version: v0.0.0-...-7e309b4 Latest Latest

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

Go to latest
Published: Aug 21, 2021 License: MIT Imports: 2 Imported by: 0




View Source
const (
	//RED represents red color of node
	RED = 0
	//BLACK represents black color of node
	BLACK = 1


This section is empty.


This section is empty.


type MKey

type MKey int

MKey is int

type MValue

type MValue interface{}

MValue is map value

type Node

type Node struct {
	Left  *Node
	Right *Node
	Color int
	Key   MKey
	Val   MValue

Node is node of tree

type NodeHandler

type NodeHandler interface {
	HandleSameKey(*Node, MKey, MValue) *Node
	MarkDeletion(*Node, MKey, MValue) (*Node, bool)

NodeHandler is interface

type RBMap

type RBMap struct {
	Root *Node

	Handler NodeHandler
	// contains filtered or unexported fields

RBMap is Red-Black tree

func NewRBMap

func NewRBMap() *RBMap

NewRBMap returns new map

func NewRBMapWithHandler

func NewRBMapWithHandler(nhandler NodeHandler) *RBMap

NewRBMapWithHandler returns new map with handler

func (*RBMap) Count

func (rbm *RBMap) Count() int

Count return number of items in RBMap

func (*RBMap) Equals

func (rbm *RBMap) Equals(other *RBMap) bool

Equals return true if maps are equal, false otherwise

func (*RBMap) Get

func (rbm *RBMap) Get(key MKey) (MValue, bool)

Get finds item from map

func (*RBMap) IsEmpty

func (rbm *RBMap) IsEmpty() bool

IsEmpty is true if map is empty, otherwise true

func (*RBMap) Keys

func (rbm *RBMap) Keys() (keys []MKey)

Keys returns list of all keys in map

func (*RBMap) Modify

func (rbm *RBMap) Modify(key MKey, val MValue) (*RBMap, bool)

Modify copies path with modified value

func (*RBMap) Print

func (rbm *RBMap) Print()

Print prints map

func (*RBMap) Put

func (rbm *RBMap) Put(key MKey, val MValue) *RBMap

Put puts value to map

func (*RBMap) Values

func (rbm *RBMap) Values() (values []MValue)

Values returns list of all values in map

func (*RBMap) VisitAll

func (rbm *RBMap) VisitAll(visitor func(*Node))

VisitAll visits all nodes and calls handler

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL