summaryrefslogtreecommitdiff
path: root/lib/btrfs
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-02-03 19:50:35 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-04 20:53:23 -0700
commitef60daef395b20b67042c011f5b2a1131049e275 (patch)
treec70aa1661272e10883bbc57373cf00ab980ef336 /lib/btrfs
parent77f3c0d7cd21274d00984b72dfce05394d11bdd0 (diff)
rebuildmappings: Optimize the KMP search
Diffstat (limited to 'lib/btrfs')
-rw-r--r--lib/btrfs/btrfssum/sumrun.go20
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) {