aGrUM  0.16.0
arcGraphPart_inl.h
Go to the documentation of this file.
1 
30 // to ease parsing by IDE
32 
33 namespace gum {
34 
35  INLINE bool ArcGraphPart::emptyArcs() const { return __arcs.empty(); }
36 
37  INLINE Size ArcGraphPart::sizeArcs() const { return __arcs.size(); }
38 
39  INLINE const ArcSet& ArcGraphPart::arcs() const { return __arcs; }
40 
41  INLINE bool ArcGraphPart::existsArc(const Arc& arc) const {
42  return __arcs.contains(arc);
43  }
44 
45  INLINE bool ArcGraphPart::existsArc(const NodeId tail, const NodeId head) const {
46  return __parents.exists(head) && __parents[head]->exists(tail);
47  }
48 
49  INLINE void ArcGraphPart::__checkParents(const NodeId id) const {
50  if (!__parents.exists(id)) { __parents.insert(id, new NodeSet); }
51  }
52 
53  INLINE void ArcGraphPart::__checkChildren(const NodeId id) const {
54  if (!__children.exists(id)) { __children.insert(id, new NodeSet); }
55  }
56 
57  INLINE const NodeSet& ArcGraphPart::parents(const NodeId id) const {
58  __checkParents(id);
59  return *(__parents[id]);
60  }
61 
62  INLINE const NodeSet& ArcGraphPart::children(const NodeId id) const {
63  __checkChildren(id);
64  return *(__children[id]);
65  }
66 
67  INLINE void ArcGraphPart::addArc(const NodeId tail, const NodeId head) {
68  Arc arc(tail, head);
69 
70  __arcs.insert(arc);
71  __checkParents(head);
72  __checkChildren(tail);
73  __parents[head]->insert(tail);
74  __children[tail]->insert(head);
75 
76  GUM_EMIT2(onArcAdded, tail, head);
77  }
78 
79  INLINE void ArcGraphPart::eraseArc(const Arc& arc) {
80  // ASSUMING tail and head exists in __parents anf __children
81  // (if not, it is an error)
82  if (existsArc(arc)) {
83  NodeId tail = arc.tail(), head = arc.head();
84  __parents[head]->erase(tail);
85  __children[tail]->erase(head);
86  __arcs.erase(arc);
87  GUM_EMIT2(onArcDeleted, tail, head);
88  }
89  }
90 
91  INLINE void ArcGraphPart::_eraseSetOfArcs(const ArcSet& set) {
92  for (const auto arc : set)
93  eraseArc(arc);
94  }
95 
96  INLINE void ArcGraphPart::eraseParents(const NodeId id) {
97  if (__parents.exists(id)) {
98  NodeSet& parents = *(__parents[id]);
99 
100  for (auto iter = parents.beginSafe(); // safe iterator needed here
101  iter != parents.endSafe();
102  ++iter) {
103  // warning: use this erase so that you actually use the virtualized
104  // arc removal function
105  eraseArc(Arc(*iter, id));
106  }
107  }
108  }
109 
110  INLINE void ArcGraphPart::eraseChildren(const NodeId id) {
111  if (__children.exists(id)) {
112  NodeSet& children = *(__children[id]);
113 
114  for (auto iter = children.beginSafe(); // safe iterator needed here
115  iter != children.endSafe();
116  ++iter) {
117  // warning: use this erase so that you actually use the vritualized
118  // arc removal function
119  eraseArc(Arc(id, *iter));
120  }
121  }
122  }
123 
125  for (const auto& arc : set)
127  }
128 
130  if (__parents.exists(id)) {
131  NodeSet& parents = *(__parents[id]);
132 
133  for (auto iter = parents.beginSafe(); // safe iterator needed here
134  iter != parents.endSafe();
135  ++iter) {
136  ArcGraphPart::eraseArc(Arc(*iter, id));
137  }
138  }
139  }
140 
142  if (__children.exists(id)) {
143  NodeSet& children = *(__children[id]);
144 
145  for (auto iter = children.beginSafe(); // safe iterator needed here
146  iter != children.endSafe();
147  ++iter) {
148  ArcGraphPart::eraseArc(Arc(id, *iter));
149  }
150  }
151  }
152 
153  INLINE bool ArcGraphPart::operator==(const ArcGraphPart& p) const {
154  return __arcs == p.__arcs;
155  }
156 
157  INLINE bool ArcGraphPart::operator!=(const ArcGraphPart& p) const {
158  return __arcs != p.__arcs;
159  }
160 
161 } /* namespace gum */
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:581
void __checkParents(const NodeId id) const
when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entr...
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the ArcGraphPart
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:707
Classes for directed edge sets.
Definition: arcGraphPart.h:79
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:656
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
NodeId head() const
returns the head of the arc
void __checkChildren(const NodeId id) const
when the ArcGraphPart contains no arc outgoing from a given node, this function adds an empty set ent...
const iterator_safe & endSafe() const noexcept
The usual safe end iterator to parse the set.
Definition: set_tpl.h:502
void _eraseSetOfArcs(const ArcSet &set)
a (virtualized) function to remove a given set of arcs
bool emptyArcs() const
indicates wether the ArcGraphPart contains any arc
bool operator!=(const ArcGraphPart &p) const
tests whether two ArcGraphParts contain different arcs
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:42
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
bool operator==(const ArcGraphPart &p) const
tests whether two ArcGraphParts contain the same arcs
void _unvirtualizedEraseSetOfArcs(const ArcSet &set)
similar to _eraseSetOfArcs except that it is unvirtualized
void eraseChildren(const NodeId id)
removes all the children of a given node
NodeProperty< NodeSet *> __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:272
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Signaler2< NodeId, NodeId > onArcAdded
Definition: arcGraphPart.h:83
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:275
iterator_safe beginSafe() const
The usual safe begin iterator to parse the set.
Definition: set_tpl.h:488
void unvirtualizedEraseChildren(const NodeId id)
same function as eraseChildren but without any virtual call to an erase
void unvirtualizedEraseParents(const NodeId id)
same function as eraseParents but without any virtual call to an erase
Signaler2< NodeId, NodeId > onArcDeleted
Definition: arcGraphPart.h:84
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:269
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
Size NodeId
Type for node ids.
Definition: graphElements.h:98
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
NodeId tail() const
returns the tail of the arc
void eraseParents(const NodeId id)
erase all the parents of a given node