mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-04 01:54:28 +00:00
77eb94b53e
* Elias fano search and merge * Add first cut of search * Iterator and test * Changes in aggregator * Elias fano bitmap * Fix uncompress decompress * Print * Print * No print * Print * Print * Print * Change to AppendBytes * Print * Fix NextUncompressed * Remove print * Fix history search * Fix in history search * More tracing * More tracing * Fix * Print * Print key * More print * Print * No deletion for history records * Remove print * Fix * Fix * Fix test * Fix lint Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
/*
|
|
Copyright 2022 Erigon contributors
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package eliasfano32
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestEliasFano(t *testing.T) {
|
|
offsets := []uint64{1, 4, 6, 8, 10, 14, 16, 19, 22, 34, 37, 39, 41, 43, 48, 51, 54, 58, 62}
|
|
count := uint64(len(offsets))
|
|
maxOffset := offsets[0]
|
|
for _, offset := range offsets {
|
|
if offset > maxOffset {
|
|
maxOffset = offset
|
|
}
|
|
}
|
|
ef := NewEliasFano(count, maxOffset)
|
|
for _, offset := range offsets {
|
|
ef.AddOffset(offset)
|
|
}
|
|
ef.Build()
|
|
for i, offset := range offsets {
|
|
offset1 := ef.Get(uint64(i))
|
|
assert.Equal(t, offset, offset1, "offset")
|
|
}
|
|
v, ok := ef.Search(37)
|
|
assert.True(t, ok, "search1")
|
|
assert.Equal(t, uint64(37), v, "search1")
|
|
v, ok = ef.Search(0)
|
|
assert.True(t, ok, "search2")
|
|
assert.Equal(t, uint64(1), v, "search2")
|
|
_, ok = ef.Search(100)
|
|
assert.False(t, ok, "search3")
|
|
v, ok = ef.Search(11)
|
|
assert.True(t, ok, "search4")
|
|
assert.Equal(t, uint64(14), v, "search4")
|
|
}
|
|
|
|
func TestIterator(t *testing.T) {
|
|
offsets := []uint64{1, 4, 6, 8, 10, 14, 16, 19, 22, 34, 37, 39, 41, 43, 48, 51, 54, 58, 62}
|
|
count := uint64(len(offsets))
|
|
maxOffset := offsets[0]
|
|
for _, offset := range offsets {
|
|
if offset > maxOffset {
|
|
maxOffset = offset
|
|
}
|
|
}
|
|
ef := NewEliasFano(count, maxOffset)
|
|
for _, offset := range offsets {
|
|
ef.AddOffset(offset)
|
|
}
|
|
ef.Build()
|
|
efi := ef.Iterator()
|
|
i := 0
|
|
for efi.HasNext() {
|
|
assert.Equal(t, offsets[i], efi.Next(), "iter")
|
|
i++
|
|
}
|
|
}
|