mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
common/prqueue: replace golang.org/exp/constraints.Ordered with cmp.Ordered
This commit is contained in:
parent
fbf1600e67
commit
72a9dacafc
3 changed files with 12 additions and 13 deletions
|
|
@ -20,8 +20,8 @@ import (
|
|||
"container/heap"
|
||||
"time"
|
||||
|
||||
"cmp"
|
||||
"github.com/ethereum/go-ethereum/common/mclock"
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
// LazyQueue is a priority queue data structure where priorities can change over
|
||||
|
|
@ -33,7 +33,7 @@ import (
|
|||
//
|
||||
// If the upper estimate is exceeded then Update should be called for that item.
|
||||
// A global Refresh function should also be called periodically.
|
||||
type LazyQueue[P constraints.Ordered, V any] struct {
|
||||
type LazyQueue[P cmp.Ordered, V any] struct {
|
||||
clock mclock.Clock
|
||||
// Items are stored in one of two internal queues ordered by estimated max
|
||||
// priority until the next and the next-after-next refresh. Update and Refresh
|
||||
|
|
@ -50,12 +50,12 @@ type LazyQueue[P constraints.Ordered, V any] struct {
|
|||
}
|
||||
|
||||
type (
|
||||
PriorityCallback[P constraints.Ordered, V any] func(data V) P // actual priority callback
|
||||
MaxPriorityCallback[P constraints.Ordered, V any] func(data V, until mclock.AbsTime) P // estimated maximum priority callback
|
||||
PriorityCallback[P cmp.Ordered, V any] func(data V) P // actual priority callback
|
||||
MaxPriorityCallback[P cmp.Ordered, V any] func(data V, until mclock.AbsTime) P // estimated maximum priority callback
|
||||
)
|
||||
|
||||
// NewLazyQueue creates a new lazy queue
|
||||
func NewLazyQueue[P constraints.Ordered, V any](setIndex SetIndexCallback[V], priority PriorityCallback[P, V], maxPriority MaxPriorityCallback[P, V], clock mclock.Clock, refreshPeriod time.Duration) *LazyQueue[P, V] {
|
||||
func NewLazyQueue[P cmp.Ordered, V any](setIndex SetIndexCallback[V], priority PriorityCallback[P, V], maxPriority MaxPriorityCallback[P, V], clock mclock.Clock, refreshPeriod time.Duration) *LazyQueue[P, V] {
|
||||
q := &LazyQueue[P, V]{
|
||||
popQueue: newSstack[P, V](nil),
|
||||
setIndex: setIndex,
|
||||
|
|
|
|||
|
|
@ -18,18 +18,17 @@
|
|||
package prque
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"container/heap"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
)
|
||||
|
||||
// Priority queue data structure.
|
||||
type Prque[P constraints.Ordered, V any] struct {
|
||||
type Prque[P cmp.Ordered, V any] struct {
|
||||
cont *sstack[P, V]
|
||||
}
|
||||
|
||||
// New creates a new priority queue.
|
||||
func New[P constraints.Ordered, V any](setIndex SetIndexCallback[V]) *Prque[P, V] {
|
||||
func New[P cmp.Ordered, V any](setIndex SetIndexCallback[V]) *Prque[P, V] {
|
||||
return &Prque[P, V]{newSstack[P, V](setIndex)}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@
|
|||
|
||||
package prque
|
||||
|
||||
import "golang.org/x/exp/constraints"
|
||||
import "cmp"
|
||||
|
||||
// The size of a block of data
|
||||
const blockSize = 4096
|
||||
|
||||
// A prioritized item in the sorted stack.
|
||||
type item[P constraints.Ordered, V any] struct {
|
||||
type item[P cmp.Ordered, V any] struct {
|
||||
value V
|
||||
priority P
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@ type SetIndexCallback[V any] func(data V, index int)
|
|||
// Internal sortable stack data structure. Implements the Push and Pop ops for
|
||||
// the stack (heap) functionality and the Len, Less and Swap methods for the
|
||||
// sortability requirements of the heaps.
|
||||
type sstack[P constraints.Ordered, V any] struct {
|
||||
type sstack[P cmp.Ordered, V any] struct {
|
||||
setIndex SetIndexCallback[V]
|
||||
size int
|
||||
capacity int
|
||||
|
|
@ -40,7 +40,7 @@ type sstack[P constraints.Ordered, V any] struct {
|
|||
}
|
||||
|
||||
// Creates a new, empty stack.
|
||||
func newSstack[P constraints.Ordered, V any](setIndex SetIndexCallback[V]) *sstack[P, V] {
|
||||
func newSstack[P cmp.Ordered, V any](setIndex SetIndexCallback[V]) *sstack[P, V] {
|
||||
result := new(sstack[P, V])
|
||||
result.setIndex = setIndex
|
||||
result.active = make([]*item[P, V], blockSize)
|
||||
|
|
|
|||
Loading…
Reference in a new issue