Documentation ¶
Overview ¶
Package priorityqueue implements a priority queue backed by binary queue.
A thread-safe priority queue based on a priority queue. The elements of the priority queue are ordered by a comparator provided at queue construction time.
The heap of this queue is the least/smallest element with respect to the specified ordering. If multiple elements are tied for least value, the heap is one of those elements arbitrarily.
Structure is thread safe.
References: https://en.wikipedia.org/wiki/Priority_queue
Index ¶
- func Append[T any](slices ...[]T) []T
- func Contains[T comparable](a []T, x T) bool
- func Dedup[T comparable](arr []T) []T
- func DeleteEmptyStrings(s []string) []string
- func Find(a []string, x string) int
- func IniToMap(path string) map[string]string
- func KeyValueSliceToMap(in []string) map[string]string
- func MapKeys[K comparable, T any](m map[K]T) []K
- func MapToIni(Map map[string]string) string
- func MatchItems(item string, items ...string) bool
- func MergeMap[T1 comparable, T2 any](a, b map[T1]T2) map[T1]T2
- func MergeStructs[T any](base, patch T) (T, error)
- func ReplaceAllInSlice(a []string, find string, replacement string) (replaced []string)
- func SelectorToMap(selector string) (matchLabels map[string]string)
- func SortedMap(m map[string]string) string
- func SplitAllInSlice(a []string, split string, index int) (replaced []string)
- func StructToIni(s interface{}) string
- func StructToJSON(v any) (string, error)
- func StructToMap(s interface{}) map[string]interface{}
- func ToBase64Map(m map[string]interface{}) map[string]string
- func ToByteMap(m map[string]interface{}) map[string][]byte
- func ToGenericMap(m map[string]string) map[string]interface{}
- func ToString(i interface{}) string
- func ToStringMap(m map[string]interface{}) map[string]string
- type Equals
- type MetricsOpts
- type Queue
- func (queue *Queue[T]) Clear()
- func (queue *Queue[T]) Dequeue() (T, bool)
- func (queue *Queue[T]) Empty() bool
- func (queue *Queue[T]) Enqueue(value T)
- func (queue *Queue[T]) EnqueueWithDelay(value T, delay time.Duration)
- func (queue *Queue[T]) Iterator() iter.Seq[T]
- func (queue *Queue[T]) Peek() (value T, ok bool)
- func (queue *Queue[T]) Size() int
- func (queue *Queue[T]) String() string
- func (queue *Queue[T]) Values() []T
- type QueueOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶ added in v1.12.0
func Append[T any](slices ...[]T) []T
Append concatenates multiple slices of strings into a single slice.
func Contains ¶ added in v1.5.1
func Contains[T comparable](a []T, x T) bool
Contains tells whether a contains x.
func Dedup ¶ added in v1.10.0
func Dedup[T comparable](arr []T) []T
func DeleteEmptyStrings ¶ added in v1.10.0
func Find ¶ added in v1.5.1
Find returns the smallest index i at which x == a[i], or len(a) if there is no such index.
func KeyValueSliceToMap ¶ added in v1.6.3
KeyValueSliceToMap takes in a list of strings in a=b format and returns a map from it.
Any string that's not in a=b format will be ignored.
func MapKeys ¶ added in v1.11.0
func MapKeys[K comparable, T any](m map[K]T) []K
func MatchItems ¶ added in v1.6.4
matchItems returns true if any of the items in the list match the item. negative matches are supported by prefixing the item with a "!". * matches everything to match prefix and suffix use "*" accordingly.
func MergeMap ¶ added in v1.6.3
func MergeMap[T1 comparable, T2 any](a, b map[T1]T2) map[T1]T2
MergeMap will merge map b into a. On key collision, map b takes precedence.
func MergeStructs ¶ added in v1.10.0
MergeStructs merges two structs where patch is applied on top of base
func ReplaceAllInSlice ¶
ReplaceAllInSlice runs strings.Replace on all elements in a slice and returns the result
func SelectorToMap ¶ added in v1.22.0
SelectorToMap returns a map from a selector string. i.e. "a=b,c=d" -> {"a": "b", "c": "d"}
func SortedMap ¶ added in v1.22.0
SortedMap takes a map and returns a sorted key value string i.e. {"a": "b", "c": "d"} -> "a=b,c=d"
func SplitAllInSlice ¶
SplitAllInSlice runs strings.Split on all elements in a slice and returns the results at the given index
func StructToIni ¶
func StructToIni(s interface{}) string
StructToIni takes an object and serializes it's fields in INI format
func StructToJSON ¶ added in v1.8.0
StructToJSON takes an object and returns its json form
func StructToMap ¶
func StructToMap(s interface{}) map[string]interface{}
StructToMap takes an object and returns all it's field in a map
func ToBase64Map ¶
ToBase64Map converts a map[string]interface{} to a map[string]string by converting []byte to base64
func ToByteMap ¶
ToByteMap converts a map[string]interface{} to a map[string]string by converting []byte to base64
func ToGenericMap ¶
ToGenericMap converts a map[string]string to a map[string]interface{}
func ToString ¶
func ToString(i interface{}) string
ToString takes an object and tries to convert it to a string
func ToStringMap ¶
ToStringMap converts a map[string]interface{} to a map[string]string by using each objects String() fn
Types ¶
type MetricsOpts ¶ added in v1.32.0
type MetricsOpts[T comparable] struct { Labels map[string]any Labeller map[string]func(i T) string DurationBuckets []float64 Name string Disable bool }
MetricsOpts contains options for queue metrics
type Queue ¶ added in v1.32.0
type Queue[T comparable] struct { Comparator utils.Comparator[T] Equals func(a, b T) bool Dedupe bool // contains filtered or unexported fields }
Queue holds elements in an array-list
func (*Queue[T]) Clear ¶ added in v1.32.0
func (queue *Queue[T]) Clear()
Clear removes all elements from the queue.
func (*Queue[T]) Dequeue ¶ added in v1.32.0
Dequeue removes first element of the queue and returns it, or nil if queue is empty. Second return parameter is true, unless the queue was empty and there was nothing to dequeue.
func (*Queue[T]) Empty ¶ added in v1.32.0
Empty returns true if queue does not contain any elements.
func (*Queue[T]) Enqueue ¶ added in v1.32.0
func (queue *Queue[T]) Enqueue(value T)
Enqueue adds a value to the end of the queue
func (*Queue[T]) EnqueueWithDelay ¶ added in v1.35.0
Enqueue adds a value to the end of the queue
func (*Queue[T]) Peek ¶ added in v1.32.0
Peek returns top element on the queue without removing it, or nil if queue is empty. Second return parameter is true, unless the queue was empty and there was nothing to peek.
type QueueOpts ¶ added in v1.32.0
type QueueOpts[T comparable] struct { Comparator utils.Comparator[T] Dedupe bool Equals func(a, b T) bool Metrics MetricsOpts[T] }