存储和散列的最佳方式键 (C++)
我的目标是创建一个有效的结构来存储矩阵中最相关的条目,该矩阵(在没有内存限制的情况下)大约为 10^5 x 10^5 并填充双精度数。该矩阵是对称的,因此它实际上只包含 (10^10)/2 个值。
我需要在模拟中多次访问条目,因此快速检索至关重要。
为了保持结构的可管理性,我将删除不太可能使用的成员。如果索引是 (int_x1, int_x2),我经常想要删除所有包含 x1 的对。
这项任务的最佳结构或结构集是什么?对于两个整数来说,什么是好的哈希值?
为了可移植性,我想避免使用 Boost。我目前在程序的其他地方使用 TR1 的 unordered_map 。我正在考虑再次使用 unordered_map 与密钥对,但我不确定如何能够以这种方式有效地删除条目,而且我不知道一个好的哈希函数会是什么样子。
我是一名初级程序员,所以请说明显而易见的事情。
My goal is to create an efficient structure to store the most relevant entries of a matrix that would (in a world without memory limitations) be approximately 10^5 x 10^5 and filled with doubles. The matrix is symmetric, so it actually would contain only (10^10)/2 values.
I need to access entries many, many times in my simulation, so fast retrieval is critical.
To keep the structure manageable, I will delete members that are unlikely to be used. If the index is (int_x1, int_x2), I will often want to delete all pairs containing, e.g., x1.
What is the best structure or set of structures for this task? What is a good hash for two ints?
For portability, I would like to avoid Boost. I am currently using TR1's unordered_map elsewhere in the program. I was thinking of using unordered_map again with the key pair, but I'm not sure how I would be able to delete entries efficiently this way, and I don't know what a good hash function would look like.
I'm a beginning programmer, so please state the obvious.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果数据非常稀疏,您可以使用哈希表数组。
然后,要查找值 (x,y),请使用 x 索引数组并在哈希表中查找 y。
需要注意的一些事情:
If the data is going to be pretty sparse, you could use an array of hash tables.
Then to look up a value (x,y), you index the array with x and look up y in the hash table.
A few things to watch out for: