orderedmap

package
v2.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry[K comparable, V any] struct {
	Key   K
	Value V
}

type Map

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

Map is a generic data structure that maintains the order of keys.

func New

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

New creates a new Map.

func NewWithCapacity

func NewWithCapacity[K comparable, V any](cap int) *Map[K, V]

NewWithCapacity creates a new Map with pre-allocated capacity for both the internal map and keys slice. Use this when the approximate number of entries is known in advance to avoid repeated allocations.

func (*Map[K, V]) Delete

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

Delete removes a key-value pair from the Map.

func (*Map[K, V]) Each

func (om *Map[K, V]) Each(cb func(key K, value V))

func (*Map[K, V]) Entries

func (om *Map[K, V]) Entries() []Entry[K, V]

Entries returns the key-value pairs in the order they were added.

func (*Map[K, V]) Get

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

Get retrieves a value by key.

func (*Map[K, V]) Keys

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

Keys returns the keys in the order they were added.

func (*Map[K, V]) Set

func (om *Map[K, V]) Set(key K, value V)

Set adds or updates a key-value pair in the Map.

func (*Map[K, V]) Values

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

Values returns the values in the order of their keys.

Jump to

Keyboard shortcuts

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