public static void blackbox(hole hole) { List <memoryitem> temp = memory.OrderBy(a => a.getstratingadd()).ToList(); memoryitem last_item; int st_add; int t_size; if (temp.Count > 0) { last_item = temp.Last(); t_size = last_item.size; st_add = last_item.getstratingadd(); if ((st_add + t_size < hole.starting_add)) { blackhole before = new blackhole(st_add + t_size, (hole.starting_add - st_add - t_size)); memory.Add(before); } } }
public static void inserthole(hole hole) { // check holes //if(hole.setstarting_add) foreach (var item in memory) { if (item.type == "s") { if ((item.starting_add + item.size <= hole.getstratingadd())) { //case 1 ; //el case de m3naha en el hole el gdeda htkon b3d el item ely ana wa2f feh fa akml itteration 3shan aro7 ll item el next //3shan hwa da el item el mohem continue; } else if ((item.starting_add <= hole.getstratingadd()) && (item.starting_add + item.size > hole.getstratingadd())) { //case 2.1 ; //remove the black hole and add the new blackhole and the new hole // two black hole one before the hole and one after //but we can use the black hole function to create these blackboxes //so we will delete only and add the hole int starting_add = item.starting_add; int size_temp = item.size; blackhole before = new blackhole(starting_add, (hole.starting_add - starting_add)); blackhole after = new blackhole(hole.starting_add + hole.size, starting_add + size_temp - hole.starting_add - hole.size); memory.Remove(item); memory.Add(hole); memory.Add(before); memory.Add(after); return; } else if ((item.starting_add <= hole.getstratingadd()) && (item.starting_add + item.size < hole.getstratingadd() + hole.size)) { //case 2.2; //hna el hole htb2a nosha fe black hole w el nos el tany either over lap with process or another hole ; //we are going tp ignore the hole inthose cases or we can fill the hole till the overlpping point } } else if (item.type == "p") { if ((item.starting_add + item.size <= hole.getstratingadd())) { //case 1 ; //el case de m3naha en el hole el gdeda htkon b3d el item ely ana wa2f feh fa akml itteration 3shan aro7 ll item el next //3shan hwa da el item el mohem continue; } else if ((item.starting_add <= hole.getstratingadd()) && (item.starting_add + item.size > hole.getstratingadd())) { //send error w break ; break; } else { //send error and break; break; } } else { if ((item.starting_add + item.size <= hole.getstratingadd())) { //case 1 ; //el case de m3naha en el hole el gdeda htkon b3d el item ely ana wa2f feh fa akml itteration 3shan aro7 ll item el next //3shan hwa da el item el mohem continue; } else if ((item.starting_add <= hole.getstratingadd()) && (item.starting_add + item.size >= hole.getstratingadd())) { //send error w break ; return; } else { //send error and break; return; } } } blackbox(hole); memory.Add(hole); concatenate(memory); }