🐛 Account for file ids > 9

This commit is contained in:
Dan Jones 2024-12-09 14:34:01 -06:00
commit 495d50ba10
7 changed files with 40 additions and 37 deletions

View file

@ -2,18 +2,18 @@ package defrag
// Defrag performs an in-place sort of blocks.
// If an error occurs during processing, it will be returned. The slice may have been partially sorted.
func Defrag(blocks []byte) error {
func Defrag(blocks []int) error {
lastPulled := len(blocks)
lastPushed := -1
for block := 0; block < len(blocks); block++ {
if blocks[block] != '.' {
if blocks[block] != -1 {
continue
}
if lastPulled <= block {
break
}
for swap := lastPulled - 1; swap > lastPushed; swap-- {
if blocks[swap] == '.' {
if blocks[swap] == -1 {
continue
}
blocks[block], blocks[swap] = blocks[swap], blocks[block]