orderedmap

package module
v0.3.0 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 IIterator added in v0.3.0

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

IIterator is an iterator over a IOrderedMap.

type IOrderedMap added in v0.3.0

type IOrderedMap[T any] interface {
	Len() int
	Set(key any, val T)
	Get(key any) (T, bool)
	Delete(key any) (T, bool)
	Index(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() IIterator[T]
}

IOrderedMap is a map with ordered keys.

func New

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

New creates a new IOrderedMap

type Iterator

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

Iterator is an IIterator implementation.

func (*Iterator[T]) GetCurrent

func (i *Iterator[T]) GetCurrent() T

GetCurrent returns the current element in the Iterator. Prefer use with HasNext() or with Next() to avoid false positives. Alternatively, use GetCurrentV(), which is more verbose.

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

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

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

func (*Iterator[T]) GetNext

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

GetNext returns the next element in the Iterator.

func (*Iterator[T]) HasNext

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

HasNext returns true if the Iterator has a next element.

func (*Iterator[T]) Next

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

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

type OrderedMap

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

OrderedMap is the IOrderedMap implementation.

func (*OrderedMap[T]) Delete

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

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

func (*OrderedMap[T]) Get

func (m *OrderedMap[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 (*OrderedMap[T]) Index

func (m *OrderedMap[T]) Index(key any) int

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

func (*OrderedMap[T]) Iterator added in v0.2.0

func (m *OrderedMap[T]) Iterator() IIterator[T]

IIterator returns an Iterator for the map.

func (*OrderedMap[T]) Len

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

Len returns the number of elements in the map.

func (*OrderedMap[T]) ReplaceKey

func (m *OrderedMap[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 (*OrderedMap[T]) Set

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

Set sets the value for the given key.

func (*OrderedMap[T]) SetAfter

func (m *OrderedMap[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 (*OrderedMap[T]) SetBefore

func (m *OrderedMap[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.

Jump to

Keyboard shortcuts

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