orderedmap

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2025 License: AGPL-3.0 Imports: 4 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 data structure that allows accessing it's element in a fixed order.

func New

func New[K comparable, V any](cmp func(a, b V) int) *Map[K, V]

New creates a new Map that orders inserted elements in ascending order after the first element accordingly to the cmp function. The position of the first element is fixed!

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 the key does not exist in the map, the zero value is returned.

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() iter.Seq[V]

Foreach returns an ordered iterator over the values.

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]) InsertIfNotExist

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

InsertIfNotExist adds val to the map if K does not exist. val is inserted at the position determined by the cmp function, but always after the first element.

func (*Map[K, V]) Len

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

Len returns the number of elements in the maps.

func (*Map[K, V]) SortByKey

func (m *Map[K, V]) SortByKey(cmp func(a, b K) int)

Jump to

Keyboard shortcuts

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