ordered

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: BSD-2-Clause Imports: 0 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 represents an ordered map.

func NewMap

func NewMap[K comparable, V any](initialData ...Pair[K, V]) *Map[K, V]

NewMap creates a new ordered map with optional initial data.

func (*Map[K, V]) Clear

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

Clear removes all pairs from the map.

func (*Map[K, V]) Delete

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

Delete removes a key-value pair from the map.

func (*Map[K, V]) Keys

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

Keys returns a slice of all keys in the map in order.

func (*Map[K, V]) Len

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

Len returns the number of pairs in the map.

func (*Map[K, V]) Load

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

Load returns the value associated with the key, and a boolean indicating if the key was found.

func (*Map[K, V]) Pairs

func (m *Map[K, V]) Pairs() []Pair[K, V]

Pairs returns a slice of all key-value pairs in the map in order.

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(yield func(key K, value V) bool)

Range calls the given function for each key-value pair in the map in order.

func (*Map[K, V]) Store

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

Store adds or updates a key-value pair in the map.

func (*Map[K, V]) Value

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

Value returns the value associated with the key, or the zero value if the key is not found.

func (*Map[K, V]) Values

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

Values returns a slice of all values in the map in order.

type Pair

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

Pair represents a key-value pair in the ordered map.

Jump to

Keyboard shortcuts

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