From c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:08:27 +0200 Subject: add: graphs et rushs --- graphs/cpp/bimap/bimap.hxx | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 graphs/cpp/bimap/bimap.hxx (limited to 'graphs/cpp/bimap/bimap.hxx') 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 +bool Bimap::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 +bool Bimap::insert(const Rhs& vr, const Lhs& vl) +{ + return insert(vl, vr); +} +template +std::size_t Bimap::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 +std::size_t Bimap::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 Bimap::iteratorLhs Bimap::find(const Lhs& vl) const +{ + return lhs_.find(vl); +} +template +typename Bimap::iteratorRhs Bimap::find(const Rhs& vr) const +{ + return rhs_.find(vr); +} +template +std::size_t Bimap::size() const +{ + return lhs_.size(); +} +template +void Bimap::clear() +{ + lhs_ = {}; + rhs_ = {}; +} +template +const typename Bimap::mapLhs& Bimap::get_lhs() const +{ + return lhs_; +} +template +const typename Bimap::mapRhs& Bimap::get_rhs() const +{ + return rhs_; +} \ No newline at end of file -- cgit v1.2.3