omap

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: BSD-2-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package omap provides a generic ordered map implementation that maintains insertion order of keys.

OrderedMap is parameterized as OrderedMap[K comparable, V any] and is used internally by the configuration tree to preserve the order of configuration keys.

Key Features

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OrderedMap

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

OrderedMap maintains key-value pairs with insertion order preservation.

func New

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

New creates an empty OrderedMap.

func NewWithCapacity

func NewWithCapacity[K comparable, V any](capacity int) *OrderedMap[K, V]

NewWithCapacity creates an empty OrderedMap with preallocated capacity.

func (*OrderedMap[K, V]) Clear

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

Clear removes all key-value pairs from the map.

func (*OrderedMap[K, V]) Delete

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

Delete removes the key-value pair from the map. It returns true if the key was present and removed.

func (*OrderedMap[K, V]) Get

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

Get returns the value associated with the key, and a boolean indicating whether the key exists.

func (*OrderedMap[K, V]) Has

func (m *OrderedMap[K, V]) Has(key K) bool

Has returns true if the key exists in the map.

func (*OrderedMap[K, V]) Items

func (m *OrderedMap[K, V]) Items() iter.Seq2[K, V]

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

func (*OrderedMap[K, V]) Keys

func (m *OrderedMap[K, V]) Keys() iter.Seq[K]

Keys returns an iterator over keys in insertion order.

func (*OrderedMap[K, V]) Len

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

Len returns the number of key-value pairs in the map.

func (*OrderedMap[K, V]) Set

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

Set sets the value for the given key. If the key is new, it is appended to the end of the order. If the key already exists, its value is updated and the order remains unchanged.

func (*OrderedMap[K, V]) Values

func (m *OrderedMap[K, V]) Values() iter.Seq[V]

Values returns an iterator over values in insertion order.

Jump to

Keyboard shortcuts

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