Documentation
¶
Overview ¶
Package minheap provides a binary heap whose elements live off the Go heap.
Example ¶
package main
import (
"fmt"
memory "github.com/stubbedev/memory-go"
"github.com/stubbedev/memory-go/minheap"
)
func main() {
var a memory.Local
defer a.Close()
type job struct {
Priority int
ID uint32
}
h, err := minheap.New(&a, func(x, y job) bool { return x.Priority < y.Priority })
if err != nil {
panic(err)
}
defer h.Free()
for i, p := range []int{5, 1, 3} {
if err := h.Push(job{Priority: p, ID: uint32(i)}); err != nil {
panic(err)
}
}
for h.Len() > 0 {
j, _ := h.Pop()
fmt.Print(j.ID, " ")
}
fmt.Println()
}
Output: 1 2 0
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Heap ¶
type Heap[T any] struct { // contains filtered or unexported fields }
Heap pops the element for which less reports true against every other first; pass a greater-than func for a max-heap. It is not safe for concurrent use.
func (*Heap[T]) DeleteFunc ¶
DeleteFunc removes every element for which del returns true and returns how many it removed.
func (*Heap[T]) Peek ¶
Peek returns the least element without removing it, or reports false if h is empty.