ROSE  0.11.96.11
GraphIteratorBiMap.h
1 // WARNING: Changes to this file must be contributed back to Sawyer or else they will
2 // be clobbered by the next update from Sawyer. The Sawyer repository is at
3 // https://github.com/matzke1/sawyer.
4 
5 
6 
7 
8 #ifndef Sawyer_GraphIteratorBiMap_H
9 #define Sawyer_GraphIteratorBiMap_H
10 
11 #include <Sawyer/GraphIteratorMap.h>
12 
13 namespace Sawyer {
14 namespace Container {
15 
22 template<class LhsIterator, class RhsIterator>
24 public:
27 
28 private:
29  ForwardMap forward_;
30  ReverseMap reverse_;
31 
32 public:
35 
41  template<class U>
43  BOOST_FOREACH (const typename ForwardMap::Node &anode, a.forward_.nodes()) {
44  if (b.forward_.exists(anode.value())) {
45  const RhsIterator &target = b.forward_[anode.value()];
46  insert(anode.key(), target);
47  }
48  }
49  }
50 
59  void updateIdNumbers() {
60  forward_.updateIdNumbers();
61  reverse_.updateIdNumbers();
62  }
63 
65  void insert(const LhsIterator &a, const RhsIterator &b) {
66  if (Sawyer::Optional<RhsIterator> found = forward_.find(a)) {
67  if (*found == b)
68  return;
69  reverse_.erase(b);
70  }
71  forward_.insert(a, b);
72  reverse_.insert(b, a);
73  }
74 
76  void eraseSource(const LhsIterator &a) {
77  if (Sawyer::Optional<RhsIterator> found = forward_.find(a)) {
78  reverse_.erase(*found);
79  forward_.erase(a);
80  }
81  }
82 
84  void eraseTarget(const RhsIterator &b) {
85  if (Sawyer::Optional<LhsIterator> found = reverse_.find(b)) {
86  forward_.erase(*found);
87  reverse_.erase(b);
88  }
89  }
90 
92  const ForwardMap& forward() const {
93  return forward_;
94  }
95 
97  const ReverseMap& reverse() const {
98  return reverse_;
99  }
100 
102  void clear() {
103  forward_.clear();
104  reverse_.clear();
105  }
106 };
107 
108 } // namespace
109 } // namespace
110 
111 #endif
Sawyer::Container::GraphIteratorBiMap::eraseTarget
void eraseTarget(const RhsIterator &b)
Erase a pair based on the right hand side.
Definition: GraphIteratorBiMap.h:84
Sawyer::Container::GraphIteratorMap< LhsIterator, RhsIterator >
Sawyer::Optional
Holds a value or nothing.
Definition: Optional.h:49
Sawyer::Container::GraphIteratorMap::erase
void erase(const Key &item)
Erase the specified key if it exists.
Definition: GraphIteratorMap.h:375
Sawyer::Container::GraphIteratorMap::clear
void clear()
Remove all entries from this container.
Definition: GraphIteratorMap.h:384
Sawyer::Container::GraphIteratorBiMap::clear
void clear()
Remove all entries from this container.
Definition: GraphIteratorBiMap.h:102
Sawyer::Container::GraphIteratorBiMap::GraphIteratorBiMap
GraphIteratorBiMap()
Default constructor.
Definition: GraphIteratorBiMap.h:34
Sawyer::Container::GraphIteratorMap::updateIdNumbers
void updateIdNumbers()
Indicate that an update is necessary due to erasures.
Definition: GraphIteratorMap.h:333
Sawyer::Container::GraphIteratorBiMap::eraseSource
void eraseSource(const LhsIterator &a)
Erase a pair based on the left hand side.
Definition: GraphIteratorBiMap.h:76
Sawyer::Container::GraphIteratorBiMap::forward
const ForwardMap & forward() const
Return the forward mapping.
Definition: GraphIteratorBiMap.h:92
Sawyer::Container::GraphIteratorBiMap
Bidirectional map of graph edge or vertex pointers.
Definition: GraphIteratorBiMap.h:23
Sawyer::Container::GraphIteratorBiMap::updateIdNumbers
void updateIdNumbers()
Indicate that an update is necessary due to erasures.
Definition: GraphIteratorBiMap.h:59
Sawyer::Container::GraphIteratorBiMap::reverse
const ReverseMap & reverse() const
Return the reverse mapping.
Definition: GraphIteratorBiMap.h:97
Sawyer::Container::GraphIteratorMap::insert
void insert(const Key &item, const Value &value)
Insert the specified edge or vertex associated with a value.
Definition: GraphIteratorMap.h:342
Sawyer::Container::GraphIteratorBiMap::GraphIteratorBiMap
GraphIteratorBiMap(const GraphIteratorBiMap< LhsIterator, U > &a, const GraphIteratorBiMap< U, RhsIterator > &b)
Construct a new map by composition of two maps.
Definition: GraphIteratorBiMap.h:42
Sawyer::Container::GraphIteratorMap::find
Sawyer::Optional< Value > find(const Key &item) const
Find the value associated with a particular key.
Definition: GraphIteratorMap.h:402
Sawyer
Name space for the entire library.
Definition: Access.h:13
Sawyer::Container::GraphIteratorMap::nodes
boost::iterator_range< NodeIterator > nodes()
Iterators for container nodes.
Definition: GraphIteratorMap.h:428
Sawyer::Container::GraphIteratorBiMap::insert
void insert(const LhsIterator &a, const RhsIterator &b)
Insert a mapping from edge or vertex a to edge or vertex b.
Definition: GraphIteratorBiMap.h:65
Sawyer::Container::GraphIteratorMap::exists
bool exists(const Key &item) const
Does the key exist in the map?
Definition: GraphIteratorMap.h:394