linked

package
v1.11.9 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InsertAfter

func InsertAfter[T any](l *List[T], v T, location *ListElement[T])

InsertAfter inserts v into a new element immediately after location. If location is not in l, l is not modified.

func InsertBefore

func InsertBefore[T any](l *List[T], v T, location *ListElement[T])

InsertBefore inserts v into a new element immediately before location. If location is not in l, l is not modified.

func PushBack

func PushBack[T any](l *List[T], v T)

PushBack inserts v into a new element at the back of l.

func PushFront

func PushFront[T any](l *List[T], v T)

PushFront inserts v into a new element at the front of l.

Types

type Hashmap

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

Hashmap provides an ordered O(1) mapping from keys to values.

Entries are tracked by insertion order.

func NewHashmap

func NewHashmap[K comparable, V any]() *Hashmap[K, V]

func NewHashmapWithSize

func NewHashmapWithSize[K comparable, V any](initialSize int) *Hashmap[K, V]

func (*Hashmap[K, V]) Clear

func (lh *Hashmap[K, V]) Clear()

func (*Hashmap[K, V]) Delete

func (lh *Hashmap[K, V]) Delete(key K) bool

func (*Hashmap[K, V]) Get

func (lh *Hashmap[K, V]) Get(key K) (V, bool)

func (*Hashmap[K, V]) Len

func (lh *Hashmap[K, V]) Len() int

func (*Hashmap[K, V]) NewIterator

func (lh *Hashmap[K, V]) NewIterator() *Iterator[K, V]

func (*Hashmap[K, V]) Newest

func (lh *Hashmap[K, V]) Newest() (K, V, bool)

func (*Hashmap[K, V]) Oldest

func (lh *Hashmap[K, V]) Oldest() (K, V, bool)

func (*Hashmap[K, V]) Put

func (lh *Hashmap[K, V]) Put(key K, value V)

type Iterator

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

Iterates over the keys and values in a LinkedHashmap from oldest to newest. Assumes the underlying LinkedHashmap is not modified while the iterator is in use, except to delete elements that have already been iterated over.

func (*Iterator[K, V]) Key

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

func (*Iterator[K, V]) Next

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

func (*Iterator[K, V]) Value

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

type List

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

List implements a doubly linked list with a sentinel node.

See: https://en.wikipedia.org/wiki/Doubly_linked_list

This datastructure is designed to be an almost complete drop-in replacement for the standard library's "container/list".

The primary design change is to remove all memory allocations from the list definition. This allows these lists to be used in performance critical paths. Additionally the zero value is not useful. Lists must be created with the NewList method.

func NewList

func NewList[T any]() *List[T]

NewList creates a new doubly linked list.

func (*List[T]) Back

func (l *List[T]) Back() *ListElement[T]

Back returns the element at the back of l. If l is empty, nil is returned.

func (*List[T]) Front

func (l *List[T]) Front() *ListElement[T]

Front returns the element at the front of l. If l is empty, nil is returned.

func (*List[T]) InsertAfter

func (l *List[T]) InsertAfter(e *ListElement[T], location *ListElement[T])

InsertAfter inserts e immediately after location. If e is already in a list, l is not modified. If location is not in l, l is not modified.

func (*List[T]) InsertBefore

func (l *List[T]) InsertBefore(e *ListElement[T], location *ListElement[T])

InsertBefore inserts e immediately before location. If e is already in a list, l is not modified. If location is not in l, l is not modified.

func (*List[_]) Len

func (l *List[_]) Len() int

Len returns the number of elements in l.

func (*List[T]) MoveAfter

func (l *List[T]) MoveAfter(e, location *ListElement[T])

MoveAfter moves e immediately after location. If the elements are equal or not in l, the list is not modified.

func (*List[T]) MoveBefore

func (l *List[T]) MoveBefore(e, location *ListElement[T])

MoveBefore moves e immediately before location. If the elements are equal or not in l, the list is not modified.

func (*List[T]) MoveToBack

func (l *List[T]) MoveToBack(e *ListElement[T])

MoveToBack moves e to the back of l. If e is not in l, l is not modified.

func (*List[T]) MoveToFront

func (l *List[T]) MoveToFront(e *ListElement[T])

MoveToFront moves e to the front of l. If e is not in l, l is not modified.

func (*List[T]) PushBack

func (l *List[T]) PushBack(e *ListElement[T])

PushBack inserts e at the back of l. If e is already in a list, l is not modified.

func (*List[T]) PushFront

func (l *List[T]) PushFront(e *ListElement[T])

PushFront inserts e at the front of l. If e is already in a list, l is not modified.

func (*List[T]) Remove

func (l *List[T]) Remove(e *ListElement[T])

Remove removes e from l if e is in l.

type ListElement

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

ListElement is an element of a linked list.

func (*ListElement[T]) Next

func (e *ListElement[T]) Next() *ListElement[T]

Next returns the next element or nil.

func (*ListElement[T]) Prev

func (e *ListElement[T]) Prev() *ListElement[T]

Prev returns the previous element or nil.

Jump to

Keyboard shortcuts

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