Skip to content

Commit

Permalink
style(memory): use standard names in UnorderedBimap
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Oct 8, 2023
1 parent 5b03570 commit f3ec829
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
20 changes: 10 additions & 10 deletions core/include/cubos/core/memory/unordered_bimap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
52 changes: 26 additions & 26 deletions core/tests/memory/unordered_bimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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'));
}

0 comments on commit f3ec829

Please sign in to comment.