Skip to content

Commit 4360f55

Browse files
committed
Reuse math.
1 parent 47afd3c commit 4360f55

File tree

6 files changed

+9
-113
lines changed

6 files changed

+9
-113
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package xts
1+
package util
22

33
func abs(n int) int {
44
if n < 0 {
@@ -7,16 +7,16 @@ func abs(n int) int {
77
return n
88
}
99

10-
func gcd(m, n int) int {
10+
func GCD(m, n int) int {
1111
for n != 0 {
1212
m, n = n, m%n
1313
}
1414
return abs(m)
1515
}
1616

17-
func lcm(m, n int) int {
17+
func LCM(m, n int) int {
1818
if n == 0 {
1919
return 0
2020
}
21-
return abs(n) * (abs(m) / gcd(m, n))
21+
return abs(n) * (abs(m) / GCD(m, n))
2222
}

vfs/xts/math_test.go renamed to internal/util/math_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package xts
1+
package util
22

33
import (
44
"math"
@@ -46,7 +46,7 @@ func Test_gcd(t *testing.T) {
4646
}
4747
for _, tt := range tests {
4848
t.Run("", func(t *testing.T) {
49-
if got := gcd(tt.arg1, tt.arg2); got != tt.want {
49+
if got := GCD(tt.arg1, tt.arg2); got != tt.want {
5050
t.Errorf("gcd(%d, %d) = %d, want %d", tt.arg1, tt.arg2, got, tt.want)
5151
}
5252
})
@@ -74,7 +74,7 @@ func Test_lcm(t *testing.T) {
7474
}
7575
for _, tt := range tests {
7676
t.Run("", func(t *testing.T) {
77-
if got := lcm(tt.arg1, tt.arg2); got != tt.want {
77+
if got := LCM(tt.arg1, tt.arg2); got != tt.want {
7878
t.Errorf("lcm(%d, %d) = %d, want %d", tt.arg1, tt.arg2, got, tt.want)
7979
}
8080
})

vfs/adiantum/hbsh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (h *hbshFile) Truncate(size int64) error {
187187
}
188188

189189
func (h *hbshFile) SectorSize() int {
190-
return lcm(h.File.SectorSize(), blockSize)
190+
return util.LCM(h.File.SectorSize(), blockSize)
191191
}
192192

193193
func (h *hbshFile) DeviceCharacteristics() vfs.DeviceCharacteristic {

vfs/adiantum/math.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

vfs/adiantum/math_test.go

Lines changed: 0 additions & 82 deletions
This file was deleted.

vfs/xts/xts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (x *xtsFile) Truncate(size int64) error {
183183
}
184184

185185
func (x *xtsFile) SectorSize() int {
186-
return lcm(x.File.SectorSize(), sectorSize)
186+
return util.LCM(x.File.SectorSize(), sectorSize)
187187
}
188188

189189
func (x *xtsFile) DeviceCharacteristics() vfs.DeviceCharacteristic {

0 commit comments

Comments
 (0)