orderedmap

package module
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2022 License: MIT Imports: 0 Imported by: 46

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element[K comparable, V any] struct {

	// The key that corresponds to this element in the ordered map.
	Key K

	// The value stored with this element.
	Value V
	// contains filtered or unexported fields
}

Element is an element of a null terminated (non circular) intrusive doubly linked list that contains the key of the correspondent element in the ordered map too.

func (*Element[K, V]) Next

func (e *Element[K, V]) Next() *Element[K, V]

Next returns the next list element or nil.

func (*Element[K, V]) Prev

func (e *Element[K, V]) Prev() *Element[K, V]

Prev returns the previous list element or nil.

type OrderedMap

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

func NewOrderedMap

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

func (*OrderedMap[K, V]) Back

func (m *OrderedMap[K, V]) Back() *Element[K, V]

Back will return the element that is the last (most recent Set element). If there are no elements this will return nil.

func (*OrderedMap[K, V]) Copy

func (m *OrderedMap[K, V]) Copy() *OrderedMap[K, V]

Copy returns a new OrderedMap with the same elements. Using Copy while there are concurrent writes may mangle the result.

func (*OrderedMap[K, V]) Delete

func (m *OrderedMap[K, V]) Delete(key K) (didDelete bool)

Delete will remove a key from the map. It will return true if the key was removed (the key did exist).

func (*OrderedMap[K, V]) Front

func (m *OrderedMap[K, V]) Front() *Element[K, V]

Front will return the element that is the first (oldest Set element). If there are no elements this will return nil.

func (*OrderedMap[K, V]) Get

func (m *OrderedMap[K, V]) Get(key K) (value V, ok bool)

Get returns the value for a key. If the key does not exist, the second return parameter will be false and the value will be nil.

func (*OrderedMap[K, V]) GetElement

func (m *OrderedMap[K, V]) GetElement(key K) *Element[K, V]

GetElement returns the element for a key. If the key does not exist, the pointer will be nil.

func (*OrderedMap[K, V]) GetOrDefault

func (m *OrderedMap[K, V]) GetOrDefault(key K, defaultValue V) V

GetOrDefault returns the value for a key. If the key does not exist, returns the default value instead.

func (*OrderedMap[K, V]) Keys

func (m *OrderedMap[K, V]) Keys() (keys []K)

Keys returns all of the keys in the order they were inserted. If a key was replaced it will retain the same position. To ensure most recently set keys are always at the end you must always Delete before Set.

func (*OrderedMap[K, V]) Len

func (m *OrderedMap[K, V]) Len() int

Len returns the number of elements in the map.

func (*OrderedMap[K, V]) Set

func (m *OrderedMap[K, V]) Set(key K, value V) bool

Set will set (or replace) a value for a key. If the key was new, then true will be returned. The returned value will be false if the value was replaced (even if the value was the same).

Jump to

Keyboard shortcuts

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