Skip to content
Snippets Groups Projects
Commit c847ece0 authored by Kostyantyn Vorobyov's avatar Kostyantyn Vorobyov
Browse files

Change bittree terminology from father-son-brother to

parent-child-sibling as the latter one is more common
parent e3c9065a
No related branches found
No related tags found
No related merge requests found
...@@ -101,7 +101,7 @@ static const int Tneq[] = ...@@ -101,7 +101,7 @@ static const int Tneq[] =
static struct bittree { static struct bittree {
_Bool is_leaf; _Bool is_leaf;
size_t addr, mask; size_t addr, mask;
struct bittree * left, * right, * father; struct bittree * left, * right, * parent;
bt_block * leaf; bt_block * leaf;
} * bt_root = NULL; } * bt_root = NULL;
...@@ -163,9 +163,9 @@ static struct bittree * __get_leaf_from_block (bt_block * ptr) { ...@@ -163,9 +163,9 @@ static struct bittree * __get_leaf_from_block (bt_block * ptr) {
while(!curr->is_leaf) { while(!curr->is_leaf) {
// the prefix is consistent // the prefix is consistent
DASSERT((curr->addr & curr->mask) == (ptr->ptr & curr->mask)); DASSERT((curr->addr & curr->mask) == (ptr->ptr & curr->mask));
// two sons // two children
DASSERT(curr->left != NULL && curr->right != NULL); DASSERT(curr->left != NULL && curr->right != NULL);
// the prefix of one son is consistent // the prefix of one child is consistent
if((curr->right->addr & curr->right->mask) if((curr->right->addr & curr->right->mask)
== (ptr->ptr & curr->right->mask)) == (ptr->ptr & curr->right->mask))
curr = curr->right; curr = curr->right;
...@@ -189,32 +189,32 @@ static void bt_remove (bt_block * ptr) { ...@@ -189,32 +189,32 @@ static void bt_remove (bt_block * ptr) {
struct bittree * leaf_to_delete = __get_leaf_from_block (ptr); struct bittree * leaf_to_delete = __get_leaf_from_block (ptr);
DASSERT(leaf_to_delete->leaf == ptr); DASSERT(leaf_to_delete->leaf == ptr);
if(leaf_to_delete->father == NULL) if(leaf_to_delete->parent == NULL)
// the leaf is the root // the leaf is the root
bt_root = NULL; bt_root = NULL;
else { else {
struct bittree * brother, * father; struct bittree * sibling, * parent;
father = leaf_to_delete->father; parent = leaf_to_delete->parent;
brother = (leaf_to_delete == father->left) ? father->right : father->left; sibling = (leaf_to_delete == parent->left) ? parent->right : parent->left;
DASSERT(brother != NULL); DASSERT(sibling != NULL);
// copying all brother's fields into the father's // copying all sibling's fields into the parent's
father->is_leaf = brother->is_leaf; parent->is_leaf = sibling->is_leaf;
father->addr = brother->addr; parent->addr = sibling->addr;
father->mask = brother->mask; parent->mask = sibling->mask;
father->left = brother->left; parent->left = sibling->left;
father->right = brother->right; parent->right = sibling->right;
father->leaf = brother->leaf; parent->leaf = sibling->leaf;
if(!brother->is_leaf) { if(!sibling->is_leaf) {
brother->left->father = father; sibling->left->parent = parent;
brother->right->father = father; sibling->right->parent = parent;
} }
native_free(brother); native_free(sibling);
/* necessary ? -- begin */ /* necessary ? -- begin */
if(father->father != NULL) { if(parent->parent != NULL) {
father->father->mask = mask(father->father->left->addr parent->parent->mask = mask(parent->parent->left->addr
& father->father->left->mask, & parent->parent->left->mask,
father->father->right->addr parent->parent->right->addr
& father->father->right->mask); & parent->parent->right->mask);
} }
/* necessary ? -- end */ /* necessary ? -- end */
} }
...@@ -223,7 +223,7 @@ static void bt_remove (bt_block * ptr) { ...@@ -223,7 +223,7 @@ static void bt_remove (bt_block * ptr) {
/* called from bt_insert */ /* called from bt_insert */
/* the returned node will be the brother of the soon to be added node */ /* the returned node will be the sibling of the soon to be added node */
/*@ requires \valid(ptr); /*@ requires \valid(ptr);
@ requires \valid(bt_root); @ requires \valid(bt_root);
@ assigns \nothing; @ assigns \nothing;
...@@ -264,54 +264,54 @@ static void bt_insert (bt_block * ptr) { ...@@ -264,54 +264,54 @@ static void bt_insert (bt_block * ptr) {
new_leaf->mask = Tmasks[WORDBITS]; /* ~0ul */ new_leaf->mask = Tmasks[WORDBITS]; /* ~0ul */
new_leaf->left = NULL; new_leaf->left = NULL;
new_leaf->right = NULL; new_leaf->right = NULL;
new_leaf->father = NULL; new_leaf->parent = NULL;
new_leaf->leaf = ptr; new_leaf->leaf = ptr;
if(bt_root == NULL) if(bt_root == NULL)
bt_root = new_leaf; bt_root = new_leaf;
else { else {
struct bittree * brother = __most_similar_node (ptr), * father, * aux; struct bittree * sibling = __most_similar_node (ptr), * parent, * aux;
DASSERT(brother != NULL); DASSERT(sibling != NULL);
father = native_malloc(sizeof(struct bittree)); parent = native_malloc(sizeof(struct bittree));
DASSERT(father != NULL); DASSERT(parent != NULL);
father->is_leaf = false; parent->is_leaf = false;
father->addr = brother->addr & new_leaf->addr; parent->addr = sibling->addr & new_leaf->addr;
/*father->mask = mask(brother->addr & brother->mask, ptr->ptr);*/ /*parent->mask = mask(sibling->addr & sibling->mask, ptr->ptr);*/
father->leaf = NULL; parent->leaf = NULL;
if(new_leaf->addr <= brother->addr) { if(new_leaf->addr <= sibling->addr) {
father->left = new_leaf; parent->left = new_leaf;
father->right = brother; parent->right = sibling;
} else { } else {
father->left = brother; parent->left = sibling;
father->right = new_leaf; parent->right = new_leaf;
} }
new_leaf->father = father; new_leaf->parent = parent;
if(brother == bt_root) { if(sibling == bt_root) {
father->father = NULL; parent->parent = NULL;
father->mask = mask(brother->addr & brother->mask, ptr->ptr); parent->mask = mask(sibling->addr & sibling->mask, ptr->ptr);
bt_root = father; bt_root = parent;
} else { } else {
if (brother->father->left == brother) if (sibling->parent->left == sibling)
brother->father->left = father; sibling->parent->left = parent;
else else
brother->father->right = father; sibling->parent->right = parent;
father->father = brother->father; parent->parent = sibling->parent;
/* necessary ? -- begin */ /* necessary ? -- begin */
aux = father; aux = parent;
aux->mask = mask(aux->left->addr & aux->left->mask, aux->mask = mask(aux->left->addr & aux->left->mask,
aux->right->addr & aux->right->mask); aux->right->addr & aux->right->mask);
/* necessary ? -- end */ /* necessary ? -- end */
} }
brother->father = father; sibling->parent = parent;
if(!brother->is_leaf) if(!sibling->is_leaf)
brother->mask = mask(brother->left->addr & brother->left->mask, sibling->mask = mask(sibling->left->addr & sibling->left->mask,
brother->right->addr & brother->right->mask); sibling->right->addr & sibling->right->mask);
DASSERT((father->left == brother && father->right == new_leaf) DASSERT((parent->left == sibling && parent->right == new_leaf)
|| (father->left == new_leaf && father->right == brother)); || (parent->left == new_leaf && parent->right == sibling));
} }
} }
...@@ -331,9 +331,9 @@ static bt_block * bt_lookup (void * ptr) { ...@@ -331,9 +331,9 @@ static bt_block * bt_lookup (void * ptr) {
while(!tmp->is_leaf) { while(!tmp->is_leaf) {
// if the ptr we are looking for does not share the prefix of tmp // if the ptr we are looking for does not share the prefix of tmp
if((tmp->addr & tmp->mask) != ((size_t)ptr & tmp->mask)) return NULL; if((tmp->addr & tmp->mask) != ((size_t)ptr & tmp->mask)) return NULL;
// two sons // two children
DASSERT(tmp->left != NULL && tmp->right != NULL); DASSERT(tmp->left != NULL && tmp->right != NULL);
// the prefix of one son is consistent // the prefix of one child is consistent
if((tmp->right->addr & tmp->right->mask) if((tmp->right->addr & tmp->right->mask)
== ((size_t)ptr & tmp->right->mask)) == ((size_t)ptr & tmp->right->mask))
tmp = tmp->right; tmp = tmp->right;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment