strtree

package
v0.0.0-...-66ceba8 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: Apache-2.0 Imports: 2 Imported by: 8

Documentation

Overview

Package strtree implements red-black tree for key value pairs with string keys and custom comparison.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Compare

type Compare func(a, b string) int

Compare defines function interface for custom comparison. Function implementing the interface should return value less than zero if its first argument precedes second one, zero if both are equal and positive if the second precedes.

type Pair

type Pair struct {
	Key   string
	Value interface{}
}

Pair is a key-value pair representing tree node content.

type Tree

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

Tree is a red-black tree for key-value pairs where key is string.

func NewTree

func NewTree() *Tree

NewTree creates empty tree with default comparison operation (strings.Compare).

func NewTreeWithCustomComparison

func NewTreeWithCustomComparison(compare Compare) *Tree

NewTreeWithCustomComparison creates empty tree with given comparison operation.

func (*Tree) Delete

func (t *Tree) Delete(key string) (*Tree, bool)

Delete removes node by given key. It returns copy of tree and true if node has been indeed deleted otherwise original tree and false.

func (*Tree) Dot

func (t *Tree) Dot() string

Dot dumps tree to Graphviz .dot format.

func (*Tree) Enumerate

func (t *Tree) Enumerate() chan Pair

Enumerate returns channel which is populated by key pair values in order of keys.

func (*Tree) Get

func (t *Tree) Get(key string) (interface{}, bool)

Get returns value by given key.

func (*Tree) InplaceInsert

func (t *Tree) InplaceInsert(key string, value interface{})

InplaceInsert inserts or replaces given key-value pair in the tree. The method inserts data directly to current tree so make sure you have exclusive access to it.

func (*Tree) Insert

func (t *Tree) Insert(key string, value interface{}) *Tree

Insert puts given key-value pair to the tree and returns pointer to new root.

func (*Tree) IsEmpty

func (t *Tree) IsEmpty() bool

IsEmpty returns true if given tree has no nodes.

Jump to

Keyboard shortcuts

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