Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Nov 4, 2024
1 parent 056026c commit f991aa8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
21 changes: 21 additions & 0 deletions erigon-lib/seg/decompress.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"os"
"path/filepath"
"sort"
"strconv"
"sync/atomic"
"time"
Expand Down Expand Up @@ -1064,3 +1065,23 @@ func (g *Getter) FastNext(buf []byte) ([]byte, uint64) {
g.dataBit = 0
return buf[:wordLen], postLoopPos
}

func (g *Getter) BinarySearch(fromPrefix []byte, count int, f func(i uint64) (offset uint64)) (foundOffset uint64) {
//n := item.src.decompressor.Count() / 2
foundItem := sort.Search(count, func(i int) bool {
offset := f(uint64(i))
g.Reset(offset)
if g.HasNext() {
key, _ := g.Next(nil)
fmt.Printf("bs: %x, %x\n", fromPrefix, key)
return bytes.Compare(fromPrefix, key) >= 0
}
return false
})
if foundItem < count {
fmt.Printf("[dbg] bs1 !ok, %x, %d\n", fromPrefix, f(uint64(foundItem)))
return f(uint64(foundItem))
}
fmt.Printf("[dbg] bs2 !ok, %x, %d\n", fromPrefix, 0)
return 0
}
14 changes: 2 additions & 12 deletions erigon-lib/state/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"math"
"path/filepath"
"regexp"
"sort"
"strconv"
"sync"
"time"
Expand Down Expand Up @@ -1366,17 +1365,8 @@ func (ht *HistoryRoTx) WalkAsOf(ctx context.Context, startTxNum uint64, from, to
var offset uint64
if len(from) > 0 {
n := item.src.decompressor.Count() / 2
found := sort.Search(n, func(i int) bool {
offset = idx.OrdinalLookup(uint64(i))
g.Reset(offset)
if g.HasNext() {
key, _ := g.Next(nil)
fmt.Printf("bs: %x, %x\n", from, key)
return bytes.Compare(from, key) >= 0
}
return false
})
if found < n {
found := item.getter.BinarySearch(from, n, idx.OrdinalLookup)
if int(found) < n {
fmt.Printf("[dbg] bs1 !ok, %x, %d\n", from, offset)
} else {
fmt.Printf("[dbg] bs2 !ok, %x, %d\n", from, offset)
Expand Down

0 comments on commit f991aa8

Please sign in to comment.