diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/cpp/bimap/bimap.hxx | |
add: graphs et rushs
Diffstat (limited to 'graphs/cpp/bimap/bimap.hxx')
| -rw-r--r-- | graphs/cpp/bimap/bimap.hxx | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/graphs/cpp/bimap/bimap.hxx b/graphs/cpp/bimap/bimap.hxx new file mode 100644 index 0000000..9b1eb1f --- /dev/null +++ b/graphs/cpp/bimap/bimap.hxx @@ -0,0 +1,74 @@ +#pragma once +#include "bimap.hh" + +template <typename Lhs, typename Rhs> +bool Bimap<Lhs, Rhs>::insert(const Lhs& vl, const Rhs& vr) +{ + if (lhs_.contains(vl) || rhs_.contains(vr)) + return false; + if (lhs_.contains(vl) || !lhs_.insert({ vl, vr }).second) + return false; + if (rhs_.contains(vr) || !rhs_.insert({ vr, vl }).second) + return false; + return true; +} +template <typename Lhs, typename Rhs> +bool Bimap<Lhs, Rhs>::insert(const Rhs& vr, const Lhs& vl) +{ + return insert(vl, vr); +} +template <typename Lhs, typename Rhs> +std::size_t Bimap<Lhs, Rhs>::erase(const Lhs& vl) +{ + if (lhs_.size() <= 0) + return 0; + auto range = lhs_.find(vl); + if (range == lhs_.end()) + return 0; + rhs_.erase(range->second); + size_t n = lhs_.erase(range->first); + return n; +} +template <typename Lhs, typename Rhs> +std::size_t Bimap<Lhs, Rhs>::erase(const Rhs& vr) +{ + if (lhs_.size() <= 0) + return 0; + auto range = rhs_.find(vr); + if (range == rhs_.end()) + return 0; + lhs_.erase(range->second); + size_t n = rhs_.erase(range->first); + return n; +} +template <typename Lhs, typename Rhs> +typename Bimap<Lhs, Rhs>::iteratorLhs Bimap<Lhs, Rhs>::find(const Lhs& vl) const +{ + return lhs_.find(vl); +} +template <typename Lhs, typename Rhs> +typename Bimap<Lhs, Rhs>::iteratorRhs Bimap<Lhs, Rhs>::find(const Rhs& vr) const +{ + return rhs_.find(vr); +} +template <typename Lhs, typename Rhs> +std::size_t Bimap<Lhs, Rhs>::size() const +{ + return lhs_.size(); +} +template <typename Lhs, typename Rhs> +void Bimap<Lhs, Rhs>::clear() +{ + lhs_ = {}; + rhs_ = {}; +} +template <typename Lhs, typename Rhs> +const typename Bimap<Lhs, Rhs>::mapLhs& Bimap<Lhs, Rhs>::get_lhs() const +{ + return lhs_; +} +template <typename Lhs, typename Rhs> +const typename Bimap<Lhs, Rhs>::mapRhs& Bimap<Lhs, Rhs>::get_rhs() const +{ + return rhs_; +}
\ No newline at end of file |
