mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 02:10:46 +00:00
common/prque: remove dependency on golang.org/exp (#29314)
This commit is contained in:
parent
009542a92e
commit
57eb92da1c
5 changed files with 14 additions and 18 deletions
|
|
@ -17,11 +17,11 @@
|
||||||
package prque
|
package prque
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cmp"
|
||||||
"container/heap"
|
"container/heap"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/common/mclock"
|
"github.com/XinFinOrg/XDPoSChain/common/mclock"
|
||||||
"golang.org/x/exp/constraints"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// LazyQueue is a priority queue data structure where priorities can change over
|
// 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.
|
// If the upper estimate is exceeded then Update should be called for that item.
|
||||||
// A global Refresh function should also be called periodically.
|
// 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
|
clock mclock.Clock
|
||||||
// Items are stored in one of two internal queues ordered by estimated max
|
// 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
|
// 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 (
|
type (
|
||||||
PriorityCallback[P constraints.Ordered, V any] func(data V) P // actual priority callback
|
PriorityCallback[P cmp.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
|
MaxPriorityCallback[P cmp.Ordered, V any] func(data V, until mclock.AbsTime) P // estimated maximum priority callback
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewLazyQueue creates a new lazy queue
|
// 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]{
|
q := &LazyQueue[P, V]{
|
||||||
popQueue: newSstack[P, V](nil),
|
popQueue: newSstack[P, V](nil),
|
||||||
setIndex: setIndex,
|
setIndex: setIndex,
|
||||||
|
|
|
||||||
|
|
@ -18,18 +18,17 @@
|
||||||
package prque
|
package prque
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"cmp"
|
||||||
"container/heap"
|
"container/heap"
|
||||||
|
|
||||||
"golang.org/x/exp/constraints"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Priority queue data structure.
|
// Priority queue data structure.
|
||||||
type Prque[P constraints.Ordered, V any] struct {
|
type Prque[P cmp.Ordered, V any] struct {
|
||||||
cont *sstack[P, V]
|
cont *sstack[P, V]
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new priority queue.
|
// 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)}
|
return &Prque[P, V]{newSstack[P, V](setIndex)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,13 @@
|
||||||
|
|
||||||
package prque
|
package prque
|
||||||
|
|
||||||
import "golang.org/x/exp/constraints"
|
import "cmp"
|
||||||
|
|
||||||
// The size of a block of data
|
// The size of a block of data
|
||||||
const blockSize = 4096
|
const blockSize = 4096
|
||||||
|
|
||||||
// A prioritized item in the sorted stack.
|
// 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
|
value V
|
||||||
priority P
|
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
|
// 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
|
// the stack (heap) functionality and the Len, Less and Swap methods for the
|
||||||
// sortability requirements of the heaps.
|
// sortability requirements of the heaps.
|
||||||
type sstack[P constraints.Ordered, V any] struct {
|
type sstack[P cmp.Ordered, V any] struct {
|
||||||
setIndex SetIndexCallback[V]
|
setIndex SetIndexCallback[V]
|
||||||
size int
|
size int
|
||||||
capacity int
|
capacity int
|
||||||
|
|
@ -40,7 +40,7 @@ type sstack[P constraints.Ordered, V any] struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new, empty stack.
|
// 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 := new(sstack[P, V])
|
||||||
result.setIndex = setIndex
|
result.setIndex = setIndex
|
||||||
result.active = make([]*item[P, V], blockSize)
|
result.active = make([]*item[P, V], blockSize)
|
||||||
|
|
|
||||||
5
go.mod
5
go.mod
|
|
@ -47,13 +47,14 @@ require (
|
||||||
github.com/deckarep/golang-set v1.8.0
|
github.com/deckarep/golang-set v1.8.0
|
||||||
github.com/dop251/goja v0.0.0-20200721192441-a695b0cdd498
|
github.com/dop251/goja v0.0.0-20200721192441-a695b0cdd498
|
||||||
github.com/ethereum/c-kzg-4844 v0.4.0
|
github.com/ethereum/c-kzg-4844 v0.4.0
|
||||||
|
github.com/go-yaml/yaml v2.1.0+incompatible
|
||||||
github.com/influxdata/influxdb-client-go/v2 v2.4.0
|
github.com/influxdata/influxdb-client-go/v2 v2.4.0
|
||||||
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c
|
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c
|
||||||
github.com/kylelemons/godebug v1.1.0
|
github.com/kylelemons/godebug v1.1.0
|
||||||
github.com/mattn/go-isatty v0.0.17
|
github.com/mattn/go-isatty v0.0.17
|
||||||
|
github.com/protolambda/bls12-381-util v0.0.0-20220416220906-d8552aa452c7
|
||||||
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible
|
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible
|
||||||
github.com/urfave/cli/v2 v2.27.5
|
github.com/urfave/cli/v2 v2.27.5
|
||||||
golang.org/x/exp v0.0.0-20221126150942-6ab00d035af9
|
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -68,7 +69,6 @@ require (
|
||||||
github.com/dlclark/regexp2 v1.10.0 // indirect
|
github.com/dlclark/regexp2 v1.10.0 // indirect
|
||||||
github.com/go-ole/go-ole v1.2.5 // indirect
|
github.com/go-ole/go-ole v1.2.5 // indirect
|
||||||
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
|
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
|
||||||
github.com/go-yaml/yaml v2.1.0+incompatible // indirect
|
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
|
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
|
||||||
github.com/kilic/bls12-381 v0.1.0 // indirect
|
github.com/kilic/bls12-381 v0.1.0 // indirect
|
||||||
|
|
@ -78,7 +78,6 @@ require (
|
||||||
github.com/mmcloughlin/addchain v0.4.0 // indirect
|
github.com/mmcloughlin/addchain v0.4.0 // indirect
|
||||||
github.com/naoina/go-stringutil v0.1.0 // indirect
|
github.com/naoina/go-stringutil v0.1.0 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/protolambda/bls12-381-util v0.0.0-20220416220906-d8552aa452c7 // indirect
|
|
||||||
github.com/rivo/uniseg v0.2.0 // indirect
|
github.com/rivo/uniseg v0.2.0 // indirect
|
||||||
github.com/rogpeppe/go-internal v1.9.0 // indirect
|
github.com/rogpeppe/go-internal v1.9.0 // indirect
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
|
|
|
||||||
2
go.sum
2
go.sum
|
|
@ -220,8 +220,6 @@ golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPh
|
||||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||||
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
|
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
|
||||||
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
|
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
|
||||||
golang.org/x/exp v0.0.0-20221126150942-6ab00d035af9 h1:yZNXmy+j/JpX19vZkVktWqAo7Gny4PBWYYK3zskGpx4=
|
|
||||||
golang.org/x/exp v0.0.0-20221126150942-6ab00d035af9/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
|
||||||
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
|
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
|
||||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue