indexmap

package
v0.0.0-...-2bc3700 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package Map defines various functions useful for Map.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry[K HashEqualer, V any] struct {
	Key   K
	Value V
}

Entry represents an entry in an Map.

type HashEqualer

type HashEqualer interface {
	Hash(h hash.Hash)
	Equal(other any) bool
}

type Map

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

Map represents a map which preserves the insertion order of keys.

func FromEntries

func FromEntries[K HashEqualer, V any](entries []Entry[K, V]) *Map[K, V]

FromEntries creates an Map and inserts specified entries.

func New

func New[K HashEqualer, V any]() *Map[K, V]

New creates an Map.

func WithCapacity

func WithCapacity[K HashEqualer, V any](capacity uint) *Map[K, V]

WithCapacity creates an Map with the specified capacity.

func (*Map[K, V]) Clone

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

Clone returns the shallow copy of m.

func (*Map[K, V]) Delete

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

Delete deletes the value for the key in m. Delete returns the value for the key and true if the key is found, or zero value of V and false otherwise.

func (*Map[K, V]) EntryAt

func (m *Map[K, V]) EntryAt(i uint) (e Entry[K, V], ok bool)

EntryAt returns the entry at i in m. EntryAt returns the key, the value, and whether the i was in the range or not.

func (*Map[K, V]) Get

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

Get gets the value for the key in m. Get returns the value for the key and true if the key is found, or zero value of V and false otherwise.

func (*Map[K, V]) Keys

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

Keys returns keys in preserved order.

func (*Map[K, V]) Len

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

Len returns the size of m.

func (*Map[K, V]) Set

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

Set sets the value for the key in m. If m contains the key, the just value is updated without modifying the insertion order of the keys.

Jump to

Keyboard shortcuts

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