mapx

package
v1.92.4 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package mapx contains extra map types and functions.

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 is a map that maintains the order of its keys.

It is meant for maps that only grow or that are small; is it not optimized for deleting keys.

The zero value is ready to use.

Locking-wise, it has the same rules as a regular Go map: concurrent reads are safe, but not writes.

func (*OrderedMap[K, V]) All

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

All yields all the keys and values, in the order they were inserted.

func (*OrderedMap[K, V]) Contains

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

Contains reports whether the map contains the given key.

func (*OrderedMap[K, V]) Delete

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

Delete removes the key from the map.

The cost is O(n) in the number of keys in the map.

func (*OrderedMap[K, V]) Get

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

Get returns the value for the given key in the map. If the key does not exist, it returns the zero value for V.

func (*OrderedMap[K, V]) GetOk

func (m *OrderedMap[K, V]) GetOk(key K) (_ V, ok bool)

GetOk returns the value for the given key in the map and whether it was present in the map.

func (*OrderedMap[K, V]) Keys

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

Keys yields the map keys, in the order they were inserted.

func (*OrderedMap[K, V]) Set

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

Set sets the value for the given key in the map.

If the key already exists, it updates the value and keeps the order.

func (*OrderedMap[K, V]) Values

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

Values yields the map values, in the order they were inserted.

Jump to

Keyboard shortcuts

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