orderedmap

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

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

Map is a map datastructure that allows accessing it's element in a fixed order.

func New

func New[K comparable, V any]() *Map[K, V]

func (*Map[K, V]) AsSlice

func (m *Map[K, V]) AsSlice() []V

AsSlice returns a new slice containing the elements of the orderedMap in order.

func (*Map[K, V]) Dequeue

func (m *Map[K, V]) Dequeue(key K) (removedElem V)

Dequeue removes the value with the key from the map and returns it. If thekey does not exist in the map, the zero value is returned.

func (*Map[K, V]) EnqueueIfNotExist

func (m *Map[K, V]) EnqueueIfNotExist(key K, val V) (isFirst, added bool)

EnqueueIfNotExist adds val to the map if K does not exist.

func (*Map[K, V]) First

func (m *Map[K, V]) First() V

First returns the first element in the map. If the map is empty, the zero value is returned.

func (*Map[K, V]) Foreach

func (m *Map[K, V]) Foreach(fn func(V) bool)

Foreach itereates through the map in order. When fn returns false the iteration is aborted.

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(key K) V

Get returns the value for the given key. If the key does not exist, the zero value is returned

func (*Map[K, V]) Len

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

Len returns the number of elements in the maps.

Jump to

Keyboard shortcuts

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