use space to check if entry in a range has allocations while doing ring merge

This commit is contained in:
Murali Reddy committed 2019-06-07 18:12:35 +05:30
1 parent 5e69e8a7b4
commit 90ccc4a014
3 files changed
+30 -16

No files matched your search

+19 -1
View File
@@ -32,7 +32,25 @@ func ParseIP(s string) address.Address {
}
func merge(r1, r2 *Ring) error {
_, err := r1.Merge(*r2)
distance := func(start, end address.Address) address.Count {
if end > start {
return address.Count(end - start)
}
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
}
return false
}
_, err := r1.Merge(*r2, checkEntryHasAllocations)
return err
}