sequencedmap

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package sequencedmap provides a map implementation that maintains the order of keys as they are added.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

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

Element is a key-value pair that is stored in a sequenced map.

func NewElem

func NewElem[K comparable, V any](key K, value V) *Element[K, V]

NewElem creates a new element with the specified key and value.

type Map

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

Map is a map implementation that maintains the order of keys as they are added.

func New

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

New creates a new map with the specified elements.

func NewWithCapacity

func NewWithCapacity[K comparable, V any](capacity int, elements ...*Element[K, V]) *Map[K, V]

NewWithCapacity creates a new map with the specified capacity and elements.

func (*Map[K, V]) All

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

All returns an iterator that iterates over all elements in the map, in the order they were added.

func (*Map[K, V]) AllUntyped

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

AllUntyped returns an iterator that iterates over all elements in the map with untyped key and value. This allows for using the map in generic code.

func (*Map[K, V]) Delete

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

Delete removes the element with the specified key from the map.

func (*Map[K, V]) Get

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

Get returns the value for the specified key and a boolean indicating whether the key was found.

func (*Map[K, V]) GetKeyType

func (m *Map[K, V]) GetKeyType() reflect.Type

GetKeyType returns the type of the keys in the map.

func (*Map[K, V]) GetOrZero

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

GetOrZero returns the value for the specified key or the zero value if the key is not found.

func (*Map[K, V]) GetUntyped

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

GetUntyped returns the untyped value for the specified key with untyped key and a boolean indicating whether the key was found. This allows for using the map in generic code. If they key is not of the correct type, the zero value is returned.

func (*Map[K, V]) GetValueType

func (m *Map[K, V]) GetValueType() reflect.Type

GetValueType returns the type of the values in the map.

func (*Map[K, V]) Has

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

Has returns a boolean indicating whether the map contains the specified key.

func (*Map[K, V]) Init

func (m *Map[K, V]) Init()

Init initializes the underlying resources of the map.

func (*Map[K, V]) Keys

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

Keys returns an iterator that iterates over all keys in the map, in the order they were added.

func (*Map[K, V]) Len

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

Len returns the number of elements in the map. nil safe.

func (*Map[K, V]) MarshalJSON

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

MarshalJSON returns the JSON representation of the map.

func (*Map[K, V]) NavigateWithKey

func (m *Map[K, V]) NavigateWithKey(key string) (any, error)

NavigateWithKey returns the value for the specified key with the key as a string. This is an implementation of the jsonpointer.KeyNavigable interface.

func (*Map[K, V]) Set

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

Set sets the value for the specified key.

func (*Map[K, V]) SetUntyped

func (m *Map[K, V]) SetUntyped(key, value any) error

SetUntyped sets the value for the specified key with untyped key and value. This allows for using the map in generic code. An error is returned if the key or value is not of the correct type.

func (*Map[K, V]) SyncChangesWithSyncFunc

func (m *Map[K, V]) SyncChangesWithSyncFunc(ctx context.Context, model any, valueNode *yaml.Node, syncFunc func(context.Context, any, any, *yaml.Node) (*yaml.Node, error)) (*yaml.Node, error)

func (*Map[K, V]) Values

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

Values returns an iterator that iterates over all values in the map, in the order they were added.

Jump to

Keyboard shortcuts

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