orderedmap

package module
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2022 License: GPL-3.0 Imports: 0 Imported by: 1

README

Ordered Map

Ordered Map

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator[T any] interface {
	HasNext() bool
	Next() bool
	GetNext() (T, bool)
	GetCurrent() (T, bool)
	GetCurrentV() (T, int, bool)
}

Iterator is an iterator over a OrderedMap.

func NewIterator added in v0.2.2

func NewIterator[T any](values []T) Iterator[T]

type OMIterator added in v0.2.0

type OMIterator[T any] struct {
	// contains filtered or unexported fields
}

OMIterator is an Iterator implementation.

func (*OMIterator[T]) GetCurrent added in v0.2.0

func (i *OMIterator[T]) GetCurrent() (T, bool)

GetCurrent returns the current element and true if there was a current element in the OMIterator.

func (*OMIterator[T]) GetCurrentV added in v0.2.1

func (i *OMIterator[T]) GetCurrentV() (T, int, bool)

GetCurrentV returns the current element, the index and true if there was a current element in the OMIterator.

func (*OMIterator[T]) GetNext added in v0.2.0

func (i *OMIterator[T]) GetNext() (T, bool)

GetNext returns the next element in the OMIterator.

func (*OMIterator[T]) HasNext added in v0.2.0

func (i *OMIterator[T]) HasNext() bool

HasNext returns true if the OMIterator has a next element.

func (*OMIterator[T]) Next added in v0.2.0

func (i *OMIterator[T]) Next() bool

Next moves the OMIterator to the next element and returns true if there was a next element in the OMIterator.

type OMap added in v0.2.1

type OMap[T any] struct {
	// contains filtered or unexported fields
}

OMap is the OrderedMap implementation.

func (*OMap[T]) Delete added in v0.2.1

func (m *OMap[T]) Delete(key any) (T, bool)

Delete deletes the value for the given key. Returns deleted value, true if the key is found.

func (*OMap[T]) Exists added in v0.2.1

func (m *OMap[T]) Exists(key any) bool

Exists returns true if the key exists in the map.

func (*OMap[T]) Get added in v0.2.1

func (m *OMap[T]) Get(key any) (T, bool)

Get returns the value for the given key. If the key does not exist, the second argument will be false.

func (*OMap[T]) IndexOf added in v0.2.4

func (m *OMap[T]) IndexOf(key any) int

IndexOf returns the index of the given key. If the key does not exist, returns -1.

func (*OMap[T]) Iterator added in v0.2.1

func (m *OMap[T]) Iterator() Iterator[T]

Iterator returns an OMIterator for the map.

func (*OMap[T]) Keys added in v0.2.1

func (m *OMap[T]) Keys() []any

Keys returns the keys of the map.

func (*OMap[T]) Len added in v0.2.1

func (m *OMap[T]) Len() int

Len returns the number of elements in the map.

func (*OMap[T]) ReplaceKey added in v0.2.1

func (m *OMap[T]) ReplaceKey(oldKey any, newKey any) bool

ReplaceKey replaces the key of the given key with the new key. Returns false if the key does not exist.

func (*OMap[T]) Set added in v0.2.1

func (m *OMap[T]) Set(key any, val T)

Set sets the value for the given key.

func (*OMap[T]) SetAfter added in v0.2.1

func (m *OMap[T]) SetAfter(presentKey any, newKey any, value T) (int, bool)

SetAfter sets the new (newKey, value) pair after the given presentKey. Return false if presentKey does not exist or if newKey already exists.

func (*OMap[T]) SetBefore added in v0.2.1

func (m *OMap[T]) SetBefore(presentKey any, newKey any, value T) (int, bool)

SetBefore sets the new (newKey, value) pair before the given presentKey. Return false if presentKey does not exist or if newKey already exists.

func (*OMap[T]) Values added in v0.2.1

func (m *OMap[T]) Values() []T

Values returns the values of the map.

type OrderedMap

type OrderedMap[T any] interface {
	Len() int
	Set(key any, val T)
	Get(key any) (T, bool)
	Delete(key any) (T, bool)
	Keys() []any
	Values() []T
	Exists(key any) bool
	IndexOf(key any) int
	ReplaceKey(oldKey any, newKey any) bool
	SetBefore(presentKey any, newKey any, val T) (int, bool)
	SetAfter(presentKey any, newKey any, val T) (int, bool)
	Iterator() Iterator[T]
}

OrderedMap is a map with ordered keys.

func New

func New[T any]() OrderedMap[T]

New creates a new OrderedMap

Jump to

Keyboard shortcuts

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