您的位置:首页 > 其它

hash_map的使用备忘

2011-04-15 15:31 190 查看
Windows上

定义一个类,重载两个操作符(此class 转自某csdn网友)

class hash_comp { public: enum { bucket_size = 4, min_buckets = 8 }; bool operator () (const Point &p1,const Point &p2)const { if (p1.distanceTo(p2) < dZERO) { return true; } return false; } size_t operator()(const Point &pt)const { unsigned long nhash = sqrt(pt.x * pt.x + pt.y * pt.y) * 1000; return (size_t) nhash; } };


然后 stdext::hash_map<KEY, VALUE>

Mac上

定义两个类,各自重载一个操作符(突然觉得似乎可以定义一个,待会再试试)

class hash_fun
{
public:
size_t operator() (const KEY& pt) const
{
...
return (size_t)nhash;
}
};

class hash_eq
{
public:
bool operator() (const KEY& k1, const KEY& k2) const
{
if (...)
{
return true;
}

return false;
}
};


然后 std::hash_map<KEY, VAL>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: