public VMFreeList(VMFreeListRegion region) { List = new LinkedList <VMFreeListRegion>(); if (region.a != region.b) { List.AddFirst(region); } }
public void Subtract(VMFreeListRegion region) { var elem = List.First; while (elem != null) { var part = elem.Value; var next = elem.Next; if (!(region.a >= part.b || region.b <= part.a)) { if (part.a >= region.a && region.b < part.b) { //erases starting from left part.a = region.b; if (part.a == part.b) { List.Remove(elem); } } else if (region.b >= part.b && region.a > part.a) { //erases starting from right part.b = region.a; if (part.a == part.b) { List.Remove(elem); } } else if (region.a <= part.a && region.b >= part.b) { //region entirely erases part List.Remove(elem); } else if (region.a > part.a && region.b < part.b) { //region internally erases part (result is two) var temp = part.b; part.b = region.a; List.AddAfter(elem, new VMFreeListRegion(region.b, temp)); } } elem = next; } }
public void Subtract(VMFreeListRegion region) { var elem = List.First; while (elem != null) { var part = elem.Value; var next = elem.Next; if (!(region.a >= part.b || region.b <= part.a)) { if (part.a >= region.a && region.b < part.b) { //erases starting from left part.a = region.b; if (part.a == part.b) List.Remove(elem); } else if (region.b >= part.b && region.a > part.a) { //erases starting from right part.b = region.a; if (part.a == part.b) List.Remove(elem); } else if (region.a <= part.a && region.b >= part.b) { //region entirely erases part List.Remove(elem); } else if (region.a > part.a && region.b < part.b) { //region internally erases part (result is two) var temp = part.b; part.b = region.a; List.AddAfter(elem, new VMFreeListRegion(region.b, temp)); } } elem = next; } }
public VMFreeList(VMFreeListRegion region) { List = new LinkedList<VMFreeListRegion>(); if (region.a != region.b) List.AddFirst(region); }