__gnu_cxx::hash_map 的key为pair ,value为 vector 出错??

herman011 2008-06-10 08:41:58
#include <ext/hash_map>
using __gnu_cxx::hash_map;

typedef std::pair <unsigned int, unsigned int> unsigned_pair;

struct snp_nt
{
char nt;
int read_id;
int read_misite;
};

int i=10,j=12,k=1;
struct snp_nt temp; temp.nt='a' ; temp.read_id=2;temp.read_missite=9;
hash_map <unsigned_pair,vector <snp_nt> > sites;

unsigned_pair p(i,j-k);
sites[p].push_back(temp);


编译 出错:


sites[p].push_back(temp); 这一行

还有 这里面 hashtable.h 和 hash_map :


size_type _M_bkt_num(const value_type& __obj, size_t __n) const
{
return _M_bkt_num_key(_M_get_key(__obj), __n);
}

_Tp& operator[](const key_type& __key) {
return _M_ht.find_or_insert(value_type(__key, _Tp())).second;
}

等 4处。。。。。。
...全文
302 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
herman011 2008-06-10
  • 打赏
  • 举报
回复
typedef std::pair <unsigned int, unsigned int> unsigned_pair;

struct snp_nt
{
char nt;
int read_id;
int read_misite;
};

struct compare_pair
{
bool operator()(const unsigned_pair p1, const unsigned_pair p2) const
{
return (p1.第一个数=p2.第一个数 && p1.第二个数=p2.第二个数); 这句怎么写啊?
}
};

typedef hash_map<unsigned_pair,vector<snp_nt>,hash <const unsigned_pair>,compare_pair> pair_vector_map;
NKLoveRene 2008-06-10
  • 打赏
  • 举报
回复
http://www.stlchina.org/twiki/bin/view.pl/Main/STLDetailHashMap#详细解说STL%20hash_map系列
herman011 2008-06-10
  • 打赏
  • 举报
回复
sites.insert(make_pair(p,snpv));

sites[p].push_back(temp);

前面那句不是保证了吗?

yuzl32 2008-06-10
  • 打赏
  • 举报
回复

int i=10,j=12,k=1;
struct snp_nt temp; temp.nt='a' ; temp.read_id=2;temp.read_missite=9;
hash_map <unsigned_pair,vector <snp_nt> > sites;

unsigned_pair p(i,j-k);
vector <snp_nt> snpv;

sites.insert(make_pair(p,snpv));

sites[p].push_back(temp); //要保证sites[p]是否存在!

yuzl32 2008-06-10
  • 打赏
  • 举报
回复

int i=10,j=12,k=1;
struct snp_nt temp; temp.nt='a' ; temp.read_id=2;temp.read_missite=9;
hash_map <unsigned_pair,vector <snp_nt> > sites;

unsigned_pair p(i,j-k);
vector <snp_nt> snpv;

sites.insert(make_pair(p(i,j-k),snpv));

sites[p].push_back(temp); //要保证sites[p]是否存在!

herman011 2008-06-10
  • 打赏
  • 举报
回复
楼上什么意思? 如果要实现这种功能,要怎么改?
hastings 2008-06-10
  • 打赏
  • 举报
回复
unsigned_pair没有提供<操作符,

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧