Skip to content

Commit

Permalink
fix iterator in erase(). Fixes #47
Browse files Browse the repository at this point in the history
  • Loading branch information
rekola committed Feb 15, 2024
1 parent 5885a34 commit 4bfaec9
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions include/radix_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,24 +482,6 @@ namespace radix_cpp {
}
}
}
size_t get_depth() const noexcept { return depth_; }
const key_type & get_prefix_key() const noexcept { return prefix_key_; }
size_t get_ordinal() const noexcept { return ordinal_; }
size_t get_offset() const noexcept { return offset_; }
size_t get_hash() const noexcept { return hash_; }

void set_ptr(PayloadPtr ptr) { ptr_ = ptr; }

private:
void clear() {
ptr_ = nullptr;
depth_ = 0;
prefix_key_ = key_type{};
ordinal_ = 0;
offset_ = 0;
hash0_ = 0;
hash_ = 0;
}

Node * repair_and_get_node() {
auto node0 = table_->read_node(hash_, offset_);
Expand All @@ -522,6 +504,25 @@ namespace radix_cpp {
}
return node;
}

size_t get_depth() const noexcept { return depth_; }
const key_type & get_prefix_key() const noexcept { return prefix_key_; }
size_t get_ordinal() const noexcept { return ordinal_; }
size_t get_offset() const noexcept { return offset_; }
size_t get_hash() const noexcept { return hash_; }

void set_ptr(PayloadPtr ptr) { ptr_ = ptr; }

private:
void clear() {
ptr_ = nullptr;
depth_ = 0;
prefix_key_ = key_type{};
ordinal_ = 0;
offset_ = 0;
hash0_ = 0;
hash_ = 0;
}

TablePtr table_;
PayloadPtr ptr_;
Expand Down Expand Up @@ -710,7 +711,7 @@ namespace radix_cpp {
}

iterator erase(iterator pos) {
auto node = read_node(pos.get_hash(), pos.get_offset());
auto node = pos.repair_and_get_node();
if (!node->is_assigned() || !node->get_payload()) {
#ifdef DEBUG
std::cerr << "invalid parameter to erase()\n";
Expand Down Expand Up @@ -740,11 +741,9 @@ namespace radix_cpp {
pos.down();
}

#if 0
if (table_size_ > bucket_count && get_load_factor() < min_load_factor100) { // Check the load factor
resize(table_size_ >> 1);
}
#endif

return next_pos;
}
Expand Down

0 comments on commit 4bfaec9

Please sign in to comment.