orderedmap

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator[K comparable, V any] struct {
	Key   *K
	Value V
	// contains filtered or unexported fields
}

Iterator starting at OrderedMap.Front or OrderedMap.Back

func (*Iterator[K, V]) Next

func (n *Iterator[K, V]) Next() *Iterator[K, V]

Next gets the next keyValue or nil when no more values can be iterated on

func (*Iterator[K, V]) Prev

func (n *Iterator[K, V]) Prev() *Iterator[K, V]

Prev gets the previous keyValue or nil when no more values can be iterated on

type OrderedMap

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

OrderedMap definition data is stored in insertion order

func NewOrderedMap

func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]

NewOrderedMap creates a new OrderedMap of type K

func (*OrderedMap[K, V]) Back

func (o *OrderedMap[K, V]) Back() *Iterator[K, V]

Back returns an Iterator pointing to the newest (inserted-last) keyValue

func (*OrderedMap[K, V]) Count

func (o *OrderedMap[K, V]) Count() int

Count returns the count of keys in OrderedMap

func (*OrderedMap[K, V]) Delete

func (o *OrderedMap[K, V]) Delete(key K)

Delete will remove the key and its associated value.

func (*OrderedMap[K, V]) Front

func (o *OrderedMap[K, V]) Front() *Iterator[K, V]

Front returns an iterator pointing to the oldest (inserted-first) keyValue

func (*OrderedMap[K, V]) Get

func (o *OrderedMap[K, V]) Get(key K) (V, bool)

Get will return the value associated with the key. If the key doesn't exist, the second return value will be false.

func (*OrderedMap[K, V]) Iterator

func (o *OrderedMap[K, V]) Iterator() func() (*int, *K, V)

Iterator is used to loop through the stored key-value pairs. The returned anonymous function returns the index, key and value.

func (*OrderedMap[K, V]) Set

func (o *OrderedMap[K, V]) Set(key K, val V)

Set will store a key-value pair. If the key already exists, it will overwrite the existing key-value pair

Jump to

Keyboard shortcuts

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