orderedmap

package
v0.0.0-...-32c7374 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

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] interface {
	// Len returns the number of items in the map.
	Len() int

	// Get returns a value by a key, or false.
	Get(key K) (V, bool)

	// GetAt returns an item at a given index.
	GetAt(index int) (K, V)

	// Contains returns true if a key exists.
	Contains(key K) bool

	// IndexOf returns the index of a key, or -1.
	// The method takes O(n) time in the worst case.
	IndexOf(key K) int

	// Keys returns a slice of keys in the order they were inserted.
	Keys() []K

	// Values returns a slice of values in the order they were inserted.
	Values() []V

	// Clear deletes all items.
	Clear()

	// Clone returns a copy of the map.
	Clone() OrderedMap[K, V]

	// Delete deletes an item, and returns its value.
	// The method takes O(n) time in the worst case.
	Delete(key K) (V, bool)

	// Set sets an item.
	Set(key K, value V)
}

OrderedMap is a map that maintains the insertion order of items.

func New

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

New returns a new ordered map.

func NewCap

func NewCap[K comparable, V any](cap int) OrderedMap[K, V]

NewCap returns a new ordered map with a given capacity.

Jump to

Keyboard shortcuts

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