🐛 Account for file ids > 9
This commit is contained in:
parent
a495a2ef1a
commit
495d50ba10
7 changed files with 40 additions and 37 deletions
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue