Documentation
¶
Overview ¶
Example (StringLengthPriority) ¶
package main
import (
"fmt"
"github.com/byExist/priorityqueues/pqs"
)
func main() {
lengthPriority := func(x, y string) bool {
return len(x) < len(y)
}
pq := pqs.New(lengthPriority)
pqs.Enqueue(pq, "apple")
pqs.Enqueue(pq, "kiwi")
pqs.Enqueue(pq, "banana")
for pqs.Len(pq) > 0 {
item, _ := pqs.Dequeue(pq)
fmt.Println(item)
}
}
Output: kiwi apple banana
Index ¶
- func Clear[T cmp.Ordered](pq *PriorityQueue[T])
- func Dequeue[T cmp.Ordered](pq *PriorityQueue[T]) (T, bool)
- func Enqueue[T cmp.Ordered](pq *PriorityQueue[T], item T)
- func Len[T cmp.Ordered](pq *PriorityQueue[T]) int
- func MaxFirst[T cmp.Ordered](x, y T) bool
- func MinFirst[T cmp.Ordered](x, y T) bool
- func Peek[T cmp.Ordered](pq *PriorityQueue[T]) (T, bool)
- type PriorityQueue
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clear ¶
func Clear[T cmp.Ordered](pq *PriorityQueue[T])
Example ¶
package main
import (
"fmt"
"github.com/byExist/priorityqueues/pqs"
)
func main() {
pq := pqs.New(pqs.MinFirst[int])
pqs.Enqueue(pq, 1)
pqs.Clear(pq)
fmt.Println(pqs.Len(pq))
}
Output: 0
func Dequeue ¶
func Dequeue[T cmp.Ordered](pq *PriorityQueue[T]) (T, bool)
Example ¶
package main
import (
"fmt"
"github.com/byExist/priorityqueues/pqs"
)
func main() {
pq := pqs.New(pqs.MinFirst[int])
pqs.Enqueue(pq, 2)
pqs.Enqueue(pq, 1)
item, _ := pqs.Dequeue(pq)
fmt.Println(item)
}
Output: 1
func Enqueue ¶
func Enqueue[T cmp.Ordered](pq *PriorityQueue[T], item T)
Example ¶
package main
import (
"fmt"
"github.com/byExist/priorityqueues/pqs"
)
func main() {
pq := pqs.New(pqs.MinFirst[int])
pqs.Enqueue(pq, 5)
item, _ := pqs.Peek(pq)
fmt.Println(item)
}
Output: 5
func Len ¶
func Len[T cmp.Ordered](pq *PriorityQueue[T]) int
Example ¶
package main
import (
"fmt"
"github.com/byExist/priorityqueues/pqs"
)
func main() {
pq := pqs.New(pqs.MinFirst[int])
fmt.Println(pqs.Len(pq))
pqs.Enqueue(pq, 1)
fmt.Println(pqs.Len(pq))
}
Output: 0 1
func MaxFirst ¶
Example ¶
package main
import (
"fmt"
"github.com/byExist/priorityqueues/pqs"
)
func main() {
fmt.Println(pqs.MaxFirst(1, 2))
}
Output: false
Types ¶
type PriorityQueue ¶
func New ¶
func New[T cmp.Ordered]( lessFunc func(x, y T) bool, ) *PriorityQueue[T]
Example ¶
package main
import (
"fmt"
"github.com/byExist/priorityqueues/pqs"
)
func main() {
pq := pqs.New(pqs.MinFirst[int])
pqs.Enqueue(pq, 3)
pqs.Enqueue(pq, 1)
item, _ := pqs.Dequeue(pq)
fmt.Println(item)
}
Output: 1
Click to show internal directories.
Click to hide internal directories.