mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-29 07:07:16 +00:00
e1860348b2
* reverted minHeap at elias-fano merge * skip ef merge test for now
70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
package state
|
|
|
|
import (
|
|
"sort"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/recsplit/eliasfano32"
|
|
)
|
|
|
|
func Test_mergeEliasFano(t *testing.T) {
|
|
t.Skip()
|
|
|
|
firstList := []int{1, 298164, 298163, 13, 298160, 298159}
|
|
sort.Ints(firstList)
|
|
uniq := make(map[int]struct{})
|
|
|
|
first := eliasfano32.NewEliasFano(uint64(len(firstList)), uint64(firstList[len(firstList)-1]))
|
|
for _, v := range firstList {
|
|
uniq[v] = struct{}{}
|
|
first.AddOffset(uint64(v))
|
|
}
|
|
first.Build()
|
|
firstBytes := first.AppendBytes(nil)
|
|
|
|
fit := first.Iterator()
|
|
for fit.HasNext() {
|
|
v := fit.Next()
|
|
require.Contains(t, firstList, int(v))
|
|
}
|
|
|
|
secondList := []int{
|
|
1, 644951, 644995, 682653, 13,
|
|
644988, 644987, 644946, 644994,
|
|
644942, 644945, 644941, 644940,
|
|
644939, 644938, 644792, 644787}
|
|
sort.Ints(secondList)
|
|
second := eliasfano32.NewEliasFano(uint64(len(secondList)), uint64(secondList[len(secondList)-1]))
|
|
|
|
for _, v := range secondList {
|
|
second.AddOffset(uint64(v))
|
|
uniq[v] = struct{}{}
|
|
}
|
|
second.Build()
|
|
secondBytes := second.AppendBytes(nil)
|
|
|
|
sit := second.Iterator()
|
|
for sit.HasNext() {
|
|
v := sit.Next()
|
|
require.Contains(t, secondList, int(v))
|
|
}
|
|
|
|
menc, err := mergeEfs(firstBytes, secondBytes, nil)
|
|
require.NoError(t, err)
|
|
|
|
merged, _ := eliasfano32.ReadEliasFano(menc)
|
|
require.NoError(t, err)
|
|
require.EqualValues(t, len(uniq), merged.Count())
|
|
mergedLists := append(firstList, secondList...)
|
|
sort.Ints(mergedLists)
|
|
require.EqualValues(t, mergedLists[len(mergedLists)-1], merged.Max())
|
|
|
|
mit := merged.Iterator()
|
|
for mit.HasNext() {
|
|
v := mit.Next()
|
|
require.Contains(t, mergedLists, int(v))
|
|
}
|
|
}
|