common/prque: generic priority queue (#26290)

* common, core, eth, les, trie: make prque generic

* les/vflux/server: fixed issues in priorityPool

* common, core, eth, les, trie: make priority also generic in prque

* les/flowcontrol: add test case for priority accumulator overflow

* les/flowcontrol: avoid priority value overflow

* common/prque: use int priority in some tests

No need to convert to int64 when we can just change the type used by the
queue.

* common/prque: remove comment about int64 range

---------

Co-authored-by: Zsolt Felfoldi <zsfelfoldi@gmail.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
authored and GitHub committed 2023-02-09 13:03:54 +02:00
1 parent 6a148dd5c3
commit bf1798e04e
20 files changed
+277 -264

No files matched your search

+15 -15
View File
@@ -17,23 +17,23 @@ import (
func TestSstack(t *testing.T) {
// Create some initial data
size := 16 * blockSize
data := make([]*item, size)
data := make([]*item[int64, int], size)
for i := 0; i < size; i++ {
data[i] = &item{rand.Int(), rand.Int63()}
data[i] = &item[int64, int]{rand.Int(), rand.Int63()}
}
stack := newSstack(nil, false)
stack := newSstack[int64, int](nil)
for rep := 0; rep < 2; rep++ {
// Push all the data into the stack, pop out every second
secs := []*item{}
secs := []*item[int64, int]{}
for i := 0; i < size; i++ {
stack.Push(data[i])
if i%2 == 0 {
secs = append(secs, stack.Pop().(*item))
secs = append(secs, stack.Pop().(*item[int64, int]))
}
}
rest := []*item{}
rest := []*item[int64, int]{}
for stack.Len() > 0 {
rest = append(rest, stack.Pop().(*item))
rest = append(rest, stack.Pop().(*item[int64, int]))
}
// Make sure the contents of the resulting slices are ok
for i := 0; i < size; i++ {
@@ -50,12 +50,12 @@ func TestSstack(t *testing.T) {
func TestSstackSort(t *testing.T) {
// Create some initial data
size := 16 * blockSize
data := make([]*item, size)
data := make([]*item[int64, int], size)
for i := 0; i < size; i++ {
data[i] = &item{rand.Int(), int64(i)}
data[i] = &item[int64, int]{rand.Int(), int64(i)}
}
// Push all the data into the stack
stack := newSstack(nil, false)
stack := newSstack[int64, int](nil)
for _, val := range data {
stack.Push(val)
}
@@ -72,18 +72,18 @@ func TestSstackSort(t *testing.T) {
func TestSstackReset(t *testing.T) {
// Create some initial data
size := 16 * blockSize
data := make([]*item, size)
data := make([]*item[int64, int], size)
for i := 0; i < size; i++ {
data[i] = &item{rand.Int(), rand.Int63()}
data[i] = &item[int64, int]{rand.Int(), rand.Int63()}
}
stack := newSstack(nil, false)
stack := newSstack[int64, int](nil)
for rep := 0; rep < 2; rep++ {
// Push all the data into the stack, pop out every second
secs := []*item{}
secs := []*item[int64, int]{}
for i := 0; i < size; i++ {
stack.Push(data[i])
if i%2 == 0 {
secs = append(secs, stack.Pop().(*item))
secs = append(secs, stack.Pop().(*item[int64, int]))
}
}
// Reset and verify both pulled and stack contents