orderedmap

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package orderedmap provides an implementation of ordered map structure in Go. In this map, keys are maintained in an order.

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyNotFound = errors.New("orderedmap: key not found")

ErrKeyNotFound means the key couldn't be found in the map.

Functions

This section is empty.

Types

type OrderedMap

type OrderedMap[K cmp.Ordered, V any] struct {
	// contains filtered or unexported fields
}

OrderedMap is an implementation of ordered map. It should be initialized with New function.

func New

func New[K cmp.Ordered, V any]() *OrderedMap[K, V]

New creates a new ordered map.

func (*OrderedMap[K, V]) Back

func (om *OrderedMap[K, V]) Back() (K, V)

Back returns the pair of key and value at the back of the list.

func (*OrderedMap[K, V]) Delete

func (om *OrderedMap[K, V]) Delete(key K) (val V, present bool)

Delete deletes a key. It returns the deleted value.

func (*OrderedMap[K, V]) Front

func (om *OrderedMap[K, V]) Front() (K, V)

Front returns the pair of key and value at the front of the list.

func (*OrderedMap[K, V]) Get

func (om *OrderedMap[K, V]) Get(key K) (value V, found bool)

Get returns the value for the provided key and whether the key presents in the map or not.

func (*OrderedMap[K, V]) Len

func (om *OrderedMap[K, V]) Len() int

Len returns the size of the map.

func (*OrderedMap[K, V]) MoveAfter

func (om *OrderedMap[K, V]) MoveAfter(key, markedKey K) error

MoveAfter moves key to a new position after markedKey.

func (*OrderedMap[K, V]) MoveBefore

func (om *OrderedMap[K, V]) MoveBefore(key, markedKey K) error

MoveAfter moves key to a new position after markedKey.

func (*OrderedMap[K, V]) MoveToBack

func (om *OrderedMap[K, V]) MoveToBack(key K) error

MoveToBack moves key to the front of list.

func (*OrderedMap[K, V]) MoveToFront

func (om *OrderedMap[K, V]) MoveToFront(key K) error

MoveToFront moves key to the front of list.

func (*OrderedMap[K, V]) ReverseScan

func (om *OrderedMap[K, V]) ReverseScan(itor func(key K, val V) bool)

ReverseScan scans through the map in in the reverse of the stored order.

func (*OrderedMap[K, V]) Scan

func (om *OrderedMap[K, V]) Scan(itor func(key K, val V) bool)

Scan scans through the map in in the stored order.

func (*OrderedMap[K, V]) Set

func (om *OrderedMap[K, V]) Set(key K, value V) (oldVal V, replaced bool)

Set inserts a new key, value into the map or replaces it if the key presents in the map.

type Pair

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

Pair is a pair of key and value.

Jump to

Keyboard shortcuts

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