// Same preconditions as 'segregate' // Post: !empty() void add_block(void * const block, const size_type nsz, const size_type npartition_sz) { // Segregate this block and merge its free list into the // free list referred to by "first" first = segregate(block, nsz, npartition_sz, first); }
bool ICF::forEachGroup(std::vector<SectionChunk *> &Chunks, Comparator Eq) { bool R = false; for (auto It = Chunks.begin(), End = Chunks.end(); It != End;) { SectionChunk *Head = *It; auto Bound = std::find_if(It + 1, End, [&](SectionChunk *SC) { return SC->GroupID != Head->GroupID; }); if (segregate(It, Bound, Eq)) R = true; It = Bound; } return R; }
// Same preconditions as 'segregate' // Post: !empty() void add_ordered_block(void * const block, const size_type nsz, const size_type npartition_sz) { // This (slower) version of add_block segregates the // block and merges its free list into our free list // in the proper order // Find where "block" would go in the free list void * const loc = find_prev(block); // Place either at beginning or in middle/end if (loc == 0) add_block(block, nsz, npartition_sz); else nextof(loc) = segregate(block, nsz, npartition_sz, nextof(loc)); }
int main() { head=insert(head,11); insert(head,3); insert(head,4); insert(head,6); insert(head,8); insert(head,10); insert(head,12); insert(head,9); display(head); segregate(&head); display(head); return 0; }