Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Heap ¶
type Heap struct {
// contains filtered or unexported fields
}
Heap is a data structure that implements a min-heap. Not thread-safe.
Although we could use workqueue.DelayingInterface for this, we don't need the concurrency guarantees that the workqueue package provides, and we should use a more straightforward implementation instead.
Example ¶
ExampleHeap implements the test from container/heap.
package main import ( "fmt" "github.com/furiko-io/furiko/pkg/utils/heap" ) func main() { hp := heap.New([]*heap.Item{ heap.NewItem("banana", 3), heap.NewItem("apple", 2), heap.NewItem("pear", 4), }) // Insert a new item and then modify its priority. hp.Push("orange", 1) hp.Update("orange", 5) // Take the items out; they arrive in increasing priority order. for hp.Len() > 0 { item := hp.Pop() fmt.Printf("%.2d:%s ", item.Priority(), item.Name()) } }
Output: 02:apple 03:banana 04:pear 05:orange
Click to show internal directories.
Click to hide internal directories.