add {heap}.IsEmpty() and use it to empty the block during write()

This commit is contained in:
onyx-and-iris 2024-12-19 20:32:42 +00:00
parent 52541e7ca7
commit abf7abf3ea
2 changed files with 5 additions and 1 deletions

View File

@ -124,7 +124,7 @@ func (d *disk) write() {
allBlocks = append(allBlocks, d.fileblocks...)
for i := 0; i < numEmptyBlocks; i++ {
for range d.emptyblocks[i].Len() {
for !d.emptyblocks[i].IsEmpty() {
allBlocks = append(allBlocks, heap.Pop(&d.emptyblocks[i]).(*block))
}
}

View File

@ -25,3 +25,7 @@ func (h *minHeap) Pop() interface{} {
*h = old[:n-1]
return x
}
func (h *minHeap) IsEmpty() bool {
return h.Len() == 0
}