#include #include using namespace std; // if true we use the unordered_map (hash table) for the mapping // from Coord to int otherwise use map (binary tree) #define HASH_TABLE false // 2 dimensional coordinate class Coord { public: int x,y; Coord(int x,int y) : x(x),y(y) {} }; // Coord stream operator, for printing std::ostream& operator<< (std::ostream &os, const Coord &c) { os<<"("< // Coord hash function, needed by CoordMap size_t hash_value(const Coord& c) { size_t x=c.x; size_t y=c.y; y<<=sizeof(size_t)*8/2; // bit shift to left half of the bits of size_t // so that different coords have different hash values return x^y; // xor bit operator } typedef boost::unordered_map CoordMap; // defines the map type used #else // use binary tree #include // Coord less than operator, needed by CoordMap bool operator< (const Coord& c1, const Coord &c2) { return (c1.y CoordMap; // defines the map type used #endif // CoordMap stream operator, for printing std::ostream& operator<< (std::ostream &os, const CoordMap &m) { for (CoordMap::const_iterator it=m.begin();it!=m.end();it++) os<first<<"=>"<second<<", "; return os; } int main() // demonstrates all needed map functionality { CoordMap coordMap; // the map cout<<"add some items (a coord that maps to an int):"<second<first; int i=it->second; cout<