Documentation ¶
Index ¶
- type Deque
- type DoublyLinkedList
- type DoublyLinkedNode
- type Elem
- type GenericHeap
- type Heap
- type LinkedHashmap
- func (lm *LinkedHashmap) BecomeNewest(k interface{})
- func (lm *LinkedHashmap) Contains(k interface{}) bool
- func (lm *LinkedHashmap) Delete(k interface{})
- func (lm *LinkedHashmap) Get(k interface{}) interface{}
- func (lm *LinkedHashmap) IntoIter() <-chan *DoublyLinkedNode
- func (lm *LinkedHashmap) PopEldest() *DoublyLinkedNode
- func (lm *LinkedHashmap) Put(k, v interface{})
- func (lm *LinkedHashmap) Size() int
- type LinkedList
- type LinkedListNode
- type MaxHeap
- type MinHeap
- type MonotonicQueue
- type PriorityQueue
- type Queue
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Deque ¶
type Deque[V any] struct { Elems []V // contains filtered or unexported fields }
Deque is a double end queue, contains a slice of any type
func (*Deque[V]) PeekFirst ¶
func (d *Deque[V]) PeekFirst() V
PeekFirst returns the queue's first element
func (*Deque[V]) PeekLast ¶
func (d *Deque[V]) PeekLast() V
PeekLast returns the queue's last element
func (*Deque[V]) PopFirst ¶
func (d *Deque[V]) PopFirst() V
PopFirst returns the queue's first element and remove it from the queue
func (*Deque[V]) PopLast ¶
func (d *Deque[V]) PopLast() V
PopLast returns the queue's last element and remove it from the queue
func (*Deque[V]) PushFirst ¶
func (d *Deque[V]) PushFirst(elem V)
PushFirst inserts a new element of any type at the begining
type DoublyLinkedList ¶
type DoublyLinkedList struct {
Head, Tail *DoublyLinkedNode
Len int
}
Doubly Linked List
func NewDoublyLinkedList ¶
func NewDoublyLinkedList() *DoublyLinkedList
NewDoublyLinkedList initializes a DoublyLinkedList
func (*DoublyLinkedList) Delete ¶
func (dl *DoublyLinkedList) Delete(node *DoublyLinkedNode)
Delete removes the chosen node from the list
func (*DoublyLinkedList) Pop ¶
func (dl *DoublyLinkedList) Pop() *DoublyLinkedNode
Pop moves out the node from the beginning of the list
func (*DoublyLinkedList) Push ¶
func (dl *DoublyLinkedList) Push(node *DoublyLinkedNode)
Push appendes a node at the list's end
type DoublyLinkedNode ¶
type DoublyLinkedNode struct {
Key, Val interface{}
Prev, Next *DoublyLinkedNode
}
Doubly Linked Node
func NewDoublyLinkedNode ¶
func NewDoublyLinkedNode(k, v interface{}) *DoublyLinkedNode
NewDoublyLinkedNode initializes a DoublyLinkedNode
type Elem ¶
type Elem[T any, O constraints.Ordered] struct { // contains filtered or unexported fields }
Elem contains a value, its priority and an index for heap.Interface methods
type GenericHeap ¶
type GenericHeap[T any, O constraints.Ordered] interface { heap.Interface GetElems() []*Elem[T, O] }
GenericHeap contains a heap.Interface and a GetElems method MaxHeap and MinHeap implement this interface
type Heap ¶
type Heap[T any, O constraints.Ordered] []*Elem[T, O]
Heap implements heap.Interface's methods except Less(i, j int) bool
type LinkedHashmap ¶
type LinkedHashmap struct { Map map[interface{}]*DoublyLinkedNode List *DoublyLinkedList }
Linked Hash Map
func NewLinkedHashmap ¶
func NewLinkedHashmap() *LinkedHashmap
NewLinkedHashmap initializes a linked hashmap
func NewLinkedHashmapFromKV ¶
func NewLinkedHashmapFromKV(kvList [][2]interface{}) *LinkedHashmap
NewLinkedHashmapFromKV initializes a linked hashmap from a list of key-value tuples
func (*LinkedHashmap) BecomeNewest ¶
func (lm *LinkedHashmap) BecomeNewest(k interface{})
BecomeNewest moves the choosen node to the end of the list
func (*LinkedHashmap) Contains ¶
func (lm *LinkedHashmap) Contains(k interface{}) bool
Contains checks if the linked hashmap contains a certain value
func (*LinkedHashmap) Delete ¶
func (lm *LinkedHashmap) Delete(k interface{})
Delete removes the node if exist.
func (*LinkedHashmap) Get ¶
func (lm *LinkedHashmap) Get(k interface{}) interface{}
Get returns the node's value if exist.
func (*LinkedHashmap) IntoIter ¶
func (lm *LinkedHashmap) IntoIter() <-chan *DoublyLinkedNode
IntoIter returns an iterator to read through the ordered linked map
func (*LinkedHashmap) PopEldest ¶
func (lm *LinkedHashmap) PopEldest() *DoublyLinkedNode
PopEldest moves out the node from the beginning of the list
func (*LinkedHashmap) Put ¶
func (lm *LinkedHashmap) Put(k, v interface{})
Put adds a node to the list and registers to the dictionary if not exist yet. Update the value of exist one.
func (*LinkedHashmap) Size ¶
func (lm *LinkedHashmap) Size() int
Size returns the linked hashmap's size
type LinkedList ¶
type LinkedList[V any] struct { Head, Tail *LinkedListNode[V] // contains filtered or unexported fields }
LinkedList contains two pointers indicating the linked list's Head and Tail position
func NewLinkedList ¶
func NewLinkedList[V any](slice []V) *LinkedList[V]
NewLinkedList creates a linked list from a slice of any type
func (*LinkedList[V]) PrintAll ¶
func (l *LinkedList[V]) PrintAll()
PrintAll prints all elements' Value in the linked list, comma separated.
func (*LinkedList[V]) Push ¶
func (l *LinkedList[V]) Push(v V)
Push appends a new element to the linked list's Tail
func (*LinkedList[V]) ToSlice ¶
func (l *LinkedList[V]) ToSlice() []V
ToSlice converts the linked list back to a slice of the same element Value's type
type LinkedListNode ¶
type LinkedListNode[V any] struct { Val V Next *LinkedListNode[V] }
LinkedListNode is the basic element in LinkedList contains a Value and a pointer to the Next element
type MaxHeap ¶
type MaxHeap[T any, O constraints.Ordered] struct { *Heap[T, O] }
MaxHeap embeds Heap and provides a Less method, thus implements heap.Interface it also provides a GetElems method, to satisfy the GenericHeap interface
type MinHeap ¶
type MinHeap[T any, O constraints.Ordered] struct { *Heap[T, O] }
MinHeap embeds Heap and provides a Less method, thus implements heap.Interface it also provides a GetElems method, to satisfy the GenericHeap interface
type MonotonicQueue ¶
type MonotonicQueue[V constraints.Ordered] struct { Deque *Deque[V] // contains filtered or unexported fields }
Monotonic queue contains a double end queue of any type All the elements stored in the Dequeue is in descending order
func NewMonotonicQueue ¶
func NewMonotonicQueue[V constraints.Ordered]() *MonotonicQueue[V]
NewMonotonicQueue creates an empty double end queue of any type
func (*MonotonicQueue[V]) IsEmpty ¶
func (mq *MonotonicQueue[V]) IsEmpty() bool
IsEmpty checks if the monotonic queue is empty
func (*MonotonicQueue[V]) Max ¶
func (mq *MonotonicQueue[V]) Max() V
Max returns the max element of the queue, which is the first element of the underlying Deque
func (*MonotonicQueue[V]) Pop ¶
func (mq *MonotonicQueue[V]) Pop(elem V)
Pop tries to remove the given element if this element is the max of the queue if not, this action is ignored
func (*MonotonicQueue[V]) Push ¶
func (mq *MonotonicQueue[V]) Push(elem V)
Push pops up all elements smaller than the current element from the end of the Dequeue and inserts the current element at the end of the underlying Dequeue
func (*MonotonicQueue[V]) Size ¶
func (mq *MonotonicQueue[V]) Size() int
Size returns the length of monotonic queue
type PriorityQueue ¶
type PriorityQueue[T any, O constraints.Ordered] struct { // contains filtered or unexported fields }
PriorityQueue adds the thread safe to the GenericHeap
func NewPQ ¶
func NewPQ[T any, O constraints.Ordered](values []T, prios []O, popLowest bool) *PriorityQueue[T, O]
NewPQ builds a priority queue with a slice of value and priority popLowest decides its a min heap or max heap
func (*PriorityQueue[T, O]) Peek ¶
func (pq *PriorityQueue[T, O]) Peek() T
Peek checks the min/max value of the priority queue
func (*PriorityQueue[T, O]) Pop ¶
func (pq *PriorityQueue[T, O]) Pop() T
Pop returns the min/max value of the priority queue
func (*PriorityQueue[T, O]) PopWithPriority ¶
func (pq *PriorityQueue[T, O]) PopWithPriority() (T, O)
PopWithPriority returns the min/max value of the priority queue along with its priority
func (*PriorityQueue[T, O]) Push ¶
func (pq *PriorityQueue[T, O]) Push(value T, prio O)
Push adds a element to the queue
func (*PriorityQueue[T, O]) Size ¶
func (pq *PriorityQueue[T, O]) Size() int
Size returns the number of elements in the priority queue
type Queue ¶
type Queue[V any] struct { Elems []V // contains filtered or unexported fields }
Queue contains a slice of any type
func (*Queue[V]) Pop ¶
func (q *Queue[V]) Pop() V
Pop returns the queue's head and remove it from the queue