summaryrefslogtreecommitdiff
path: root/graphs/cpp/bimap/bimap.hh
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:08:27 +0200
commitc9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch)
tree3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/cpp/bimap/bimap.hh
add: graphs et rushs
Diffstat (limited to 'graphs/cpp/bimap/bimap.hh')
-rw-r--r--graphs/cpp/bimap/bimap.hh36
1 files changed, 36 insertions, 0 deletions
diff --git a/graphs/cpp/bimap/bimap.hh b/graphs/cpp/bimap/bimap.hh
new file mode 100644
index 0000000..25f459d
--- /dev/null
+++ b/graphs/cpp/bimap/bimap.hh
@@ -0,0 +1,36 @@
+#pragma once
+
+#include <map>
+
+ template <typename Lhs, typename Rhs>
+ class Bimap
+{
+ static_assert(!std::is_same_v<Lhs, Rhs>,
+ "Lhs and Rhs must be different types");
+ using mapLhs = std::map<Lhs, Rhs>;
+ using mapRhs = std::map<Rhs, Lhs>;
+ using iteratorLhs = typename mapLhs::const_iterator;
+ using iteratorRhs = typename mapRhs::const_iterator;
+
+public:
+ bool insert(const Lhs& vl, const Rhs& vr);
+ bool insert(const Rhs& vr, const Lhs& vl);
+
+ std::size_t erase(const Lhs& vl);
+ std::size_t erase(const Rhs& vr);
+
+ iteratorLhs find(const Lhs& vl) const;
+ iteratorRhs find(const Rhs& vr) const;
+
+ std::size_t size() const;
+ void clear();
+
+ const mapLhs& get_lhs() const;
+ const mapRhs& get_rhs() const;
+
+private:
+ mapLhs lhs_;
+ mapRhs rhs_;
+};
+
+#include "bimap.hxx"