orderedmap

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package orderedmap provides a generic ordered map that maintains insertion order. It wraps github.com/wk8/go-ordered-map/v2 to encapsulate the dependency.

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 generic ordered map that maintains insertion order.

func New

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

New creates a new empty ordered map.

func (*Map[K, V]) All

func (m *Map[K, V]) All() iter.Seq2[K, V]

All returns an iterator over all key-value pairs in insertion order.

func (*Map[K, V]) Get

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

Get retrieves a value by key.

func (*Map[K, V]) Len

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

Len returns the number of entries.

func (*Map[K, V]) MarshalJSON

func (m *Map[K, V]) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. The JSON output preserves key order.

func (*Map[K, V]) Set

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

Set sets a key-value pair. If the key already exists, its value is updated but its position in the iteration order is preserved. If the key is new, it is appended to the end.

func (*Map[K, V]) ToMap

func (m *Map[K, V]) ToMap() map[K]V

ToMap converts to a regular Go map. Note: The resulting map does not preserve order.

func (*Map[K, V]) UnmarshalJSON

func (m *Map[K, V]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. The insertion order matches the order of keys in the JSON input.

Jump to

Keyboard shortcuts

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