sortedmap

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2024 License: GPL-3.0 Imports: 1 Imported by: 1

README

sortedmap

?

License

GPL-3


Documentation

Overview

This package provides a generic red-black tree implementation. It is in effect a < ordered key-value map.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparable

type Comparable interface {
	~string | ~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Comparable allows only string or integer keys.

type SortedMap

type SortedMap[K Comparable, V any] struct {
	// contains filtered or unexported fields
}

An SortedMap zero value is usable. Create it with statements like these:

var tree SortedMap[string, int]
tree := SortedMap[int, int]{}

func (*SortedMap[K, V]) All

func (me *SortedMap[K, V]) All() iter.Seq2[K, V]

All is a range function for use as an iterable in a for … range loop that returns all of the tree’s keys and values, e.g.,

for key, value := range tree.All()

See also [Keys] and [Values]

func (*SortedMap[K, V]) Clear

func (me *SortedMap[K, V]) Clear()

Clear deletes all the tree’s key-value items. See also [Delete]

func (*SortedMap[K, V]) Contains

func (me *SortedMap[K, V]) Contains(key K) bool

Contains returns true if the key is in the tree and false otherwise.

func (*SortedMap[K, V]) Delete

func (me *SortedMap[K, V]) Delete(key K) bool

Delete deletes the key-value item with the given key from the tree and returns true, or does nothing and returns false if there is no key-value with the given key. For example:

ok := tree.Delete(key).

See also [Clear]

func (*SortedMap[K, V]) Find

func (me *SortedMap[K, V]) Find(key K) (V, bool)

Find returns the value and true if the key is in the tree or V’s zero value and false otherwise. For example:

value, ok := tree.Find(key)

func (*SortedMap[K, V]) Insert

func (me *SortedMap[K, V]) Insert(key K, value V) bool

Insert inserts a new key-value item into the tree and returns true; or replaces an existing key-value pair’s value if the keys are equal and returns false. For example:

ok := tree.Insert(key, value).

func (*SortedMap[K, V]) Keys

func (me *SortedMap[K, V]) Keys() iter.Seq[K]

Keys is a range function for use as an iterable in a for … range loop that returns all of the tree’s keys:

for key := range tree.Keys()

See also [All] and [Values]

func (*SortedMap[K, V]) Len

func (me *SortedMap[K, V]) Len() int

Len returns the number of items in the tree.

func (*SortedMap[K, V]) Values

func (me *SortedMap[K, V]) Values() iter.Seq[V]

Values is a range function for use as an iterable in a for … range loop that returns all of the tree’s values:

for value := range tree.Values()

See also [All] and [Keys]

Jump to

Keyboard shortcuts

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