From f3ec829f8c781109ff9374c2cba8b5b130e9a30e Mon Sep 17 00:00:00 2001 From: Ricardo Antunes Date: Sun, 8 Oct 2023 16:50:55 +0100 Subject: [PATCH] style(memory): use standard names in UnorderedBimap --- .../cubos/core/memory/unordered_bimap.hpp | 20 +++---- core/tests/memory/unordered_bimap.cpp | 52 +++++++++---------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/core/include/cubos/core/memory/unordered_bimap.hpp b/core/include/cubos/core/memory/unordered_bimap.hpp index 29ef094fd..4d6b2c8fc 100644 --- a/core/include/cubos/core/memory/unordered_bimap.hpp +++ b/core/include/cubos/core/memory/unordered_bimap.hpp @@ -24,7 +24,7 @@ namespace cubos::core::memory /// @note If any of the values already exists, the old entries with them are removed. /// @param left Left value. /// @param right Right value. - void add(L left, R right) + void insert(L left, R right) { auto leftIt = mLeftToRight.find(left); if (leftIt != mLeftToRight.end()) @@ -45,7 +45,7 @@ namespace cubos::core::memory /// @brief Removes the entry associated to the given left value. /// @param left Left value. /// @return Whether the entry was removed. - bool removeLeft(const L& left) + bool eraseLeft(const L& left) { auto it = mLeftToRight.find(left); if (it == mLeftToRight.end()) @@ -61,7 +61,7 @@ namespace cubos::core::memory /// @brief Removes the entry associated to the given right value. /// @param right Right value. /// @return Whether the entry was removed. - bool removeRight(const R& right) + bool eraseRight(const R& right) { auto it = mRightToLeft.find(right); if (it == mRightToLeft.end()) @@ -78,7 +78,7 @@ namespace cubos::core::memory /// @param left Left value. /// @param right Right value. /// @return Whether the map has the entry. - bool has(const L& left, const R& right) const + bool contains(const L& left, const R& right) const { auto it = mLeftToRight.find(left); if (it == mLeftToRight.end()) @@ -91,24 +91,24 @@ namespace cubos::core::memory /// @brief Checks if the map contains the given left value. /// @param left Left value. /// @return Whether the map contains the value. - bool hasLeft(const L& left) const + bool containsLeft(const L& left) const { - return mLeftToRight.find(left) != mLeftToRight.end(); + return mLeftToRight.contains(left); } /// @brief Checks if the map contains the given right value. /// @param right Right value. /// @return Whether the map contains the value. - bool hasRight(const R& right) const + bool containsRight(const R& right) const { - return mRightToLeft.find(right) != mRightToLeft.end(); + return mRightToLeft.contains(right); } /// @brief Gets the right value associated to the given left value. /// @note Aborts if the left value isn't stored. /// @param left Left value. /// @return Right value. - const R& getRight(const L& left) const + const R& atRight(const L& left) const { return mLeftToRight.at(left); } @@ -117,7 +117,7 @@ namespace cubos::core::memory /// @note Aborts if the right value isn't stored. /// @param right Right value. /// @return Left value. - const L& getLeft(const R& right) const + const L& atLeft(const R& right) const { return mRightToLeft.at(right); } diff --git a/core/tests/memory/unordered_bimap.cpp b/core/tests/memory/unordered_bimap.cpp index 8391fbc05..1e31f87b7 100644 --- a/core/tests/memory/unordered_bimap.cpp +++ b/core/tests/memory/unordered_bimap.cpp @@ -14,49 +14,49 @@ TEST_CASE("memory::UnorderedBimap") SUBCASE("had entries") { - bimap.add(1, 'a'); + bimap.insert(1, 'a'); CHECK_FALSE(bimap.empty()); CHECK(bimap.size() == 1); - CHECK(bimap.has(1, 'a')); - CHECK(bimap.hasLeft(1)); - CHECK(bimap.hasRight('a')); - CHECK(bimap.getLeft('a') == 1); - CHECK(bimap.getRight(1) == 'a'); + CHECK(bimap.contains(1, 'a')); + CHECK(bimap.containsLeft(1)); + CHECK(bimap.containsRight('a')); + CHECK(bimap.atLeft('a') == 1); + CHECK(bimap.atRight(1) == 'a'); CHECK(bimap.begin() != bimap.end()); CHECK(bimap.begin()->first == 1); CHECK(bimap.begin()->second == 'a'); CHECK(++bimap.begin() == bimap.end()); - bimap.add(2, 'b'); + bimap.insert(2, 'b'); CHECK(bimap.size() == 2); - CHECK(bimap.has(1, 'a')); - CHECK(bimap.has(2, 'b')); - CHECK(bimap.getRight(1) == 'a'); - CHECK(bimap.getRight(2) == 'b'); - CHECK(bimap.getLeft('a') == 1); - CHECK(bimap.getLeft('b') == 2); + CHECK(bimap.contains(1, 'a')); + CHECK(bimap.contains(2, 'b')); + CHECK(bimap.atRight(1) == 'a'); + CHECK(bimap.atRight(2) == 'b'); + CHECK(bimap.atLeft('a') == 1); + CHECK(bimap.atLeft('b') == 2); - bimap.add(1, 'b'); + bimap.insert(1, 'b'); CHECK(bimap.size() == 1); - CHECK(bimap.has(1, 'b')); - CHECK_FALSE(bimap.has(1, 'a')); - CHECK_FALSE(bimap.has(2, 'b')); - CHECK(bimap.getRight(1) == 'b'); - CHECK(bimap.getLeft('b') == 1); + CHECK(bimap.contains(1, 'b')); + CHECK_FALSE(bimap.contains(1, 'a')); + CHECK_FALSE(bimap.contains(2, 'b')); + CHECK(bimap.atRight(1) == 'b'); + CHECK(bimap.atLeft('b') == 1); SUBCASE("remove left") { - CHECK(bimap.removeLeft(1)); + CHECK(bimap.eraseLeft(1)); } SUBCASE("remove right") { - CHECK(bimap.removeRight('b')); + CHECK(bimap.eraseRight('b')); } SUBCASE("clear") @@ -69,12 +69,12 @@ TEST_CASE("memory::UnorderedBimap") CHECK(bimap.empty()); CHECK(bimap.size() == 0); - CHECK_FALSE(bimap.has(1, 'a')); - CHECK_FALSE(bimap.hasLeft(1)); - CHECK_FALSE(bimap.hasRight('a')); + CHECK_FALSE(bimap.contains(1, 'a')); + CHECK_FALSE(bimap.containsLeft(1)); + CHECK_FALSE(bimap.containsRight('a')); CHECK(bimap.begin() == bimap.end()); - CHECK_FALSE(bimap.removeLeft(1)); - CHECK_FALSE(bimap.removeRight('a')); + CHECK_FALSE(bimap.eraseLeft(1)); + CHECK_FALSE(bimap.eraseRight('a')); }