ordered

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

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 represents an ordered map of key-value pairs. Use the All method to iterate over pairs in the order they were added. The zero value of Map is ready to use. Methods on Map are not safe for concurrent use and must be protected by a synchronization mechanism.

func (*Map[K, V]) All

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

All returns a sequence that iterates over all items in m. It is safe to add or delete items from the map while iterating. New items added to the map will be yielded, deleted items will not.

func (*Map[K, V]) DecodeField

func (m *Map[K, V]) DecodeField(dec codec.Decoder, k K) error

DecodeField implements the codec.FieldDecoder interface (if K == string).

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(k K) (deleted bool)

Delete deletes key k from the map. It returns true if k was present in the map and deleted.

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(k K) (v V)

Get returns a value of type V if it exists in the map, otherwise the zero value.

func (*Map[K, V]) GetOK

func (m *Map[K, V]) GetOK(k K) (v V, ok bool)

GetOK returns a value of type V if it exists in the map, otherwise the zero value, and a boolean value that expresses whether k is present in the map.

func (*Map[K, V]) Len

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

Len returns the number of elements in m.

func (*Map[K, V]) Set

func (m *Map[K, V]) Set(k K, v V) (replaced bool)

Set sets the value of k to v. If k is not present, the value is appended to the end. If k is already present in the map, its value is replaced. To guarantee the value is appended to the end, call Delete before calling Set. It returns true if k was present in the map and its value was replaced.

Jump to

Keyboard shortcuts

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