diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-03 19:50:35 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-04 20:53:23 -0700 |
commit | ef60daef395b20b67042c011f5b2a1131049e275 (patch) | |
tree | c70aa1661272e10883bbc57373cf00ab980ef336 /lib/btrfs | |
parent | 77f3c0d7cd21274d00984b72dfce05394d11bdd0 (diff) |
rebuildmappings: Optimize the KMP search
Diffstat (limited to 'lib/btrfs')
-rw-r--r-- | lib/btrfs/btrfssum/sumrun.go | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/btrfs/btrfssum/sumrun.go b/lib/btrfs/btrfssum/sumrun.go index 1000e7a..bc2db3f 100644 --- a/lib/btrfs/btrfssum/sumrun.go +++ b/lib/btrfs/btrfssum/sumrun.go @@ -6,9 +6,9 @@ package btrfssum import ( "context" - "io" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol" + "git.lukeshu.com/btrfs-progs-ng/lib/diskio" ) type SumRun[Addr btrfsvol.IntAddr[Addr]] struct { @@ -20,21 +20,21 @@ type SumRun[Addr btrfsvol.IntAddr[Addr]] struct { Sums ShortSum } -func (run SumRun[Addr]) NumSums() int { +var _ diskio.Sequence[int, ShortSum] = SumRun[btrfsvol.LogicalAddr]{} + +// SeqLen implements diskio.Sequence[int, ShortSum]. +func (run SumRun[Addr]) SeqLen() int { return len(run.Sums) / run.ChecksumSize } func (run SumRun[Addr]) Size() btrfsvol.AddrDelta { - return btrfsvol.AddrDelta(run.NumSums()) * BlockSize + return btrfsvol.AddrDelta(run.SeqLen()) * BlockSize } -// Get implements diskio.Sequence[int, ShortSum] -func (run SumRun[Addr]) Get(sumIdx int64) (ShortSum, error) { - if sumIdx < 0 || int(sumIdx) >= run.NumSums() { - return "", io.EOF - } - off := int(sumIdx) * run.ChecksumSize - return run.Sums[off : off+run.ChecksumSize], nil +// SeqGet implements diskio.Sequence[int, ShortSum]. +func (run SumRun[Addr]) SeqGet(sumIdx int) ShortSum { + off := sumIdx * run.ChecksumSize + return run.Sums[off : off+run.ChecksumSize] } func (run SumRun[Addr]) SumForAddr(addr Addr) (ShortSum, bool) { |