Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewUniquePriorityQueue ¶
func NewUniquePriorityQueue[T comparable, P constraints.Ordered]( items ...PriorityQueueItem[T, P]) *uniquePriorityQueue[T, P]
NewUniquePriorityQueue returns a unique priority queue.
Types ¶
type OrderedMap ¶
type OrderedMap[K comparable, V any] interface { // Index returns the index of the given key, or -1. Index(key K) int // Len returns the number of items in the map. Len() int // Contains returns true if the map contains the given key. Contains(key K) bool // Get returns the value for the given key, or false. Get(key K) (value V, ok bool) // Put adds or updates the given key with the given value. Put(key K, value V) // Delete removes the given key, the method takes O(n) time to update the linked list. Delete(key K) // Clear removes all items from the map. Clear() // Clone returns a clone of the map. Clone() OrderedMap[K, V] // Iterate iterates over the map, returns false if the iteration stopped early. Iterate(yield func(key K, value V) bool) bool // Item returns an item at the given index. Item(index int) (K, V) // Key returns a key at the given index. Key(index int) K // Value returns a value at the given index. Value(index int) V // Items returns a slice of items in the order they were inserted. Items() []OrderedMapItem[K, V] // Keys returns a slice of keys in the order they were inserted. Keys() []K // Values returns a slice of values in the order they were inserted. Values() []V }
Map is an ordered map which maintains the order of insertion, even on updates.
func NewOrderedMap ¶
func NewOrderedMap[K comparable, V any](items ...OrderedMapItem[K, V]) OrderedMap[K, V]
NewOrderedMap returns a new ordered map.
func NewOrderedMapSize ¶
func NewOrderedMapSize[K comparable, V any](size int) OrderedMap[K, V]
NewOrderedMapSize returns a new ordered map with the given size hint.
type OrderedMapItem ¶
type OrderedMapItem[K comparable, V any] struct { Key K Value V }
OrderedMapItem is a key-value pair.
type PriorityQueue ¶
type PriorityQueue[T any, P any] interface { // Len returns the number of elements in the queue. Len() int // Clear removes all elements from the queue. Clear() // Poll removes and returns the minimum element (according to Less) from the queue. Poll() (value T, priority P, ok bool) // Push pushes an element onto the queue. Push(value T, priority P) }
PriorityQueue is a priority queue.
func NewPriorityQueue ¶
func NewPriorityQueue[T any, P constraints.Ordered]( items ...PriorityQueueItem[T, P]) PriorityQueue[T, P]
NewPriorityQueue returns a new priority queue with an ordered priority.
func NewPriorityQueueCompare ¶
func NewPriorityQueueCompare[T any, P any](compare compare.Compare[P], items ...PriorityQueueItem[T, P]) PriorityQueue[T, P]
NewPriorityQueueCompare returns a new priority queue with a priority compare function.
type PriorityQueueItem ¶
PriorityQueueItem is an element of the queue.
type UniquePriorityQueue ¶
type UniquePriorityQueue[T comparable, P any] interface { // Len returns the number of elements in the queue. Len() int // Clear removes all elements from the queue. Clear() // Contains returns true if the queue contains an element. Contains(value T) bool // Get returns the priority of an element. Get(value T) (p P, ok bool) // Push pushes an element onto the queue, or updates its priority. Push(value T, priority P) // Poll removes and returns the minimum element (according to Less) from the queue. Poll() (value T, priority P, ok bool) // Remove removes an element from the queue, and returns its priority. Remove(value T) (p P, ok bool) }
UniquePriorityQueue is a priority queue that contains unique elements.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.