谷歌的dense_hash_map在set_empty_key()函数中崩溃
我正在尝试使用 google dend_hash_map 来存储键值数据而不是 std:map。
当我使用 (int, int ) 对进行测试时,我设置了 set_empty_key(mymap, -2) 并且它起作用了。
但是,现在当我将它与我的 (hash, value) 对一起使用时,我设置了 set_empty_key (mymap -2) 或 set_empty_key(mymap, some_random_hash),在这两种情况下我的程序都会在 set_empty_key(); 中崩溃。
任何人都可以指导我吗?我该如何修复这个崩溃?
谢谢。
I am trying to use google dense_hash_map to store key value data instead of std:map.
When I tested with (int, int ) pair, I set the set_empty_key(mymap, -2) and it worked.
But, now when I use it with my (hash, value) pair, I set the set_empty_key (mymap -2) or set_empty_key(mymap, some_random_hash), in both the cases my program crashes in set_empty_key();.
Anyone can guide me with this? How can I fix this crash?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道您崩溃的确切原因,但是根据您的描述,我至少看到两个潜在的错误。
第一的。检查
key_type
和data_type
类型是否都是 POD 类型,并且不包含指向自身的指针。更具体地说(原始):第二。关于使用dense_hash_map。您需要设置一些特殊的“空”键值,该值永远不会用于存储在集合中的真实元素。此外,如果您要使用
erase()
,您需要为已删除的项目指定特殊的密钥,该密钥也永远不会用作实际存储的项目的密钥。这是此处完美描述的:
I don't know the exact reason of crash you've got, but, based on your description I see at least two potential mistakes.
First. Check that both
key_type
anddata_type
types are POD types and don't contain pointers to itself. More specifically (original):Second. Concerning using dense_hash_map. You need to set up some special "empty" key value which will never be used for real elements stored in your collection. Moreover if you are going to use
erase()
you need to specify special key for deleted items which also will never be used as key for real stored items.That is perfectly described here: