indexedlist

package
v0.4.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IndexedList

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

IndexedList is a doubly-linked list with a map index. Appending, prepending, and removing arbitrary elements is performed in constant time and thread-safe.

func New

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

New returns a new empty IndexedList with K as the index type and V as the value type.

func (*IndexedList[K, V]) Append

func (il *IndexedList[K, V]) Append(keys []K, vals []V) ([]K, []V)

Append adds multiple key-value pairs to the end of the list, in the given order. Append skips a key-value pair if an item is already stored under the same key anywhere in the list. Returns lists of actually appended keys and values. If the two arguments have different lengths, Append panics.

func (*IndexedList[K, V]) GarbageCollect

func (il *IndexedList[K, V]) GarbageCollect(retIdx tt.RetentionIndex)

func (*IndexedList[K, V]) Iterator

func (il *IndexedList[K, V]) Iterator(retIdx tt.RetentionIndex) *Iterator[K, V]

Iterator creates a new iterator for the list, initialized to the list's start. The list can be modified concurrently with being iterated over.

func (*IndexedList[K, V]) Len

func (il *IndexedList[K, V]) Len() int

Len returns the number of items stored in the list.

func (*IndexedList[K, V]) LookUp

func (il *IndexedList[K, V]) LookUp(keys []K) ([]K, []V, []K)

LookUp takes a slice of keys and returns 3 slices containing, respectively, 1. Those among the given keys that have been found in the list 2. The corresponding values 3. Those among the given keys that have not been found in the list The order of elements in the returned slices respects the order of the given keys.

func (*IndexedList[K, V]) Remove

func (il *IndexedList[K, V]) Remove(keys []K) ([]K, []V)

Remove removes list entries with the given keys, if they are in the list. Returns the keys and values actually removed.

func (*IndexedList[K, V]) RemoveSelected

func (il *IndexedList[K, V]) RemoveSelected(predicate func(K, V) bool) ([]K, []V)

RemoveSelected removes all items satisfying the given predicate from the list. Returns the removed items as two slices of equal lengths, for keys and values respectively. The returned values preserve the order of the removed elements in the list.

type Iterator

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

func (*Iterator[K, V]) Next

func (i *Iterator[K, V]) Next() (K, V, bool)

func (*Iterator[K, V]) NextWhile

func (i *Iterator[K, V]) NextWhile(predicate func(K, V) bool) ([]K, []V, bool)

Jump to

Keyboard shortcuts

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