| 1 | /* |
| 2 | * ids.hpp |
| 3 | * |
| 4 | * Created on: Mar 1, 2016 |
| 5 | * Author: i-bird |
| 6 | */ |
| 7 | |
| 8 | #ifndef SRC_GRAPH_IDS_HPP_ |
| 9 | #define SRC_GRAPH_IDS_HPP_ |
| 10 | |
| 11 | /*! Here we define different the remapped-id |
| 12 | * |
| 13 | * rid, gid and lid are all unsigned long integer, and can be easily interchanged by mistake |
| 14 | * encapsulating avoid that this could happen. The second is readability, from the definition |
| 15 | * of function/structure we see immediately which id parameter accept/store |
| 16 | * |
| 17 | */ |
| 18 | struct rid |
| 19 | { |
| 20 | //! id |
| 21 | idx_t id; |
| 22 | |
| 23 | /*! \brief Cosntructor from id |
| 24 | * |
| 25 | * \param id |
| 26 | * |
| 27 | */ |
| 28 | rid(size_t id) |
| 29 | :id(id) |
| 30 | {} |
| 31 | |
| 32 | //! Constructor |
| 33 | rid() |
| 34 | :id(0) |
| 35 | {} |
| 36 | |
| 37 | /*! \brief Compare two gid |
| 38 | * |
| 39 | * \param r gid to compare with |
| 40 | * |
| 41 | * \return the result for comparation |
| 42 | * |
| 43 | */ |
| 44 | inline bool operator<=(const rid & r) const |
| 45 | { |
| 46 | return id <= r.id; |
| 47 | } |
| 48 | |
| 49 | /*! \brief Compare two gid |
| 50 | * |
| 51 | * \param r gid to compare with |
| 52 | * |
| 53 | * \return the result for comparation |
| 54 | * |
| 55 | */ |
| 56 | inline bool operator<(const rid & r) const |
| 57 | { |
| 58 | return id < r.id; |
| 59 | } |
| 60 | |
| 61 | /*! \brief Subtract two gid |
| 62 | * |
| 63 | * \param i |
| 64 | * |
| 65 | * \return itself |
| 66 | * |
| 67 | */ |
| 68 | inline rid operator-(int i) const |
| 69 | { |
| 70 | struct rid tmp; |
| 71 | tmp.id = id - i; |
| 72 | return tmp; |
| 73 | } |
| 74 | |
| 75 | /*! \brief Subtract two gid |
| 76 | * |
| 77 | * \param i gid to subtract |
| 78 | * |
| 79 | * \return itself |
| 80 | * |
| 81 | */ |
| 82 | inline rid operator-(struct rid i) const |
| 83 | { |
| 84 | struct rid tmp; |
| 85 | tmp.id = id - i.id; |
| 86 | return tmp; |
| 87 | } |
| 88 | |
| 89 | /*! \brief Sum two gid |
| 90 | * |
| 91 | * \param i gid to subtract |
| 92 | * |
| 93 | * \return itself |
| 94 | * |
| 95 | */ |
| 96 | inline rid operator+(int i) const |
| 97 | { |
| 98 | struct rid tmp; |
| 99 | tmp.id = id + i; |
| 100 | return tmp; |
| 101 | } |
| 102 | |
| 103 | /*! \brief Sum two gid |
| 104 | * |
| 105 | * \param i gid to sum |
| 106 | * |
| 107 | * \return itself |
| 108 | * |
| 109 | */ |
| 110 | inline rid & operator+=(const rid & i) |
| 111 | { |
| 112 | id += i.id; |
| 113 | return *this; |
| 114 | } |
| 115 | |
| 116 | /*! \brief Increment the id |
| 117 | * |
| 118 | * \return itself |
| 119 | * |
| 120 | */ |
| 121 | inline rid & operator++() |
| 122 | { |
| 123 | id++; |
| 124 | |
| 125 | return *this; |
| 126 | } |
| 127 | |
| 128 | /*! \brief compare two ids |
| 129 | * |
| 130 | * \param r id to check with |
| 131 | * |
| 132 | * \return the result |
| 133 | * |
| 134 | */ |
| 135 | inline bool operator==(const rid & r) const |
| 136 | { |
| 137 | return id == r.id; |
| 138 | } |
| 139 | }; |
| 140 | |
| 141 | /*! Here we define different the remapped-id |
| 142 | * |
| 143 | * rid, gid and lid are all unsigned long integer, and can be easily interchanged by mistake |
| 144 | * encapsulating avoid that this could happen. The second is readability, from the definition |
| 145 | * of function/structure we see immediately which id parameter accept/store |
| 146 | * |
| 147 | */ |
| 148 | struct gid |
| 149 | { |
| 150 | size_t id; |
| 151 | |
| 152 | //! Constructor |
| 153 | gid(){}; |
| 154 | |
| 155 | //! Constructor |
| 156 | gid(size_t id) |
| 157 | :id(id) |
| 158 | {} |
| 159 | }; |
| 160 | |
| 161 | /*! Here we define different the remapped-id |
| 162 | * |
| 163 | * rid, gid and lid are all unsigned long integer, and can be easily interchanged by mistake |
| 164 | * encapsulating avoid that this could happen. The second is readability, from the definition |
| 165 | * of function/structure we see immediately which id parameter accept/store |
| 166 | * |
| 167 | */ |
| 168 | struct lid |
| 169 | { |
| 170 | size_t id; |
| 171 | }; |
| 172 | |
| 173 | // define hash map for gid rid and lid |
| 174 | |
| 175 | namespace std |
| 176 | { |
| 177 | template <> |
| 178 | struct hash<rid> |
| 179 | { |
| 180 | inline std::size_t operator()(const rid& k) const |
| 181 | { |
| 182 | return k.id; |
| 183 | } |
| 184 | }; |
| 185 | |
| 186 | template <> |
| 187 | struct hash<gid> |
| 188 | { |
| 189 | inline std::size_t operator()(const gid& k) const |
| 190 | { |
| 191 | return k.id; |
| 192 | } |
| 193 | }; |
| 194 | |
| 195 | template <> |
| 196 | struct hash<lid> |
| 197 | { |
| 198 | inline std::size_t operator()(const lid& k) const |
| 199 | { |
| 200 | return k.id; |
| 201 | } |
| 202 | }; |
| 203 | |
| 204 | } |
| 205 | |
| 206 | |
| 207 | #endif /* SRC_GRAPH_IDS_HPP_ */ |
| 208 | |