Documentation ¶
Index ¶
- func Abs(n int) int
- func GCD(a, b int) int
- func LCM(a, b int, args ...int) int
- func Mod(n, m int) int
- type Item
- type Node
- type PriorityQueue
- type Queue
- type Ring
- func (ring *Ring[T]) Append(elem T)
- func (ring Ring[T]) FindIndex(elem T) int
- func (ring *Ring[T]) GetNode(idx int) *Node[T]
- func (ring *Ring[T]) GetValue(idx int) T
- func (ring *Ring[T]) MoveIdx(idx, delta int)
- func (ring *Ring[T]) MoveNode(node *Node[T], delta int)
- func (ring Ring[T]) OriginalNodes() []*Node[T]
- func (ring Ring[T]) OriginalValues() []T
- func (ring Ring[T]) Values() []T
- type Set
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Item ¶
type Item[T any] struct { Value T // The value of the item; arbitrary. Priority int // The priority of the item in the queue (less is higher). // contains filtered or unexported fields }
An Item is something we manage in a priority queue.
type Node ¶
type Node[T comparable] struct { Value T Prev *Node[T] Next *Node[T] }
A Node holds a value and forward and backward pointers
type PriorityQueue ¶
A PriorityQueue implements heap.Interface and holds Items.
Note: please use the `container/heap` methods when pushing/popping items!
func (PriorityQueue[T]) Len ¶
func (pq PriorityQueue[T]) Len() int
Return the size of the PriorityQueue
func (PriorityQueue[T]) Less ¶
func (pq PriorityQueue[T]) Less(i, j int) bool
Less is used to sort the PriorityQueue
func (*PriorityQueue[T]) Pop ¶
func (pq *PriorityQueue[T]) Pop() any
Pop the Item[T] with the lowest priority value
func (*PriorityQueue[T]) Push ¶
func (pq *PriorityQueue[T]) Push(x any)
Add an Item[T] to the PriorityQueue
func (PriorityQueue[T]) Swap ¶
func (pq PriorityQueue[T]) Swap(i, j int)
Swap two elements of the PriorityQueue using their indices
func (*PriorityQueue[T]) Update ¶
func (pq *PriorityQueue[T]) Update(item *Item[T], value T, priority int)
Update modifies the priority and value of an Item[T] in the queue.
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
A queue is internally represented with a slice
type Ring ¶
type Ring[T comparable] struct { Size int // contains filtered or unexported fields }
A ring is a singly linked list with extra logic
func (Ring[T]) OriginalNodes ¶
Get the slice of nodes in the insertion order
func (Ring[T]) OriginalValues ¶
func (ring Ring[T]) OriginalValues() []T
Get the list of values in the insertion order
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
A set is represented by a map of its values
func NewSetFrom ¶
func NewSetFrom[T comparable](values []T) Set[T]
Create a new Set from a slice of values
func (Set[T]) Intersection ¶
Return the intersection of two given Sets