aGrUM  0.16.0
graphElements_inl.h
Go to the documentation of this file.
1 
28 #include <algorithm>
29 #include <iostream>
30 
31 #include <agrum/agrum.h>
32 
33 // to facilitate parsing
35 
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
37 
38 namespace gum {
39 
40  /* ===========================================================================
41  */
42  /* ===========================================================================
43  */
44  /* === GENERIC UNDIRECTED EDGES IMPLEMENTATION ===
45  */
46  /* ===========================================================================
47  */
48  /* ===========================================================================
49  */
50 
52 
53  INLINE Edge::Edge(NodeId aN1, NodeId aN2) :
54  n1(std::min(aN1, aN2)), n2(std::max(aN1, aN2)) {
55  // for debugging purposes
56  GUM_CONSTRUCTOR(Edge);
57  }
58 
60 
61  INLINE Edge::Edge(const Edge& src) : n1(src.n1), n2(src.n2) {
62  // for debugging purposes
63  GUM_CONS_CPY(Edge);
64  }
65 
67 
68  INLINE Edge& Edge::operator=(const Edge& src) {
69  // for debugging purposes
70  GUM_OP_CPY(Edge);
71  n1 = src.n1;
72  n2 = src.n2;
73  return *this;
74  }
75 
77 
78  INLINE Edge::~Edge() {
79  // for debugging purposes
80  GUM_DESTRUCTOR(Edge);
81  }
82 
84 
85  INLINE NodeId Edge::other(NodeId id) const {
86  if (id == n1)
87  return n2;
88  else if (id == n2)
89  return n1;
90  else {
91  GUM_ERROR(IdError, id << " does not belong to this edge");
92  }
93  }
94 
96 
97  INLINE NodeId Edge::first() const { return n1; }
98 
100 
101  INLINE NodeId Edge::second() const { return n2; }
102 
104 
105  INLINE bool Edge::operator==(const Edge& src) const {
106  return ((n1 == src.n1) && (n2 == src.n2));
107  }
108 
110 
111  INLINE bool Edge::operator!=(const Edge& src) const {
112  return ((n1 != src.n1) || (n2 != src.n2));
113  }
114 
115 
116  // Returns the value of a key as a Size
117  INLINE Size HashFunc< Edge >::castToSize(const Edge& key) {
118  return Size(key.first()) * HashFuncConst::pi
119  + Size(key.second()) * HashFuncConst::gold;
120  }
121 
122  // Computes the hashed value of a key.
123  INLINE Size HashFunc< Edge >::operator()(const Edge& key) const {
124  return castToSize(key) & this->_hash_mask;
125  }
126 
127 
128  /* ===========================================================================
129  */
130  /* ===========================================================================
131  */
132  /* === GENERIC DIRECTED EDGES IMPLEMENTATION ===
133  */
134  /* ===========================================================================
135  */
136  /* ===========================================================================
137  */
138 
140 
141  INLINE Arc::Arc(NodeId tail, NodeId head) : n1(tail), n2(head) {
142  // for debugging purposes
143  GUM_CONSTRUCTOR(Arc);
144  }
145 
147 
148  INLINE Arc::Arc(const Arc& src) : n1(src.n1), n2(src.n2) {
149  // for debugging purposes
150  GUM_CONS_CPY(Arc);
151  }
152 
154 
155  INLINE Arc& Arc::operator=(const Arc& src) {
156  // for debugging purposes
157  GUM_OP_CPY(Arc);
158  n1 = src.n1;
159  n2 = src.n2;
160  return *this;
161  }
162 
164 
165  INLINE Arc::~Arc() {
166  // for debugging purposes
167  GUM_DESTRUCTOR(Arc);
168  }
169 
171 
172  INLINE NodeId Arc::tail() const { return n1; }
173 
175 
176  INLINE void Arc::__setTail(NodeId id) { n1 = id; }
177 
179 
180  INLINE NodeId Arc::head() const { return n2; }
181 
183 
184  INLINE void Arc::__setHead(NodeId id) { n2 = id; }
185 
187 
188  INLINE NodeId Arc::other(NodeId id) const {
189  if (id == n1)
190  return n2;
191  else if (id == n2)
192  return n1;
193  else {
194  GUM_ERROR(IdError, id << " does not belong to this arc");
195  }
196  }
197 
199 
200  INLINE NodeId Arc::first() const { return n1; }
201 
203 
204  INLINE NodeId Arc::second() const { return n2; }
205 
207 
208  INLINE bool Arc::operator==(const Arc& src) const {
209  return ((n1 == src.n1) && (n2 == src.n2));
210  }
211 
213 
214  INLINE bool Arc::operator!=(const Arc& src) const {
215  return ((n1 != src.n1) || (n2 != src.n2));
216  }
217 
219 
220  INLINE void Arc::operator-() {
221  NodeId n_temp = n1;
222  n1 = n2;
223  n2 = n_temp;
224  }
225 
226 
227  // Returns the value of a key as a Size
228  INLINE Size HashFunc< Arc >::castToSize(const Arc& key) {
229  return Size(key.first()) * HashFuncConst::pi
230  + Size(key.second()) * HashFuncConst::gold;
231  }
232 
233  // Computes the hashed value of a key.
234  INLINE Size HashFunc< Arc >::operator()(const Arc& key) const {
235  return castToSize(key) & this->_hash_mask;
236  }
237 
238 
239 } /* namespace gum */
240 
241 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
static constexpr Size pi
Definition: hashFunc.h:78
NodeId second() const
returns the node ID of the other extremal node ID
void __setTail(NodeId id)
modifies the tail of the arc
static constexpr Size gold
Definition: hashFunc.h:76
NodeId n1
the extremal nodes of the edge (their order is unimportant)
Edge & operator=(const Edge &src)
copy operator
NodeId n2
bool operator==(const Arc &src) const
checks whether two arcs are equal
STL namespace.
NodeId other(NodeId id) const
returns an extremal node of an edge given the ID of the other one
Edge(NodeId aN1, NodeId aN2)
constructs a new edge (aN1,aN2)
bool operator!=(const Arc &src) const
check if two arcs are different
~Edge()
destructor
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
void operator-()
reverses the direction of the arc
NodeId head() const
returns the head of the arc
NodeId second() const
returns the node ID of the other extremal node ID
NodeId first() const
returns one extremal node ID (whichever one it is is unspecified)
Arc(NodeId tail, NodeId head)
basic constructor. Creates tail -> head.
bool operator!=(const Edge &src) const
checks whether two undirected edges are different
void __setHead(NodeId id)
modifies the head of the arc
~Arc()
destructor
Arc & operator=(const Arc &src)
copy operator
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
NodeId n1
the extremal nodes of the edge (their order is unimportant)
bool operator==(const Edge &src) const
checks whether two undirected edges are equal
NodeId first() const
returns one extremal node ID (whichever one it is is unspecified)
Size NodeId
Type for node ids.
Definition: graphElements.h:98
NodeId tail() const
returns the tail of the arc
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
NodeId other(NodeId id) const
returns an extremal node of an edge given the ID of the other one
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.