import "github.com/ethereum/go-ethereum/common/prque"
Package prque implements a priority queue data structure supporting arbitrary value types and int64 priorities.
If you would like to use a min-priority queue, simply negate the priorities.
Internally the queue is based on the standard heap package working on a sortable version of the block based stack.
lazyqueue.go prque.go sstack.go
type LazyQueue struct {
// contains filtered or unexported fields
}
LazyQueue is a priority queue data structure where priorities can change over time and are only evaluated on demand. Two callbacks are required: - priority evaluates the actual priority of an item - maxPriority gives an upper estimate for the priority in any moment between
now and the given absolute time
If the upper estimate is exceeded then Update should be called for that item. A global Refresh function should also be called periodically.
func NewLazyQueue(setIndex SetIndexCallback, priority PriorityCallback, maxPriority MaxPriorityCallback, clock mclock.Clock, refreshPeriod time.Duration) *LazyQueue
NewLazyQueue creates a new lazy queue
Empty checks whether the priority queue is empty.
MultiPop pops multiple items from the queue and is more efficient than calling Pop multiple times. Popped items are passed to the callback. MultiPop returns when the callback returns false or there are no more items to pop.
Pop removes and returns the item with the greatest actual priority
PopItem pops the item from the queue only, dropping the associated priority value.
Push adds an item to the queue
Refresh performs queue re-evaluation if necessary
Remove removes removes the item with the given index.
Reset clears the contents of the queue
Size returns the number of items in the priority queue.
Update updates the upper priority estimate for the item with the given queue index
type MaxPriorityCallback func(data interface{}, until mclock.AbsTime) int64 // estimated maximum priority callback
type Prque struct {
// contains filtered or unexported fields
}
Priority queue data structure.
func New(setIndex SetIndexCallback) *Prque
New creates a new priority queue.
Checks whether the priority queue is empty.
Peek returns the value with the greates priority but does not pop it off.
Pops the value with the greates priority off the stack and returns it. Currently no shrinking is done.
Pops only the item from the queue, dropping the associated priority value.
Pushes a value with a given priority into the queue, expanding if necessary.
Remove removes the element with the given index.
Clears the contents of the priority queue.
Returns the number of element in the priority queue.
SetIndexCallback is called when the element is moved to a new index. Providing SetIndexCallback is optional, it is needed only if the application needs to delete elements other than the top one.
Package prque imports 3 packages (graph) and is imported by 328 packages. Updated 2021-01-11. Refresh now. Tools for package owners.