mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-11 21:49:13 +00:00
NPOT sectors.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
//go:build unix
|
||||
//go:build unix && !sqlite3_nosys
|
||||
|
||||
package util
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ func (h *hbshFile) Truncate(size int64) error {
|
||||
}
|
||||
|
||||
func (h *hbshFile) SectorSize() int {
|
||||
return max(h.File.SectorSize(), blockSize)
|
||||
return lcm(h.File.SectorSize(), blockSize)
|
||||
}
|
||||
|
||||
func (h *hbshFile) DeviceCharacteristics() vfs.DeviceCharacteristic {
|
||||
|
||||
22
vfs/adiantum/math.go
Normal file
22
vfs/adiantum/math.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package adiantum
|
||||
|
||||
func abs(n int) int {
|
||||
if n < 0 {
|
||||
return -n
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func gcd(m, n int) int {
|
||||
for n != 0 {
|
||||
m, n = n, m%n
|
||||
}
|
||||
return abs(m)
|
||||
}
|
||||
|
||||
func lcm(m, n int) int {
|
||||
if n == 0 {
|
||||
return 0
|
||||
}
|
||||
return abs(n) * (abs(m) / gcd(m, n))
|
||||
}
|
||||
82
vfs/adiantum/math_test.go
Normal file
82
vfs/adiantum/math_test.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package adiantum
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_abs(t *testing.T) {
|
||||
tests := []struct {
|
||||
arg int
|
||||
want int
|
||||
}{
|
||||
{0, 0},
|
||||
{1, 1},
|
||||
{-1, 1},
|
||||
{math.MaxInt, math.MaxInt},
|
||||
{math.MinInt, math.MinInt},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
if got := abs(tt.arg); got != tt.want {
|
||||
t.Errorf("abs(%d) = %d, want %d", tt.arg, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_gcd(t *testing.T) {
|
||||
tests := []struct {
|
||||
arg1 int
|
||||
arg2 int
|
||||
want int
|
||||
}{
|
||||
{0, 0, 0},
|
||||
{0, 1, 1},
|
||||
{1, 0, 1},
|
||||
{1, 1, 1},
|
||||
{2, 3, 1},
|
||||
{42, 56, 14},
|
||||
{48, -18, 6},
|
||||
{1e9, 1e9, 1e9},
|
||||
{1e9, -1e9, 1e9},
|
||||
{-1e9, -1e9, 1e9},
|
||||
{math.MaxInt, math.MaxInt, math.MaxInt},
|
||||
{math.MinInt, math.MinInt, math.MinInt},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
if got := gcd(tt.arg1, tt.arg2); got != tt.want {
|
||||
t.Errorf("gcd(%d, %d) = %d, want %d", tt.arg1, tt.arg2, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_lcm(t *testing.T) {
|
||||
tests := []struct {
|
||||
arg1 int
|
||||
arg2 int
|
||||
want int
|
||||
}{
|
||||
{0, 0, 0},
|
||||
{0, 1, 0},
|
||||
{1, 0, 0},
|
||||
{1, 1, 1},
|
||||
{2, 3, 6},
|
||||
{42, 56, 168},
|
||||
{48, -18, 144},
|
||||
{1e9, 1e9, 1e9},
|
||||
{1e9, -1e9, 1e9},
|
||||
{-1e9, -1e9, 1e9},
|
||||
{math.MaxInt, math.MaxInt, math.MaxInt},
|
||||
{math.MinInt, math.MinInt, math.MinInt},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run("", func(t *testing.T) {
|
||||
if got := lcm(tt.arg1, tt.arg2); got != tt.want {
|
||||
t.Errorf("lcm(%d, %d) = %d, want %d", tt.arg1, tt.arg2, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user