Tulip  5.0.0
Large graphs analysis and drawing
Node.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
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 object.
35  *
36  * @see tlp::edge
37  * @see tlp::Graph
38  */
39 struct node {
40  /**
41  * @brief id The identifier of the node.
42  */
43  unsigned int id;
44 
45  /**
46  * @brief node creates an invalid node.
47  */
48  node():id(UINT_MAX) {}
49 
50  /**
51  * @brief node Create a node of given identifier.
52  * It is your responsibility to make sure a node of this ID exists when you create the node.
53  * If you want to make sure this node exists, use Graph::isElement(), as isValid() will only tell is the node was correctly initialized.
54  *
55  * @param j the identifier this node will use.
56  */
57  explicit node(unsigned int j):id(j) {}
58 
59  /**
60  * @brief operator unsigned int A convenience function to get the id of a node.
61  */
62  operator unsigned int() const {
63  return id;
64  }
65 
66  /**
67  * @brief operator != Compares two nodes, checking that they are different..
68  * @param n The other node to compare this one to.
69  * @return Whether or not the two nodes are different.
70  */
71  bool operator!=(const node n) const {
72  return id!=n.id;
73  }
74 
75  /**
76  * @brief operator != Compares two nodes, checking that they are identical.
77  * @param n The other node to compare this one to.
78  * @return Whether or not the two nodes are the same.
79  */
80  bool operator==(const node n) const {
81  return id==n.id;
82  }
83 
84  /**
85  * @brief isValid checks if the node is valid.
86  * An invalid node is a node whose id is UINT_MAX.
87  *
88  * @return whether the node is valid or not.
89  */
90  bool isValid() const {
91  return id!=UINT_MAX;
92  }
93 };
94 
95 }
96 
97 ///@cond DOXYGEN_HIDDEN
98 //these three functions allow to use tlp::node as a key in a hash-based data structure (e.g. hashmap).
99 TLP_BEGIN_HASH_NAMESPACE {
100  template<> struct hash<tlp::node> {
101  size_t operator()(const tlp::node n) const {return n.id;}
102  };
103 } TLP_END_HASH_NAMESPACE
104 
105 
106 namespace std {
107 template<> struct equal_to<tlp::node> {
108  size_t operator()(const tlp::node n,const tlp::node n2) const {
109  return n.id==n2.id;
110  }
111 };
112 template<> struct less<tlp::node> {
113  size_t operator()(const tlp::node n,const tlp::node n2) const {
114  return n.id<n2.id;
115  }
116 };
117 }
118 ///@endcond
119 
120 #endif
bool operator!=(const node n) const
operator != Compares two nodes, checking that they are different..
Definition: Node.h:71
node()
node creates an invalid node.
Definition: Node.h:48
bool isValid() const
isValid checks if the node is valid. An invalid node is a node whose id is UINT_MAX.
Definition: Node.h:90
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:57
bool operator==(const node n) const
operator != Compares two nodes, checking that they are identical.
Definition: Node.h:80
The node struct represents a node in a Graph object.
Definition: Node.h:39
unsigned int id
id The identifier of the node.
Definition: Node.h:43