mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-24 20:47:16 +00:00
5dbe1724be
* save progress * save progress * save progress * save progress * etl bimaps * etl bimaps * etl bimaps * etl bimaps * a * a * a * a * a * a * a * save progress * save progress * save progress * a * fix_race_condition_on_zstd_build * clean * clean * clean * clean * clean * go mod tidy * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * clean * fix corner case * commit every * call traces etl * call traces etl * call traces etl * return missed error * go mod tidy * go mod tidy * go mod tidy * rebase to master * remove trash * print full key if it has 8 leading zeroes
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package bitmapdb_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/RoaringBitmap/roaring"
|
|
"github.com/ledgerwatch/turbo-geth/ethdb/bitmapdb"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCutLeft(t *testing.T) {
|
|
bm := roaring.New()
|
|
for j := 0; j < 10_000; j += 20 {
|
|
bm.AddRange(uint64(j), uint64(j+10))
|
|
}
|
|
N := uint64(1024)
|
|
for bm.GetCardinality() > 0 {
|
|
lft := bitmapdb.CutLeft(bm, N)
|
|
lftSz := lft.GetSerializedSizeInBytes()
|
|
if bm.GetCardinality() > 0 {
|
|
require.True(t, lftSz > N-256 && lftSz < N+256)
|
|
} else {
|
|
require.True(t, lft.GetSerializedSizeInBytes() > 0)
|
|
require.True(t, lftSz < N+256)
|
|
}
|
|
}
|
|
|
|
bm = roaring.New()
|
|
for j := 0; j < 10_000; j += 20 {
|
|
bm.AddRange(uint64(j), uint64(j+10))
|
|
}
|
|
N = uint64(2048)
|
|
for bm.GetCardinality() > 0 {
|
|
lft := bitmapdb.CutLeft(bm, N)
|
|
lftSz := lft.GetSerializedSizeInBytes()
|
|
if bm.GetCardinality() > 0 {
|
|
require.True(t, lftSz > N-256 && lftSz < N+256)
|
|
} else {
|
|
require.True(t, lft.GetSerializedSizeInBytes() > 0)
|
|
require.True(t, lftSz < N+256)
|
|
}
|
|
}
|
|
|
|
bm = roaring.New()
|
|
bm.Add(1)
|
|
lft := bitmapdb.CutLeft(bm, N)
|
|
require.True(t, lft.GetSerializedSizeInBytes() > 0)
|
|
require.True(t, lft.GetCardinality() == 1)
|
|
require.True(t, bm.GetCardinality() == 0)
|
|
|
|
bm = roaring.New()
|
|
lft = bitmapdb.CutLeft(bm, N)
|
|
require.True(t, lft == nil)
|
|
require.True(t, bm.GetCardinality() == 0)
|
|
}
|