Skip to content

Commit

Permalink
Merge pull request #17 from coopsdev/fix-emplace
Browse files Browse the repository at this point in the history
fix emplace - only allocate object if insertable
  • Loading branch information
cooperlarson committed Aug 6, 2024
2 parents 6a04e7c + cceb10d commit 25c1e81
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Pkg(ConanFile):
name = "bpd"
version = "0.2.7"
version = "0.2.8"
license = "MIT"
author = "Cooper Larson | cooper.larson1@gmail.com"
url = ""
Expand Down
10 changes: 8 additions & 2 deletions include/BoundedPriorityDeque.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,13 @@ class BoundedPriorityDequeBase {
* @param key The bounding key value
* @param value The data held by the bounding pair.
*/
void emplace(K key, const V& value) { push({ key, value }); }
void emplace(K key, const V& value) {
if (_size == _k) {
if (compare(key, _buffer[_tail].key)) _popBottom();
else return;
}
insert({ key, value });
}

/**
* @brief Inserts an element into the vector.
Expand All @@ -270,7 +276,7 @@ class BoundedPriorityDequeBase {
*/
void push(const BoundingPair<K, V>& element) {
if (_size == _k) {
if (compare(element.key, _buffer[_tail].key)) popBottom();
if (compare(element.key, _buffer[_tail].key)) _popBottom();
else return;
}
insert(element);
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project('bpd', 'cpp',
version : '0.2.7',
version : '0.2.8',
default_options : ['warning_level=3', 'cpp_std=c++23', 'optimization=3', 'buildtype=release'])

source_root = meson.source_root()
Expand Down

0 comments on commit 25c1e81

Please sign in to comment.