aGrUM  0.16.0
edgeGraphPart_inl.h
Go to the documentation of this file.
1 
30 // to ease parsing by IDE
32 
33 namespace gum {
34 
35  INLINE bool EdgeGraphPart::emptyEdges() const { return __edges.empty(); }
36 
37  INLINE Size EdgeGraphPart::sizeEdges() const { return __edges.size(); }
38 
39  INLINE const EdgeSet& EdgeGraphPart::edges() const { return __edges; }
40 
41  INLINE bool EdgeGraphPart::existsEdge(const Edge& edge) const {
42  return __edges.contains(edge);
43  }
44 
45  INLINE bool EdgeGraphPart::existsEdge(const NodeId first,
46  const NodeId second) const {
47  return __neighbours.exists(first) && __neighbours[first]->exists(second);
48  }
49 
50  INLINE void EdgeGraphPart::__checkNeighbours(const NodeId id) const {
51  if (!__neighbours.exists(id)) { __neighbours.insert(id, new NodeSet); }
52  }
53 
54  INLINE void EdgeGraphPart::addEdge(const NodeId first, const NodeId second) {
55  Edge edge(first, second);
56  __edges.insert(edge);
57  __checkNeighbours(first);
58  __checkNeighbours(second);
59  __neighbours[first]->insert(second);
60  __neighbours[second]->insert(first);
61 
62  GUM_EMIT2(onEdgeAdded, first, second);
63  }
64 
65  INLINE void EdgeGraphPart::eraseEdge(const Edge& edge) {
66  if (existsEdge(edge)) {
67  // ASSUMING first and second exists in __neighbours (if not, it is an
68  // error)
69  NodeId id1 = edge.first(), id2 = edge.second();
70 
71  __neighbours[id1]->erase(id2);
72  __neighbours[id2]->erase(id1);
73  __edges.erase(edge);
74  GUM_EMIT2(onEdgeDeleted, id1, id2);
75  }
76  }
77 
78  INLINE const NodeSet& EdgeGraphPart::neighbours(const NodeId id) const {
80  return *(__neighbours[id]);
81  }
82 
83  INLINE void EdgeGraphPart::eraseNeighbours(const NodeId id) {
84  if (__neighbours.exists(id)) {
85  const NodeSet& set = neighbours(id);
86 
87  for (auto iter = set.beginSafe(); iter != set.endSafe();
88  ++iter) { // safe iterator needed here
89  // warning: use this erase so that you actually use the virtualized
90  // edge removal function
91  eraseEdge(Edge(*iter, id));
92  }
93  }
94  }
95 
97  if (__neighbours.exists(id)) {
98  const NodeSet& set = neighbours(id);
99 
100  for (auto iter = set.beginSafe(); iter != set.endSafe();
101  ++iter) { // safe iterator needed here
102  EdgeGraphPart::eraseEdge(Edge(*iter, id));
103  }
104  }
105  }
106 
107  INLINE bool EdgeGraphPart::operator==(const EdgeGraphPart& p) const {
108  return __edges == p.__edges;
109  }
110 
111  INLINE bool EdgeGraphPart::operator!=(const EdgeGraphPart& p) const {
112  return __edges != p.__edges;
113  }
114 
115 } /* namespace gum */
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:581
NodeId second() const
returns the node ID of the other extremal node ID
bool operator==(const EdgeGraphPart &p) const
tests whether two EdgeGraphParts contain the same edges
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:707
bool emptyEdges() const
indicates wether the EdgeGraphPart contains any edge
virtual void addEdge(const NodeId n1, const NodeId n2)
insert a new edge into the EdgeGraphPart
NodeProperty< NodeSet *> __neighbours
for each node, the set of its adjacent edges
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:656
Classes for undirected edge sets.
Definition: edgeGraphPart.h:75
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
void __checkNeighbours(const NodeId id) const
when the EdgeGraphPart contains no edge adjacent to a given node, this function adds an empty set ent...
const EdgeSet & edges() const
returns the set of edges stored within the EdgeGraphPart
NodeId first() const
returns one extremal node ID (whichever one it is is unspecified)
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:42
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists
Signaler2< NodeId, NodeId > onEdgeDeleted
Definition: edgeGraphPart.h:80
bool operator!=(const EdgeGraphPart &p) const
tests whether two EdgeGraphParts contain different edges
The base class for all undirected edges.
Size sizeEdges() const
indicates the number of edges stored within the EdgeGraphPart
void unvirtualizedEraseNeighbours(const NodeId id)
same function as eraseNeighbours but without any virtual call to an erase
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
virtual void eraseEdge(const Edge &edge)
removes an edge from the EdgeGraphPart
Signaler2< NodeId, NodeId > onEdgeAdded
Definition: edgeGraphPart.h:79
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701
void eraseNeighbours(const NodeId id)
erase all the edges adjacent to a given node
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
EdgeSet __edges
the set of all the edges contained within the EdgeGraphPart