SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Bimap.h
Go to the documentation of this file.
1 /**
2  * @file CSplitModule.h
3  * @author Ă–mer Sali <oemer.sali@rwth-aachen.de>
4  *
5  * @version 2018-04-04
6  * Created on 2017-11-01.
7  */
8 
9 #pragma once
10 
11 #include <forward_list>
12 #include <set>
13 
14 namespace smtrat
15 {
16  /**
17  * Container that stores expensive to construct objects and allows the
18  * fast lookup with respect to two independent keys within the objects.
19  */
20  template<class Class, typename FirstKeyType, FirstKeyType Class::*FirstKeyName, typename SecondKeyType, SecondKeyType Class::*SecondKeyName>
21  class Bimap
22  {
23  public:
24  typedef std::forward_list<Class> Data;
25  typedef typename Data::iterator Iterator;
26  typedef typename Data::const_iterator ConstIterator;
27 
28  private:
29  /// Comparator that performs a heterogeneous lookup on the first key
30  struct FirstCompare
31  {
32  using is_transparent = void;
33 
34  bool operator()(const Iterator& lhs, const Iterator& rhs) const
35  {
36  return (*lhs).*FirstKeyName<(*rhs).*FirstKeyName;
37  }
38 
39  bool operator()(const Iterator& lhs, const FirstKeyType& rhs) const
40  {
41  return (*lhs).*FirstKeyName<rhs;
42  }
43 
44  bool operator()(const FirstKeyType& lhs, const Iterator& rhs) const
45  {
46  return lhs<(*rhs).*FirstKeyName;
47  }
48  };
49 
50  /// Comparator that performs a heterogeneous lookup on the second key
52  {
53  using is_transparent = void;
54 
55  bool operator()(const Iterator& lhs, const Iterator& rhs) const
56  {
57  return (*lhs).*SecondKeyName<(*rhs).*SecondKeyName;
58  }
59 
60  bool operator()(const Iterator& lhs, const SecondKeyType& rhs) const
61  {
62  return (*lhs).*SecondKeyName<rhs;
63  }
64 
65  bool operator()(const SecondKeyType& lhs, const Iterator& rhs) const
66  {
67  return lhs<(*rhs).*SecondKeyName;
68  }
69  };
70 
72  std::set<Iterator, FirstCompare> mFirstMap;
73  std::set<Iterator, SecondCompare> mSecondMap;
74 
75  public:
76  Iterator begin() noexcept
77  {
78  return mData.begin();
79  }
80 
81  ConstIterator begin() const noexcept
82  {
83  return mData.begin();
84  }
85 
86  Iterator end() noexcept
87  {
88  return mData.end();
89  }
90 
91  ConstIterator end() const noexcept
92  {
93  return mData.end();
94  }
95 
96  Class& firstAt(const FirstKeyType& firstKey)
97  {
98  return *(*mFirstMap.find(firstKey));
99  }
100 
101  Class& secondAt(const SecondKeyType& secondKey)
102  {
103  return *(*mSecondMap.find(secondKey));
104  }
105 
106  Iterator firstFind(const FirstKeyType& firstKey)
107  {
108  auto firstIter{mFirstMap.find(firstKey)};
109  if (firstIter == mFirstMap.end())
110  return mData.end();
111  else
112  return *firstIter;
113  }
114 
115  Iterator secondFind(const SecondKeyType& secondKey)
116  {
117  auto secondIter{mSecondMap.find(secondKey)};
118  if (secondIter == mSecondMap.end())
119  return mData.end();
120  else
121  return *secondIter;
122  }
123 
124  template<typename... Args>
125  Iterator emplace(Args&&... args)
126  {
127  mData.emplace_front(std::move(args)...);
128  mFirstMap.emplace(mData.begin());
129  mSecondMap.emplace(mData.begin());
130  return mData.begin();
131  }
132  };
133 }
Container that stores expensive to construct objects and allows the fast lookup with respect to two i...
Definition: Bimap.h:22
Iterator end() noexcept
Definition: Bimap.h:86
Iterator begin() noexcept
Definition: Bimap.h:76
ConstIterator begin() const noexcept
Definition: Bimap.h:81
ConstIterator end() const noexcept
Definition: Bimap.h:91
Class & firstAt(const FirstKeyType &firstKey)
Definition: Bimap.h:96
Data::const_iterator ConstIterator
Definition: Bimap.h:26
Data mData
Definition: Bimap.h:71
Iterator firstFind(const FirstKeyType &firstKey)
Definition: Bimap.h:106
std::set< Iterator, SecondCompare > mSecondMap
Definition: Bimap.h:73
std::forward_list< Class > Data
Definition: Bimap.h:24
Iterator emplace(Args &&... args)
Definition: Bimap.h:125
Data::iterator Iterator
Definition: Bimap.h:25
Class & secondAt(const SecondKeyType &secondKey)
Definition: Bimap.h:101
std::set< Iterator, FirstCompare > mFirstMap
Definition: Bimap.h:72
Iterator secondFind(const SecondKeyType &secondKey)
Definition: Bimap.h:115
Class to create the formulas for axioms.
Comparator that performs a heterogeneous lookup on the first key.
Definition: Bimap.h:31
bool operator()(const Iterator &lhs, const Iterator &rhs) const
Definition: Bimap.h:34
bool operator()(const Iterator &lhs, const FirstKeyType &rhs) const
Definition: Bimap.h:39
bool operator()(const FirstKeyType &lhs, const Iterator &rhs) const
Definition: Bimap.h:44
Comparator that performs a heterogeneous lookup on the second key.
Definition: Bimap.h:52
bool operator()(const Iterator &lhs, const SecondKeyType &rhs) const
Definition: Bimap.h:60
bool operator()(const SecondKeyType &lhs, const Iterator &rhs) const
Definition: Bimap.h:65
bool operator()(const Iterator &lhs, const Iterator &rhs) const
Definition: Bimap.h:55