ids.hpp 3.13 KB
Newer Older
Pietro Incardona's avatar
Pietro Incardona committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * ids.hpp
 *
 *  Created on: Mar 1, 2016
 *      Author: i-bird
 */

#ifndef SRC_GRAPH_IDS_HPP_
#define SRC_GRAPH_IDS_HPP_

/*! Here we define different the remapped-id
 *
 * rid, gid and lid are all unsigned long integer, and can be easily interchanged by mistake
 *  encapsulating avoid that this could happen. The second is readability, from the definition
 *  of function/structure we see immediately which id parameter accept/store
 *
 */
struct rid
{
incardon's avatar
incardon committed
20
	//! id
Pietro Incardona's avatar
Pietro Incardona committed
21 22
	idx_t id;

23 24 25 26 27
	/*! \brief Cosntructor from id
	 *
	 * \param id
	 *
	 */
incardon's avatar
incardon committed
28 29 30 31 32
	rid(size_t id)
	:id(id)
	{}

	//! Constructor
33 34 35
	rid()
	:id(0)
	{}
incardon's avatar
incardon committed
36

37 38 39 40 41 42 43
	/*! \brief Compare two gid
	 *
	 * \param r gid to compare with
	 *
	 * \return the result for comparation
	 *
	 */
Pietro Incardona's avatar
Pietro Incardona committed
44 45 46 47 48
	inline bool operator<=(const rid & r) const
	{
		return id <= r.id;
	}

49 50 51 52 53 54 55
	/*! \brief Compare two gid
	 *
	 * \param r gid to compare with
	 *
	 * \return the result for comparation
	 *
	 */
Pietro Incardona's avatar
Pietro Incardona committed
56 57 58 59 60
	inline bool operator<(const rid & r) const
	{
		return id < r.id;
	}

61 62 63 64 65 66 67
	/*! \brief Subtract two gid
	 *
	 * \param i
	 *
	 * \return itself
	 *
	 */
Pietro Incardona's avatar
Pietro Incardona committed
68 69 70 71 72 73 74
	inline rid operator-(int i) const
	{
		struct rid tmp;
		tmp.id = id - i;
		return tmp;
	}

75 76 77 78 79 80 81
	/*! \brief Subtract two gid
	 *
	 * \param i gid to subtract
	 *
	 * \return itself
	 *
	 */
Pietro Incardona's avatar
Pietro Incardona committed
82 83 84 85 86 87 88
	inline rid operator-(struct rid i) const
	{
		struct rid tmp;
		tmp.id = id - i.id;
		return tmp;
	}

89 90 91 92 93 94 95
	/*! \brief Sum two gid
	 *
	 * \param i gid to subtract
	 *
	 * \return itself
	 *
	 */
Pietro Incardona's avatar
Pietro Incardona committed
96 97 98 99 100 101 102
	inline rid operator+(int i) const
	{
		struct rid tmp;
		tmp.id = id + i;
		return tmp;
	}

103 104 105 106 107 108 109
	/*! \brief Sum two gid
	 *
	 * \param i gid to sum
	 *
	 * \return itself
	 *
	 */
Pietro Incardona's avatar
Pietro Incardona committed
110 111 112 113 114 115
	inline rid & operator+=(const rid & i)
	{
		id += i.id;
		return *this;
	}

116 117 118 119 120
	/*! \brief Increment the id
	 *
	 * \return itself
	 *
	 */
Pietro Incardona's avatar
Pietro Incardona committed
121 122 123 124 125 126 127
	inline rid & operator++()
	{
		id++;

		return *this;
	}

128 129 130 131 132 133 134
	/*! \brief compare two ids
	 *
	 * \param r id to check with
	 *
	 * \return the result
	 *
	 */
Pietro Incardona's avatar
Pietro Incardona committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
	inline bool operator==(const rid & r) const
	{
		return id == r.id;
	}
};

/*! Here we define different the remapped-id
 *
 * rid, gid and lid are all unsigned long integer, and can be easily interchanged by mistake
 *  encapsulating avoid that this could happen. The second is readability, from the definition
 *  of function/structure we see immediately which id parameter accept/store
 *
 */
struct gid
{
	size_t id;
incardon's avatar
incardon committed
151 152 153 154 155 156 157 158

	//! Constructor
	gid(){};

	//! Constructor
	gid(size_t id)
	:id(id)
	{}
Pietro Incardona's avatar
Pietro Incardona committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
};

/*! Here we define different the remapped-id
 *
 * rid, gid and lid are all unsigned long integer, and can be easily interchanged by mistake
 *  encapsulating avoid that this could happen. The second is readability, from the definition
 *  of function/structure we see immediately which id parameter accept/store
 *
 */
struct lid
{
	size_t id;
};

// define hash map for gid rid and lid

namespace std
{
	template <>
	struct hash<rid>
	{
		inline std::size_t operator()(const rid& k) const
		{
			return k.id;
		}
	};

	template <>
	struct hash<gid>
	{
		inline std::size_t operator()(const gid& k) const
		{
			return k.id;
		}
	};

	template <>
	struct hash<lid>
	{
		inline std::size_t operator()(const lid& k) const
		{
			return k.id;
		}
	};

}


#endif /* SRC_GRAPH_IDS_HPP_ */