Handle range wrap-around when checking for allocations
Ring wraps around at zero but Space doesn't know about this, so we have to normalise ranges coming out of Ring. In turn we may need to split one range into two, across the end of the Ring.
This commit is contained in:
1 parent
9c09e36135
commit
d2f0287fa3
3 files changed
+26
-18
No files matched your search
+11
-9
@@ -38,19 +38,21 @@ func merge(r1, r2 *Ring) error {
|
||||
}
|
||||
return address.Count((r1.End - start) + (end - r1.Start))
|
||||
}
|
||||
checkEntryHasAllocations := func(r address.Range) bool {
|
||||
size := distance(r.Start, r.End)
|
||||
entry, found := r1.Entries.get(r.Start)
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
if entry.Free < size {
|
||||
return true
|
||||
check := func(rs []address.Range) bool {
|
||||
for _, r := range rs {
|
||||
size := distance(r.Start, r.End)
|
||||
entry, found := r1.Entries.get(r.Start)
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
if entry.Free < size {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
_, err := r1.Merge(*r2, checkEntryHasAllocations)
|
||||
_, err := r1.Merge(*r2, check)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user