Documentation
¶
Overview ¶
Example ¶
// Create a new list and put some numbers in it. l := NewDoubly[int]() e4 := l.PushBack(4) e1 := l.PushFront(1) l.InsertBefore(3, e4) l.InsertAfter(2, e1) // Iterate through list and print its contents. for e := l.Front(); e != nil; e = e.Next() { fmt.Println(e.Value) }
Output: 1 2 3 4
Index ¶
- type DList
- func (l *DList[T]) All() iter.Seq[T]
- func (l *DList[T]) Back() *DNode[T]
- func (l *DList[T]) Front() *DNode[T]
- func (l *DList[T]) Init() *DList[T]
- func (l *DList[T]) InsertAfter(v T, mark *DNode[T]) *DNode[T]
- func (l *DList[T]) InsertBefore(v T, mark *DNode[T]) *DNode[T]
- func (l *DList[T]) InsertNodeAfter(e, mark *DNode[T])
- func (l *DList[T]) InsertNodeBefore(e, mark *DNode[T])
- func (l *DList[T]) Len() int
- func (l *DList[T]) MoveAfter(e, mark *DNode[T])
- func (l *DList[T]) MoveBefore(e, mark *DNode[T])
- func (l *DList[T]) MoveToBack(e *DNode[T])
- func (l *DList[T]) MoveToFront(e *DNode[T])
- func (l *DList[T]) PushBack(v T) *DNode[T]
- func (l *DList[T]) PushBackDList(other *DList[T])
- func (l *DList[T]) PushBackNode(e *DNode[T])
- func (l *DList[T]) PushFront(v T) *DNode[T]
- func (l *DList[T]) PushFrontDList(other *DList[T])
- func (l *DList[T]) PushFrontNode(e *DNode[T])
- func (l *DList[T]) Remove(e *DNode[T]) T
- type DNode
- type SList
- func (l *SList[T]) All() iter.Seq[T]
- func (l *SList[T]) Back() *SNode[T]
- func (l *SList[T]) Front() *SNode[T]
- func (l *SList[T]) Get(i int) *SNode[T]
- func (l *SList[T]) InsertAt(i int, v T)
- func (l *SList[T]) InsertNodeAt(i int, e *SNode[T])
- func (l *SList[T]) Len() int
- func (l *SList[T]) PushBack(v T)
- func (l *SList[T]) PushBackNode(e *SNode[T])
- func (l *SList[T]) PushFront(v T)
- func (l *SList[T]) PushFrontNode(e *SNode[T])
- func (l *SList[T]) Remove(i int) *SNode[T]
- func (l *SList[T]) RemoveFront() *SNode[T]
- func (l *SList[T]) Swap(i, j int)
- type SNode
- type SkipList
- func (s *SkipList[K, V]) All() iter.Seq2[K, V]
- func (s *SkipList[K, V]) Clear()
- func (s *SkipList[K, V]) Get(key K) (V, bool)
- func (s *SkipList[K, V]) GetNode(key K) *SkipNode[K, V]
- func (s *SkipList[K, V]) Head() *SkipNode[K, V]
- func (s *SkipList[K, V]) Init()
- func (s *SkipList[K, V]) Keys() []K
- func (s *SkipList[K, V]) Len() int
- func (s *SkipList[K, V]) Range(f func(key K, val V) bool)
- func (s *SkipList[K, V]) RangeWithRange(start, end K, f func(key K, val V) bool)
- func (s *SkipList[K, V]) RangeWithStart(start K, f func(key K, val V) bool)
- func (s *SkipList[K, V]) Remove(key K) (V, bool)
- func (s *SkipList[K, V]) Set(key K, val V)
- func (s *SkipList[K, V]) SetNx(key K, val V) bool
- func (s *SkipList[K, V]) SetX(key K, val V) bool
- func (s *SkipList[K, V]) Values() []V
- type SkipListWithCmp
- func (s *SkipListWithCmp[K, V]) All() iter.Seq2[K, V]
- func (s *SkipListWithCmp[K, V]) Clear()
- func (s *SkipListWithCmp[K, V]) Get(key K) (V, bool)
- func (s *SkipListWithCmp[K, V]) GetNode(key K) *SkipNodeCmp[K, V]
- func (s *SkipListWithCmp[K, V]) Head() *SkipNodeCmp[K, V]
- func (s *SkipListWithCmp[K, V]) Init(keyCmp func(K, K) int)
- func (s *SkipListWithCmp[K, V]) Keys() []K
- func (s *SkipListWithCmp[K, V]) Len() int
- func (s *SkipListWithCmp[K, V]) Range(f func(K, V) bool)
- func (s *SkipListWithCmp[K, V]) RangeWithRange(start, end K, f func(K, V) bool)
- func (s *SkipListWithCmp[K, V]) RangeWithStart(start K, f func(K, V) bool)
- func (s *SkipListWithCmp[K, V]) Remove(key K) (V, bool)
- func (s *SkipListWithCmp[K, V]) Set(key K, val V)
- func (s *SkipListWithCmp[K, V]) SetNx(key K, val V) bool
- func (s *SkipListWithCmp[K, V]) SetX(key K, val V) bool
- func (s *SkipListWithCmp[K, V]) Values() []V
- type SkipNode
- type SkipNodeCmp
- type SyncList
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DList ¶
type DList[T any] struct { // contains filtered or unexported fields }
DList represents a doubly linked list. The zero value for DList is an empty list ready to use.
func (*DList[T]) All ¶
All returns an iterator that yields all element value in the doubly linked list.
func (*DList[T]) InsertAfter ¶
InsertAfter inserts a new node e with value v immediately after mark and returns e. If mark is not a node of l, the list is not modified. The mark must not be nil.
func (*DList[T]) InsertBefore ¶
InsertBefore inserts a new node e with value v immediately before mark and returns e. If mark is not a node of l, the list is not modified. The mark must not be nil.
func (*DList[T]) InsertNodeAfter ¶
InsertNodeAfter inserts a new elenodeent e after mark and returns e.
func (*DList[T]) InsertNodeBefore ¶
InsertNodeBefore inserts a new node e before mark and returns e.
func (*DList[T]) MoveAfter ¶
MoveAfter moves node e to its new position after mark. If e or mark is not a node of l, or e == mark, the list is not modified. The node and mark must not be nil.
func (*DList[T]) MoveBefore ¶
MoveBefore moves node e to its new position before mark. If e or mark is not a node of l, or e == mark, the list is not modified. The node and mark must not be nil.
func (*DList[T]) MoveToBack ¶
MoveToBack moves node e to the back of list l. If e is not an node of l, the list is not modified. The node must not be nil.
func (*DList[T]) MoveToFront ¶
MoveToFront moves node e to the front of list l. If e is not an node of l, the list is not modified. The node must not be nil.
func (*DList[T]) PushBack ¶
PushBack inserts a new node e with value v at the back of list l and returns e.
func (*DList[T]) PushBackDList ¶
PushBackDList inserts a copy of another list at the back of list l. The lists l and other may be the same. They must not be nil.
func (*DList[T]) PushBackNode ¶
PushBackNode inserts a new node e at the back of list l.
func (*DList[T]) PushFront ¶
PushFront inserts a new node e with value v at the front of list l and returns e.
func (*DList[T]) PushFrontDList ¶
PushFrontDList inserts a copy of another list at the front of list l. The lists l and other may be the same. They must not be nil.
func (*DList[T]) PushFrontNode ¶
PushFrontNode inserts a new node e at the front of list l.
type DNode ¶
type DNode[T any] struct { // The value stored with this node. Value T // contains filtered or unexported fields }
DNode is a node of a doubly linked list.
type SList ¶
type SList[T any] struct { // contains filtered or unexported fields }
SList represents a singly linked list.
func (*SList[T]) All ¶
All returns an iterator that yields all element value in the singly linked list.
func (*SList[T]) InsertAt ¶
InsertAt inserts a new node with value v at index i. The old node at index i will be pushed to the next index.
func (*SList[T]) InsertNodeAt ¶
InsertNodeAt inserts a new node at index i. The old node at index i will be pushed to the next index.
func (*SList[T]) PushBack ¶
func (l *SList[T]) PushBack(v T)
PushBack inserts a new node with value v at the back of list l.
func (*SList[T]) PushBackNode ¶
PushBackNode inserts a new node at the back of the list.
func (*SList[T]) PushFront ¶
func (l *SList[T]) PushFront(v T)
PushFront inserts a new node with value v at the front of list l.
func (*SList[T]) PushFrontNode ¶
PushFrontNode inserts a new node at the front of the list.
func (*SList[T]) Remove ¶
Remove removes the node at index i from the list. This operation is O(n) where n is the len of the list.
func (*SList[T]) RemoveFront ¶
RemoveFront removes the first node from the list and returns it.
type SNode ¶
type SNode[T any] struct { Value T // contains filtered or unexported fields }
SNode is a node of a singly linked list.
type SkipList ¶ added in v0.0.20
func NewSkipList ¶ added in v0.0.20
NewSkipList returns an initialized skip list.
func (*SkipList[K, V]) All ¶ added in v0.0.20
All returns an iterator that yields all element value in the skip list.
func (*SkipList[K, V]) Clear ¶ added in v0.0.20
func (s *SkipList[K, V]) Clear()
Clear removes all nodes from the skip list.
func (*SkipList[K, V]) Init ¶ added in v0.0.20
func (s *SkipList[K, V]) Init()
Init initializes the skip list.
func (*SkipList[K, V]) Keys ¶ added in v0.0.20
func (s *SkipList[K, V]) Keys() []K
Keys returns all keys in the skip list.
func (*SkipList[K, V]) RangeWithRange ¶ added in v0.0.20
RangeWithRange traverses the skip list in ascending order starting from the start key and ending before the end key. The zone is [start, end)
func (*SkipList[K, V]) RangeWithStart ¶ added in v0.0.20
RangeWithStart traverses the skip list in ascending order starting from the start key. The zone is [start, +∞)
func (*SkipList[K, V]) Set ¶ added in v0.0.20
func (s *SkipList[K, V]) Set(key K, val V)
Set sets the value associated with the key.
func (*SkipList[K, V]) SetNx ¶ added in v0.0.20
SetNx sets the value associated with the key if the key does not exist.
type SkipListWithCmp ¶ added in v0.0.20
func NewSkipListWithCmp ¶ added in v0.0.20
func NewSkipListWithCmp[K any, V any](keyCmp func(K, K) int) *SkipListWithCmp[K, V]
NewSkipListWithCmp returns an initialized skip list with custom comparator.
func (*SkipListWithCmp[K, V]) All ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) All() iter.Seq2[K, V]
All returns an iterator that yields all element value in the skip list with custom comparator.
func (*SkipListWithCmp[K, V]) Clear ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) Clear()
Clear removes all nodes from the skip list.
func (*SkipListWithCmp[K, V]) Get ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) Get(key K) (V, bool)
Get returns the value associated with the key.
func (*SkipListWithCmp[K, V]) GetNode ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) GetNode(key K) *SkipNodeCmp[K, V]
GetNode returns the node associated with the key.
func (*SkipListWithCmp[K, V]) Head ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) Head() *SkipNodeCmp[K, V]
Head returns the first node of the skip list.
func (*SkipListWithCmp[K, V]) Init ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) Init(keyCmp func(K, K) int)
Init initializes the skip list with custom comparator.
func (*SkipListWithCmp[K, V]) Keys ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) Keys() []K
Keys returns all keys in the skip list.
func (*SkipListWithCmp[K, V]) Len ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) Len() int
Len returns the number of nodes of the skip list.
func (*SkipListWithCmp[K, V]) Range ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) Range(f func(K, V) bool)
Range calls f sequentially for each key and value present in the skip list.
func (*SkipListWithCmp[K, V]) RangeWithRange ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) RangeWithRange(start, end K, f func(K, V) bool)
RangeWithRange calls f sequentially for each key and value present in the skip list within the range [start, end).
func (*SkipListWithCmp[K, V]) RangeWithStart ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) RangeWithStart(start K, f func(K, V) bool)
RangeWithStart calls f sequentially for each key and value present in the skip list starting from the key. The zone is [start, +∞)
func (*SkipListWithCmp[K, V]) Remove ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) Remove(key K) (V, bool)
Remove deletes the value associated with the key.
func (*SkipListWithCmp[K, V]) Set ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) Set(key K, val V)
Set sets the value associated with the key.
func (*SkipListWithCmp[K, V]) SetNx ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) SetNx(key K, val V) bool
SetNx sets the value associated with the key if the key does not exist.
func (*SkipListWithCmp[K, V]) SetX ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) SetX(key K, val V) bool
SetX sets the value associated with the key if the key exists.
func (*SkipListWithCmp[K, V]) Values ¶ added in v0.0.20
func (s *SkipListWithCmp[K, V]) Values() []V
Values returns all values in the skip list.
type SkipNodeCmp ¶ added in v0.0.20
func (*SkipNodeCmp[K, V]) Key ¶ added in v0.0.20
func (n *SkipNodeCmp[K, V]) Key() K
func (*SkipNodeCmp[K, V]) Next ¶ added in v0.0.20
func (n *SkipNodeCmp[K, V]) Next() *SkipNodeCmp[K, V]
func (*SkipNodeCmp[K, V]) SetValue ¶ added in v0.0.20
func (n *SkipNodeCmp[K, V]) SetValue(val V)
func (*SkipNodeCmp[K, V]) Value ¶ added in v0.0.20
func (n *SkipNodeCmp[K, V]) Value() V
type SyncList ¶
type SyncList[T any] struct { // contains filtered or unexported fields }
func (*SyncList[T]) Pop ¶
Pop removes and returns the value at the front of the list. If the list is empty or concurrent Pop is in progress, it returns false.