-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocation.h
56 lines (43 loc) · 1.01 KB
/
Location.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef LOCATION_H_
#define LOCATION_H_
#include <iostream>
enum { LocInf = 999999 };
/*
struct for representing locations in the grid.
*/
struct Location
{
int row, col;
Location()
:row(0), col(0)
{ }
Location(int r, int c)
:row(r), col(c)
{ }
Location(const Location &other)
:row(other.row), col(other.col)
{ }
bool operator < (const Location &other) const
{
return (row == other.row ? (col < other.col) : (row < other.row));
}
bool operator == (const Location &other) const
{
return row == other.row && col == other.col;
}
};
struct LocationHash {
inline size_t operator () (const Location &loc) const
{
return loc.col + loc.row * 256;
}
};
#if 0
#include <tr1/unordered_set>
typedef std::tr1::unordered_set<Location, LocationHash> LocationSet;
#else
#include <set>
typedef std::set<Location> LocationSet;
#endif
std::ostream& operator<<(std::ostream &os, const Location &loc);
#endif //LOCATION_H_