/*@ requires \valid(ptr); @*/ void __remove_element (struct _block * ptr) { struct bittree * leaf_to_delete = __get_leaf_from_block (ptr); assert(leaf_to_delete->leaf == ptr); if(leaf_to_delete->father == NULL) // the leaf is the root __root = NULL; else { struct bittree * brother, * father; father = leaf_to_delete->father; brother = (leaf_to_delete == father->left) ? father->right : father->left; assert(brother != NULL); // copying all brother's fields into the father's father->is_leaf = brother->is_leaf; father->addr = brother->addr; father->mask = brother->mask; father->left = brother->left; father->right = brother->right; father->leaf = brother->leaf; if(!brother->is_leaf) { brother->left->father = father; brother->right->father = father; } free(brother); /* necessary ? -- begin */ if(father->father != NULL) { father->father->mask = mask(father->father->left->addr & father->father->left->mask, father->father->right->addr & father->father->right->mask); } /* necessary ? -- end */ } free(leaf_to_delete); }
void __remove_element (__metadata_unit * ptr) { struct bittree * leaf_to_delete = __get_leaf_from_block (ptr); assert(leaf_to_delete->leaf == ptr); if(leaf_to_delete->father == NULL) __root = NULL; else { struct bittree * brother, * father; father = leaf_to_delete->father; brother = (leaf_to_delete == father->left) ? father->right : father->left; assert(brother != NULL); father->is_leaf = brother->is_leaf; father->addr = brother->addr; father->mask = brother->mask; father->left = brother->left; father->right = brother->right; father->leaf = brother->leaf; if(!brother->is_leaf) { brother->left->father = father; brother->right->father = father; } free(brother); if(father->father != NULL) { father->father->mask = mask(father->father->left->addr & father->father->left->mask, father->father->right->addr & father->father->right->mask); } } free(leaf_to_delete); }