orderedmapx

package
v0.0.0-...-3511abf Latest Latest
Warning

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

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

Documentation

Overview

Package orderedmapx is a thread safe and ordered implementation of a standard map. The elements can be retrieved in the same order in which they were added. orderedmapx allows elements to be located without having to sequentially search the list to find the element we're looking for.

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 is a thread safe and ordered implementation of standard map. K is the type of key and V is the type of value.

func New

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

New returns an initialized Map[K, V].

func (*Map[K, V]) Delete

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

Delete deletes the entry for the specified key from the map. Returns true if the key existed in the map and was deleted; false otherwise.

func (*Map[K, V]) Get

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

Get returns the value for the specified key if the key exists in the map. The second return value is a boolean, which will be set to true if the key was found in the map, or false if the key was not found in the map.

func (*Map[K, V]) GetAndDelete

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

GetAndDelete removes the first (i.e., oldest) element from the list and returns it. If the list is empty, the call will block until a new element is added. The second return value will be set to true if the list was not empty; otherwise it will be set to false if the list is empty.

func (*Map[k, V]) Length

func (m *Map[k, V]) Length() int

Length will return the length of Map.

func (*Map[K, V]) Put

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

Put adds a key to the map with the specified value. If the key already exists, then the existing key's value is replaced with the new value.

func (*Map[K, V]) PutIfAbsent

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

PutIfAbsent returns the existing value if the key already exists in the map and sets the second return value to false to indicate that the value was not updated because the key already existed in the map. Otherwise, if the key did not already exist in the map, it returns the new value and sets the second return value to true to indicate that the key and its value were added to the map.

Jump to

Keyboard shortcuts

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