Documentation
¶
Overview ¶
Example (ReversedStableMinHeap) ¶
package main
import (
"fmt"
"github.com/byExist/priorityqueues/mpqs"
)
func main() {
reversedStable := func(x, y mpqs.Elem[string, int]) bool {
if x.Priority() == y.Priority() {
return x.Sequence() > y.Sequence()
}
return x.Priority() < y.Priority()
}
pq := mpqs.New(reversedStable)
mpqs.Enqueue(pq, "a", 1)
mpqs.Enqueue(pq, "b", 2)
mpqs.Enqueue(pq, "c", 2)
first, _ := mpqs.Dequeue(pq)
second, _ := mpqs.Dequeue(pq)
third, _ := mpqs.Dequeue(pq)
fmt.Println(first)
fmt.Println(second)
fmt.Println(third)
}
Output: a c b
Index ¶
- func Clear[T any, P cmp.Ordered](pq *PriorityQueue[T, P])
- func Dequeue[T any, P cmp.Ordered](pq *PriorityQueue[T, P]) (T, bool)
- func Enqueue[T any, P cmp.Ordered](pq *PriorityQueue[T, P], item T, prio P)
- func Len[T any, P cmp.Ordered](pq *PriorityQueue[T, P]) int
- func MaxFirst[T any, P cmp.Ordered](x, y Elem[T, P]) bool
- func MinFirst[T any, P cmp.Ordered](x, y Elem[T, P]) bool
- func Peek[T any, P cmp.Ordered](pq *PriorityQueue[T, P]) (T, bool)
- func StableMaxFirst[T any, P cmp.Ordered](x, y Elem[T, P]) bool
- func StableMinFirst[T any, P cmp.Ordered](x, y Elem[T, P]) bool
- type Elem
- type PriorityQueue
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clear ¶
func Clear[T any, P cmp.Ordered](pq *PriorityQueue[T, P])
Example ¶
package main
import (
"fmt"
"github.com/byExist/priorityqueues/mpqs"
)
func main() {
pq := mpqs.New(mpqs.MinFirst[string, int])
mpqs.Enqueue(pq, "task", 1)
mpqs.Clear(pq)
fmt.Println(mpqs.Len(pq))
}
Output: 0
func Dequeue ¶
func Dequeue[T any, P cmp.Ordered](pq *PriorityQueue[T, P]) (T, bool)
Example ¶
package main
import (
"fmt"
"github.com/byExist/priorityqueues/mpqs"
)
func main() {
pq := mpqs.New(mpqs.MinFirst[string, int])
mpqs.Enqueue(pq, "task1", 2)
mpqs.Enqueue(pq, "task2", 1)
item, _ := mpqs.Dequeue(pq)
fmt.Println(item)
}
Output: task2
func Enqueue ¶
func Enqueue[T any, P cmp.Ordered](pq *PriorityQueue[T, P], item T, prio P)
Example ¶
package main
import (
"fmt"
"github.com/byExist/priorityqueues/mpqs"
)
func main() {
pq := mpqs.New(mpqs.MinFirst[string, int])
mpqs.Enqueue(pq, "task", 10)
item, _ := mpqs.Peek(pq)
fmt.Println(item)
}
Output: task
func Len ¶
func Len[T any, P cmp.Ordered](pq *PriorityQueue[T, P]) int
Example ¶
package main
import (
"fmt"
"github.com/byExist/priorityqueues/mpqs"
)
func main() {
pq := mpqs.New(mpqs.MinFirst[string, int])
fmt.Println(mpqs.Len(pq))
mpqs.Enqueue(pq, "a", 1)
fmt.Println(mpqs.Len(pq))
}
Output: 0 1
func Peek ¶
func Peek[T any, P cmp.Ordered](pq *PriorityQueue[T, P]) (T, bool)
Example ¶
package main
import (
"fmt"
"github.com/byExist/priorityqueues/mpqs"
)
func main() {
pq := mpqs.New(mpqs.MinFirst[string, int])
mpqs.Enqueue(pq, "task", 1)
item, _ := mpqs.Peek(pq)
fmt.Println(item)
}
Output: task
Types ¶
type PriorityQueue ¶
Click to show internal directories.
Click to hide internal directories.