xcontainer

package module
v0.0.0-...-978f43b Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: MIT Imports: 2 Imported by: 0

README

xcontainer

xcontainer is a collection of various container type implementations in Go, such as a double-linked circular list and an ordered map.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

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

List is a doubly-linked circular list. Any element in the list is a reference to the whole list. A zero-value List is not valid, but a nil *List is and is the correct representation of an empty list.

func NewList

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

NewList returns a List containing the provided values.

func NewListFromSeq

func NewListFromSeq[T any](seq iter.Seq[T]) (list *List[T])

NewListFromSeq returns a List containing the values yielded by seq.

func (*List[T]) All

func (list *List[T]) All() iter.Seq[*List[T]]

All returns an iter.Seq that yields the nodes of the List in next order, starting with list itself, once each.

For most situations, [Values] is more convenient.

func (*List[T]) Backward

func (list *List[T]) Backward() iter.Seq[*List[T]]

Backward returns an iter.Seq that yields the nodes of the List in prev order, starting with list itself, once each.

For most situations, [ValuesBackward] is more convenient.

func (*List[T]) InsertAfter

func (list *List[T]) InsertAfter(v T) *List[T]

InsertAfter inserts v as a new node in between list and the node after it. It returns list, possibly modified. Similar to [append], the existing list should always be replaced with the result of this function.

func (*List[T]) InsertBefore

func (list *List[T]) InsertBefore(v T) *List[T]

InsertBefore inserts v as a new node in between list and the node before it. It returns list, possibly modified. Similar to [append], the existing list should always be replaced with the result of this function.

func (*List[T]) InsertSeqAfter

func (list *List[T]) InsertSeqAfter(seq iter.Seq[T]) *List[T]

InsertSeqAfter inserts the values yielded by seq as new nodes after list. The order of the elements in the List will be the same as they were in seq. The behavior of this function is otherwise the same as that of [InsertBefore].

func (*List[T]) InsertSeqBefore

func (list *List[T]) InsertSeqBefore(seq iter.Seq[T]) *List[T]

InsertSeqBefore inserts the values yielded by seq as new nodes before list. The order of the elements in the List will be the same as they were in seq. The behavior of this function is otherwise the same as that of [InsertBefore].

func (*List[T]) Next

func (list *List[T]) Next() *List[T]

Next returns the node after list.

func (*List[T]) Prev

func (list *List[T]) Prev() *List[T]

Prev returns the node before list.

func (*List[T]) Remove

func (list *List[T]) Remove() *List[T]

Remove removes list from the List that it represents. It returns the node before list. list is no longer valid after a call to Remove.

func (*List[T]) Values

func (list *List[T]) Values() iter.Seq[T]

Values returns an iter.Seq that yields the values of each node in the List in next order, starting with that of list itself, once each.

func (*List[T]) ValuesBackward

func (list *List[T]) ValuesBackward() iter.Seq[T]

ValuesBackward returns an iter.Seq that yields the values of each node in the List in prev order, starting with that of list itself, once each.

type OrderedMap

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

OrderedMap is similar to Go's built-in map type, but maintains insertion order for iteration. In other words, if element b is inserted after element a is already in the map, b will always be yieled after a during iteration.

Unlike a built-in Go map, a zero-value OrderedMap is empty and ready to use.

func (*OrderedMap[K, V]) All

func (m *OrderedMap[K, V]) All() iter.Seq2[K, V]

All returns an iter.Seq that yields key value pairs in insertion order.

func (*OrderedMap[K, V]) Clear

func (m *OrderedMap[K, V]) Clear()

Clear deletes everything from m, resulting in an empty map.

func (*OrderedMap[K, V]) Delete

func (m *OrderedMap[K, V]) Delete(key K)

Delete removes the value associated with key from the map. If no such value exists, it does nothing.

func (*OrderedMap[K, V]) Keys

func (m *OrderedMap[K, V]) Keys() iter.Seq[K]

Keys returns an iter.Seq that yields keys in insertion order.

func (*OrderedMap[K, V]) Lookup

func (m *OrderedMap[K, V]) Lookup(key K) (val V, ok bool)

Lookup returns the value associated with the key and a boolean indicating if there was one or not.

func (*OrderedMap[K, V]) Set

func (m *OrderedMap[K, V]) Set(key K, val V)

Set sets the provided key to val in m.

func (*OrderedMap[K, V]) Values

func (m *OrderedMap[K, V]) Values() iter.Seq[V]

Values returns an iter.Seq that yields values in insertion order.

Jump to

Keyboard shortcuts

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