Skip to content

Commit

Permalink
Minor code changes for better readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-shekhar committed Oct 15, 2024
1 parent 91d692d commit 7689ac5
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions hhds/tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class __attribute__((packed, aligned(64))) Tree_pointers {
Tree_pos last_child_l : CHUNK_BITS;

// Track number of occupied short delta pointers
unsigned short num_occupied : CHUNK_SHIFT;
unsigned short num_short_del_occ : CHUNK_SHIFT;

// Short (delta) child pointers
__int128 first_child_s;
Expand Down Expand Up @@ -108,15 +108,15 @@ class __attribute__((packed, aligned(64))) Tree_pointers {
: parent(INVALID),
next_sibling(INVALID), prev_sibling(INVALID),
first_child_l(INVALID), last_child_l(INVALID),
num_occupied(0),
num_short_del_occ(0),
first_child_s(INVALID), last_child_s(INVALID) {}

/* PARAM CONSTRUCTOR */
Tree_pointers(Tree_pos p)
: parent(p),
next_sibling(INVALID), prev_sibling(INVALID),
first_child_l(INVALID), last_child_l(INVALID),
num_occupied(0),
num_short_del_occ(0),
first_child_s(INVALID), last_child_s(INVALID) {}

// Getters
Expand All @@ -135,7 +135,7 @@ class __attribute__((packed, aligned(64))) Tree_pointers {
}

// Getter for num_occ
unsigned short get_num_occupied() const { return num_occupied; }
unsigned short get_num_short_del_occ() const { return num_short_del_occ; }

// Setters
void set_parent(Tree_pos p) { parent = p; }
Expand All @@ -152,9 +152,9 @@ class __attribute__((packed, aligned(64))) Tree_pointers {
_set_last_child_s(index, lcs);
}

// Setter for num_occ
void set_num_occupied(unsigned short num) {
num_occupied = num;
// Setter for num_short_del_occ
void set_num_short_del_occ(unsigned short num) {
num_short_del_occ = num;
}

// Operators
Expand Down Expand Up @@ -188,7 +188,7 @@ class tree {
}

inline bool _contains_data(const Tree_pos &idx) const noexcept {
return (pointers_stack[idx >> CHUNK_SHIFT].get_num_occupied() >= (idx & CHUNK_MASK));
return (pointers_stack[idx >> CHUNK_SHIFT].get_num_short_del_occ() >= (idx & CHUNK_MASK));
// return (idx < data_stack.size() && data_stack[idx].has_value());
}

Expand Down Expand Up @@ -243,7 +243,7 @@ class tree {
}

Tree_pos _try_fit_child_ptr(const Tree_pos &parent_id, const Tree_pos &child_id) {
I(_check_idx_exists(parent_id), "First parent_id index out of range");
I(_check_idx_exists(parent_id), "parent_id index out of range");
I(_check_idx_exists(child_id), "child_id index out of range");

/* BASE CASE OF THE RECURSION */
Expand Down Expand Up @@ -312,7 +312,7 @@ class tree {
}
}
// Decrement the number of occupied slots in the chunk
pointers_stack[parent_chunk_id].set_num_occupied(parent_chunk_offset - 1);
pointers_stack[parent_chunk_id].set_num_short_del_occ(parent_chunk_offset - 1);

// Try fitting the last chunk here in the grandparent. Recurse.
const auto my_new_parent = _try_fit_child_ptr(grandparent_id,
Expand Down Expand Up @@ -396,7 +396,7 @@ class tree {
std::cout << "Last Child: " << pointers_stack[i].get_last_child_l() << " ";
std::cout << "Next Sibling: " << pointers_stack[i].get_next_sibling() << " ";
std::cout << "Prev Sibling: " << pointers_stack[i].get_prev_sibling() << " ";
std::cout << "Num Occ: " << pointers_stack[i].get_num_occupied() << std::endl;
std::cout << "Num Occ: " << pointers_stack[i].get_num_short_del_occ() << std::endl;
std::cout << std::endl;
}

Expand Down Expand Up @@ -909,7 +909,7 @@ Tree_pos tree<X>::get_last_child(const Tree_pos& parent_index) const {

return (child_chunk_id == INVALID) ? (static_cast<Tree_pos>(INVALID))
: (static_cast<Tree_pos>((child_chunk_id << CHUNK_SHIFT)
+ pointers_stack[child_chunk_id].get_num_occupied()));
+ pointers_stack[child_chunk_id].get_num_short_del_occ()));
}

/**
Expand Down Expand Up @@ -965,7 +965,7 @@ bool tree<X>::is_last_child(const Tree_pos& self_index) const {
return false;
}

return pointers_stack[self_chunk_id].get_num_occupied() == self_chunk_offset;
return pointers_stack[self_chunk_id].get_num_short_del_occ() == self_chunk_offset;

// Now, to be the last child, all entries after this should be invalid
// for (short offset = self_chunk_offset; offset < NUM_SHORT_DEL; offset++) {
Expand Down Expand Up @@ -1061,15 +1061,7 @@ Tree_pos tree<X>::get_sibling_prev(const Tree_pos& sibling_id) const {
// Find the last occupied in the prev sibling chunk
return (prev_sibling == INVALID) ? INVALID
: static_cast<Tree_pos>((prev_sibling << CHUNK_SHIFT)
+ pointers_stack[prev_sibling].get_num_occupied());
// // TODOTODO
// if (prev_sibling != INVALID) {
// for (short offset = NUM_SHORT_DEL - 1; offset >= 0; offset--) {
// if (_contains_data(prev_sibling + offset)) {
// return static_cast<Tree_pos>(prev_sibling + offset);
// }
// }
// }
+ pointers_stack[prev_sibling].get_num_short_del_occ());
}

/**
Expand Down Expand Up @@ -1111,7 +1103,7 @@ Tree_pos tree<X>::append_sibling(const Tree_pos& sibling_id, const X& data) {
}

// Increment the number of occupied slots in the sibling chunk
pointers_stack[new_sib >> CHUNK_SHIFT].set_num_occupied(
pointers_stack[new_sib >> CHUNK_SHIFT].set_num_short_del_occ(
((unsigned)new_sib & CHUNK_MASK)
);

Expand Down Expand Up @@ -1186,7 +1178,7 @@ Tree_pos tree<X>::add_root(const X& data) {
pointers_stack.emplace_back();

// Set num occupied to 1
// pointers_stack[ROOT].set_num_occupied(0);
// pointers_stack[ROOT].set_num_short_del_occ(0);

return (data_stack.size() - CHUNK_SIZE);
}
Expand Down Expand Up @@ -1220,7 +1212,7 @@ Tree_pos tree<X>::add_child(const Tree_pos& parent_index, const X& data) {
pointers_stack[child_chunk_id].set_parent(new_parent_id);

// Set num occupied to 0
pointers_stack[child_chunk_id].set_num_occupied(0);
pointers_stack[child_chunk_id].set_num_short_del_occ(0);

return child_chunk_id << CHUNK_SHIFT;
}
Expand Down

0 comments on commit 7689ac5

Please sign in to comment.