llrb

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: MIT Imports: 4 Imported by: 3

README

llrb

Go Report Card GoDoc GitHub license gocover.io

LLRB is a Left-Leaning Red-Black Tree Implementation in Golang Generic.

Licensed under the MIT License. See LICENSE for the full license text.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Any

type Any any

type Ordered

type Ordered interface {
	constraints.Ordered
}

type Tree

type Tree[K Ordered, V Any] struct {
	// contains filtered or unexported fields
}

Tree is a left-leaning red-black tree.

func NewTree

func NewTree[K Ordered, V Any]() *Tree[K, V]

NewTree returns a new Tree.

func (*Tree[K, V]) Delete

func (t *Tree[K, V]) Delete(k K) (v V, ok bool)

Delete removes the key-value pair associated with the given key.

func (*Tree[K, V]) DeleteMax

func (t *Tree[K, V]) DeleteMax() (k K, v V, ok bool)

DeleteMax removes the maximum key-value pair from the tree.

func (*Tree[K, V]) DeleteMin

func (t *Tree[K, V]) DeleteMin() (k K, v V, ok bool)

DeleteMin removes the minimum key-value pair from the tree.

func (*Tree[K, V]) Get

func (t *Tree[K, V]) Get(k K) (v V, ok bool)

Get returns the value associated with the given key.

func (*Tree[K, V]) Keys

func (t *Tree[K, V]) Keys() []K

Keys returns a slice of all keys in the tree in ascending order.

func (*Tree[K, V]) Len

func (t *Tree[K, V]) Len() int

Len returns the number of key-value pairs in the tree.

func (*Tree[K, V]) Max

func (t *Tree[K, V]) Max() (k K, v V, ok bool)

Max returns the maximum key-value pair in the tree.

func (*Tree[K, V]) Min

func (t *Tree[K, V]) Min() (k K, v V, ok bool)

Min returns the minimum key-value pair in the tree.

func (*Tree[K, V]) Put

func (t *Tree[K, V]) Put(k K, v V) (ok bool)

Put inserts a key-value pair into the tree.

func (*Tree[K, V]) Range

func (t *Tree[K, V]) Range(fn func(K, V) bool)

Range calls fn for each key-value pair in the tree in ascending order.

func (*Tree[K, V]) String

func (t *Tree[K, V]) String() string

func (*Tree[K, V]) Values

func (t *Tree[K, V]) Values() []V

Values returns a slice of all values in the tree in ascending order.

Jump to

Keyboard shortcuts

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