Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
jere8184 committed Nov 8, 2024
1 parent 8f7c145 commit 8df70b3
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions libopenage/datastructure/pairing_heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class PairingHeapNode{
* by comparing `this` with `node`.
* The new root is returned, it has the other node as child.
*/
this_type* link_with(this_type* node) {
this_type* link_with(this_type* const node) {
this_type* new_root;
this_type* new_child;

Expand Down Expand Up @@ -179,10 +179,10 @@ class PairingHeapNode{
}

private:
this_type* child;
this_type* prev_sibling;
this_type* next_sibling;
this_type* parent; // for decrease-key and delete
this_type* child = nullptr;
this_type* prev_sibling = nullptr;
this_type* next_sibling = nullptr;
this_type* parent = nullptr; // for decrease-key and delete
};


Expand All @@ -205,7 +205,10 @@ class PairingHeap final {
root_node(nullptr) {
}

~PairingHeap() = default;
~PairingHeap()
{
this->clear();
};

/**
* adds the given item to the heap.
Expand Down Expand Up @@ -246,9 +249,9 @@ class PairingHeap final {
*
* O(pop_node)
*/
std::shared_ptr<heapnode_t> unlink_node(const element_t &node) { //how can we garuntee poped node deleted, without use of shared ptr, or making this function private?
void unlink_node(const element_t &node) { //how can we garuntee poped node deleted, without use of shared ptr, or making this function private?
if (node == this->root_node) {
return std::shared_ptr<heapnode_t>(this->pop_node());
this->pop_node();
}
else {
node->loosen();
Expand All @@ -263,7 +266,6 @@ class PairingHeap final {
if (new_root != nullptr) {
this->root_insert(new_root);
}
return std::shared_ptr<heapnode_t>(node);
}
}

Expand Down Expand Up @@ -312,8 +314,7 @@ class PairingHeap final {
*/
void update(const element_t &node) {
if (node != this->root_node) [[likely]] {
auto ptr = this->unlink_node(node);
ptr = nullptr;
this->unlink_node(node);
this->push_node(node);
}
else {
Expand Down

0 comments on commit 8df70b3

Please sign in to comment.