From d28c1d4e8182ea54f5d68580944448d65c3f5d5e Mon Sep 17 00:00:00 2001 From: fusion32 Date: Sun, 18 May 2025 16:13:33 -0300 Subject: implement `priority_queue` --- src/vector.hh | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/vector.hh') diff --git a/src/vector.hh b/src/vector.hh index 5c59d2c..044ffe1 100644 --- a/src/vector.hh +++ b/src/vector.hh @@ -39,7 +39,9 @@ struct vector{ } } - T *operator(int index){ + // TODO(fusion): Probably missing some inlined destructor? + + T *at(int index){ // TODO(fusion): This is probably not the best way to achieve this. while(index < this->start){ @@ -56,11 +58,7 @@ struct vector{ // TODO(fusion): Do we actually need to swap elements here? I'm // assuming some non-trivial structures that would invoke their // destructors when `this->entry` gets deleted just below. - { - T tmp = entry[new_index]; - entry[new_index] = this->entry[old_index]; - this->entry[old_index] = tmp; - } + std::swap(entry[new_index], this->entry[old_index]); } if(this->entry != NULL){ @@ -83,11 +81,7 @@ struct vector{ int new_index = old_index; // TODO(fusion): Same as above. - { - T tmp = entry[new_index]; - entry[new_index] = this->entry[old_index]; - this->entry[old_index] = tmp; - } + std::swap(entry[new_index], this->entry[old_index]); } if(this->entry != NULL){ -- cgit v1.2.3