ordered_map

package
v0.0.0-...-5eefc96 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface[K cmp.Ordered, V any] interface {
	Len() int
	Get(key K) (V, bool)
	GetMutable(key K) (*V, bool)
	Set(key K, value V)
	// SetReturn(key K, value V) (old V, replaced bool)
	Delete(key K) bool
	// DeleteReturn(key K) (old V, deleted bool)
	Has(key K) bool

	Keys() []K
	Values() []V
	Pairs() []pair.Pair[K, V]

	KeySeq() iter.Seq[K]
	ValueSeq() iter.Seq[V]
	PairSeq() iter.Seq2[K, V]
}

type RedBlackTree

type RedBlackTree[K cmp.Ordered, V any] struct {
	// contains filtered or unexported fields
}

RedBlackTree implements the ordered_map.Interface using a Red-Black Tree.

func NewRedBlackTree

func NewRedBlackTree[K cmp.Ordered, V any]() *RedBlackTree[K, V]

NewRedBlackTree creates a new RedBlackTree.

func (*RedBlackTree[K, V]) Cap

func (t *RedBlackTree[K, V]) Cap() int

Cap returns the capacity of the map. For Red-Black Tree, capacity equals size since it's dynamic.

func (*RedBlackTree[K, V]) Delete

func (t *RedBlackTree[K, V]) Delete(key K) bool

Delete removes a key from the map.

func (*RedBlackTree[K, V]) Get

func (t *RedBlackTree[K, V]) Get(key K) (V, bool)

Get searches for a key and returns its value and existence.

func (*RedBlackTree[K, V]) GetMutable

func (t *RedBlackTree[K, V]) GetMutable(key K) (*V, bool)

GetMutable returns a pointer to the value for mutation.

func (*RedBlackTree[K, V]) Has

func (t *RedBlackTree[K, V]) Has(key K) bool

Has checks if a key exists in the map.

func (*RedBlackTree[K, V]) KeySeq

func (t *RedBlackTree[K, V]) KeySeq() iter.Seq[K]

KeySeq returns an iterator for keys (go1.23). Uses efficient iterative in-order traversal without pre-allocating all keys.

func (*RedBlackTree[K, V]) Keys

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

Keys returns all keys in order.

func (*RedBlackTree[K, V]) Len

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

Len returns the number of elements in the map.

func (*RedBlackTree[K, V]) PairSeq

func (t *RedBlackTree[K, V]) PairSeq() iter.Seq2[K, V]

PairSeq returns an iterator for key-value pairs (go1.23). Uses efficient iterative in-order traversal without pre-allocating all pairs.

func (*RedBlackTree[K, V]) Pairs

func (t *RedBlackTree[K, V]) Pairs() []pair.Pair[K, V]

Pairs returns all key-value pairs in order.

func (*RedBlackTree[K, V]) Set

func (t *RedBlackTree[K, V]) Set(key K, value V)

Set inserts or updates a key-value pair.

func (*RedBlackTree[K, V]) ValueSeq

func (t *RedBlackTree[K, V]) ValueSeq() iter.Seq[V]

ValueSeq returns an iterator for values (go1.23). Uses efficient iterative in-order traversal without pre-allocating all values.

func (*RedBlackTree[K, V]) Values

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

Values returns all values in order.

Jump to

Keyboard shortcuts

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