orderedmap

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package orderedmap implements a generic ordered map that supports iteration in insertion order.

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 {
	// Pairs is the list of pairs in insertion order. It should _never_ be modified directly (use
	// Store instead), but can be used for read-only purposes (e.g., iterations). It is
	// specifically exported to allow serialization via gob encoding.
	Pairs []*Pair[K, V]
	// contains filtered or unexported fields
}

OrderedMap is an ordered map that supports iteration in insertion order. It is an _internal_ helper struct for NilAway and lacks some of the features of a full map.

func New

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

New creates a new OrderedMap.

func (*OrderedMap[K, V]) Load

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

Load returns the value stored in the map for the key, with an additional bool indicating if the key was found.

func (*OrderedMap[K, V]) Store

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

Store stores the value in the map for the key, overwriting the previous value if the key exists.

func (*OrderedMap[K, V]) Value

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

Value returns the value stored in the map for the key, or the zero value if the key is not found. It is the same as Load, but without the additional bool.

type Pair

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

Pair is a key-value pair stored in the ordered map.

Jump to

Keyboard shortcuts

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