summaryrefslogtreecommitdiff
path: root/pkg/btrfs/internal/addr.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-06-26 15:53:49 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-06-26 15:53:49 -0600
commit6a1b5c780b8fbb9ca0285286036096960458d4e6 (patch)
treed25b258039bfcdea66fbdfd698431d2673e520ec /pkg/btrfs/internal/addr.go
parentfce6934cf76f4dfb04ea6eef1e2cd55c172beb1b (diff)
Add an AddrDelta type for safer arithmentic
Diffstat (limited to 'pkg/btrfs/internal/addr.go')
-rw-r--r--pkg/btrfs/internal/addr.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/pkg/btrfs/internal/addr.go b/pkg/btrfs/internal/addr.go
index 7067982..a3f41ed 100644
--- a/pkg/btrfs/internal/addr.go
+++ b/pkg/btrfs/internal/addr.go
@@ -9,6 +9,7 @@ import (
type (
PhysicalAddr int64
LogicalAddr int64
+ AddrDelta int64
)
func formatAddr(addr int64, f fmt.State, verb rune) {
@@ -23,3 +24,10 @@ func formatAddr(addr int64, f fmt.State, verb rune) {
func (a PhysicalAddr) Format(f fmt.State, verb rune) { formatAddr(int64(a), f, verb) }
func (a LogicalAddr) Format(f fmt.State, verb rune) { formatAddr(int64(a), f, verb) }
+func (d AddrDelta) Format(f fmt.State, verb rune) { formatAddr(int64(d), f, verb) }
+
+func (a PhysicalAddr) Sub(b PhysicalAddr) AddrDelta { return AddrDelta(a - b) }
+func (a LogicalAddr) Sub(b LogicalAddr) AddrDelta { return AddrDelta(a - b) }
+
+func (a PhysicalAddr) Add(b AddrDelta) PhysicalAddr { return a + PhysicalAddr(b) }
+func (a LogicalAddr) Add(b AddrDelta) LogicalAddr { return a + LogicalAddr(b) }