Tulip  5.2.1
Large graphs analysis and drawing
Node.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 #ifndef Tulip_NODE_H
21 #define Tulip_NODE_H
22 #include <climits>
23 #include <tulip/tuliphash.h>
24 
25 namespace tlp {
26 
27 /**
28  * @ingroup Graph
29  * @brief The node struct represents a node in a Graph object.
30  *
31  * This structure only contains an identifier, and a function to check if the node is valid.
32  * A node is considered invalid when its id has the UINT_MAX value.
33  *
34  * Most operations performed on a node (getting out edges etc) are available into the tlp::Graph
35  * object.
36  *
37  * @see tlp::edge
38  * @see tlp::Graph
39  */
40 struct node {
41  /**
42  * @brief id The identifier of the node.
43  */
44  unsigned int id;
45 
46  /**
47  * @brief node creates an invalid node.
48  */
49  node() : id(UINT_MAX) {}
50 
51  /**
52  * @brief node Create a node of given identifier.
53  * It is your responsibility to make sure a node of this ID exists when you create the node.
54  * If you want to make sure this node exists, use Graph::isElement(), as isValid() will only tell
55  * is the node was correctly initialized.
56  *
57  * @param j the identifier this node will use.
58  */
59  explicit node(unsigned int j) : id(j) {}
60 
61  /**
62  * @brief operator unsigned int A convenience function to get the id of a node.
63  */
64  operator unsigned int() const {
65  return id;
66  }
67 
68  /**
69  * @brief operator != Compares two nodes, checking that they are different..
70  * @param n The other node to compare this one to.
71  * @return Whether or not the two nodes are different.
72  */
73  bool operator!=(const node n) const {
74  return id != n.id;
75  }
76 
77  /**
78  * @brief operator != Compares two nodes, checking that they are identical.
79  * @param n The other node to compare this one to.
80  * @return Whether or not the two nodes are the same.
81  */
82  bool operator==(const node n) const {
83  return id == n.id;
84  }
85 
86  /**
87  * @brief isValid checks if the node is valid.
88  * An invalid node is a node whose id is UINT_MAX.
89  *
90  * @return whether the node is valid or not.
91  */
92  bool isValid() const {
93  return id != UINT_MAX;
94  }
95 };
96 } // namespace tlp
97 
98 ///@cond DOXYGEN_HIDDEN
99 // these three functions allow to use tlp::node as a key in a hash-based data structure (e.g.
100 // hashmap).
101 TLP_BEGIN_HASH_NAMESPACE {
102  template <>
103  struct hash<tlp::node> {
104  size_t operator()(const tlp::node n) const {
105  return n.id;
106  }
107  };
108 }
109 TLP_END_HASH_NAMESPACE
110 
111 namespace std {
112 template <>
113 struct equal_to<tlp::node> {
114  size_t operator()(const tlp::node n, const tlp::node n2) const {
115  return n.id == n2.id;
116  }
117 };
118 template <>
119 struct less<tlp::node> {
120  size_t operator()(const tlp::node n, const tlp::node n2) const {
121  return n.id < n2.id;
122  }
123 };
124 } // namespace std
125 ///@endcond
126 
127 #endif
node()
node creates an invalid node.
Definition: Node.h:49
node(unsigned int j)
node Create a node of given identifier. It is your responsibility to make sure a node of this ID exis...
Definition: Node.h:59
The node struct represents a node in a Graph object.
Definition: Node.h:40
unsigned int id
id The identifier of the node.
Definition: Node.h:44
bool isValid() const
isValid checks if the node is valid. An invalid node is a node whose id is UINT_MAX.
Definition: Node.h:92
bool operator!=(const node n) const
operator != Compares two nodes, checking that they are different..
Definition: Node.h:73
bool operator==(const node n) const
operator != Compares two nodes, checking that they are identical.
Definition: Node.h:82