ordered

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package ordered provides an insertion-ordered map with live iteration. Wire-visible participant order, candidate ordering, round-robin state and deletion during iteration depend on those semantics.

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 keeps keys in first-insertion order. Set on an existing key keeps its position; MoveToBack removes and reinserts it at the end. Iteration is live: an entry deleted before it is visited is skipped and an entry appended during iteration is visited. The zero value is ready to use.

func (*Map[K, V]) All

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

All iterates live entries in order with JavaScript Map semantics. Mutating the map inside the loop is allowed.

func (*Map[K, V]) Clear

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

Clear removes every entry. Dropping the index before compacting is safe because every entry is now a tombstone, so compact writes no index entry.

func (*Map[K, V]) Delete

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

Delete removes key and reports whether it was present.

func (*Map[K, V]) Get

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

Get returns the value for key and whether it is present.

func (*Map[K, V]) Has

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

Has reports whether key is present.

func (*Map[K, V]) Keys

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

Keys returns a snapshot of the live keys in order.

func (*Map[K, V]) Len

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

Len reports the number of live entries.

func (*Map[K, V]) MoveToBack

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

MoveToBack re-inserts key at the end, as JavaScript `map.delete(k); map.set(k, v)` does. It is a plain Set when the key is absent.

func (*Map[K, V]) Set

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

Set stores value under key, keeping the existing position when the key is already present and appending otherwise.

func (*Map[K, V]) Values

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

Values returns a snapshot of the live values in order.

Jump to

Keyboard shortcuts

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