linkmap

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

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

Iterator is a struct for iterating over the map.

func (*Iterator[K, V]) Get

func (it *Iterator[K, V]) Get() misc.Pair[K, V]

Get returns the current entry as a Pair.

func (*Iterator[K, V]) Key

func (it *Iterator[K, V]) Key() K

Key returns the current key.

func (*Iterator[K, V]) Move

func (it *Iterator[K, V]) Move()

Move moves the iterator to the next element.

func (*Iterator[K, V]) Node

func (it *Iterator[K, V]) Node() *Node[K, V]

Node returns the current node.

func (*Iterator[K, V]) Remove

func (it *Iterator[K, V]) Remove()

Remove removes the current entry from the map. The iterator will be moved to the next element.

func (*Iterator[K, V]) SetValue

func (it *Iterator[K, V]) SetValue(value V)

SetValue sets the value of the current entry.

func (*Iterator[K, V]) Valid

func (it *Iterator[K, V]) Valid() bool

Valid returns true if the iterator points to a valid element.

func (*Iterator[K, V]) Value

func (it *Iterator[K, V]) Value() V

Value returns the value of the current entry.

func (*Iterator[K, V]) ValueRef

func (it *Iterator[K, V]) ValueRef() *V

ValueRef returns a reference to the value of the current entry.

type Node

type Node[K, V any] struct {
	Value V // The Value of the entry stored in the node.
	// contains filtered or unexported fields
}

Node is a entry in the map. It is used to keep track of the order of the elements. It should not be created directly.

func (*Node[K, V]) Clone

func (node *Node[K, V]) Clone() *Node[K, V]

Clone returns a copy of the node. The clone has the same key and value as the node. The clone does not have any links to other nodes.

func (*Node[K, V]) Key

func (node *Node[K, V]) Key() K

Key returns the key of the entry stored in the node.

func (*Node[K, V]) Next

func (node *Node[K, V]) Next() *Node[K, V]

Next returns the next node in the map.

func (*Node[K, V]) Prev

func (node *Node[K, V]) Prev() *Node[K, V]

Prev returns the previous node in the map.

type Order

type Order bool

Order represents the order of the nodes in the map.

const (
	FIFO Order = false // FIFO represents the first-in-first-out order.
	LRU        = true  // LRU represents the least-recently-used order.
)

type Wrapper

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

Wrapper is a map that keeps track of the order of the nodes.

func From

func From[K, V any](m maps.Map[K, *Node[K, V]], capacity int, order Order) *Wrapper[K, V]

From returns a new Wrapper that wraps the given map.

func NewHashmap

func NewHashmap[K comparable, V any](capacity int, order Order) *Wrapper[K, V]

NewHashmap returns a new Wrapper around a empty hashmap.

func (*Wrapper[K, V]) Clear

func (w *Wrapper[K, V]) Clear()

Clear removes all entries from the map.

func (*Wrapper[K, V]) Clone

func (w *Wrapper[K, V]) Clone() maps.Map[K, V]

Clone returns a copy of the wrapper and of the underlying map.

func (*Wrapper[K, V]) Contains

func (w *Wrapper[K, V]) Contains(key K) bool

Contains returns true if the map contains the given key.

func (*Wrapper[K, V]) Get

func (w *Wrapper[K, V]) Get(key K) V

Get returns the value associated with the given key. Panics if the key is not in the map. If the order is LRU, the entry is moved to the front.

func (*Wrapper[K, V]) GetRef

func (w *Wrapper[K, V]) GetRef(key K) *V

GetRef returns a reference to the value associated with the given key. Panics if the key is not in the map. If the order is LRU, the entry is moved to the front.

func (*Wrapper[K, V]) Iterator

func (w *Wrapper[K, V]) Iterator() iter.Iterator[misc.Pair[K, V]]

Iterator returns an iter.Iterator over the entries in the map.

func (*Wrapper[K, V]) MapIterator

func (w *Wrapper[K, V]) MapIterator() maps.Iterator[K, V]

MapIterator returns a iterator over the entries in the map.

func (*Wrapper[K, V]) RefsStream2 added in v1.7.0

func (w *Wrapper[K, V]) RefsStream2(yield func(K, *V) bool)

RefsStream2 streams keys and references to values of the Map

func (*Wrapper[K, V]) Remove

func (w *Wrapper[K, V]) Remove(key K)

Remove removes the entry with the given key. If the key is not in the map, nothing happens.

func (*Wrapper[K, V]) Set

func (w *Wrapper[K, V]) Set(key K, value V)

Set sets the value associated with the given key. Entry is moved to the front of the map. If the map is full, the last entry is removed.

func (*Wrapper[K, V]) Size

func (w *Wrapper[K, V]) Size() int

Size returns the number of entries in the map.

func (*Wrapper[K, V]) Stream2 added in v1.7.0

func (w *Wrapper[K, V]) Stream2(yield func(K, V) bool)

Stream2 streams over the entries in the Map.

func (*Wrapper[K, V]) TryGet

func (w *Wrapper[K, V]) TryGet(key K) (V, bool)

TryGet returns the value associated with the given key. If the key is not in the map, the zero value and false is returned. If the order is LRU, the entry is moved to the front.

Jump to

Keyboard shortcuts

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