// exam1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <hash_map>
#include <cv.h>
#include <iostream>
using namespace std;
struct pt_hash
{
static const size_t bucket_size = 4;
static const size_t min_buckets = 8;
//哈希值函数
size_t operator()(const CvPoint2D32f &pt)const
{
return pt.x*2+pt.y;
}
//小于号比较函数
bool operator()(const CvPoint2D32f &pt1,const CvPoint2D32f &pt2)const
{
if(pt1.x<pt2.x)
return true;
else if(pt1.x>pt2.x)
return false;
else
{
return pt1.y<pt2.y;
}
}
};
int main()
{
hash_multimap<CvPoint2D32f,string,pt_hash> map;
pair<CvPoint2D32f,string> p;
CvPoint2D32f pt;
pt.x=100.12;
pt.y=200.23;
p.first=pt;
p.second="cjc";
map.insert(p);
pt.x=300;
pt.y=400;
p.first=pt;
p.second="cxc";
map.insert(p);
pt.x=100.12;
pt.y=200.23;
p.first=pt;
p.second="cxc";
map.insert(p);
cout<<map.size()<<endl;
hash_multimap<CvPoint2D32f,string,pt_hash>::iterator be=map.lower_bound(pt),
ed=map.upper_bound(pt),it;
for(it=be;it!=ed;it++)
{
cout<<it->second<<endl;
}
system("pause");
return 0;
}