寻找 C 中的数组(与链表)哈希表实现
我正在寻找 C 中的哈希表实现,它将其对象存储在(二维)数组而不是链接列表中。 即,如果发生冲突,导致冲突的对象将存储在下一个空闲行索引中,而不是推送到链表的头部和第一个元素。
另外,对象本身必须复制到哈希表中,而不是通过指针引用。 (对象不会在程序的整个生命周期中存在,但表却存在)。
我知道这样的实现可能会存在严重的效率缺陷,并且不是“散列的标准方式”,但当我致力于一个非常特殊的系统架构时,我需要这些特征。
谢谢
I'm looking for a hashtable implementation in C that stores its objects in (twodimensional) arrays rather than linked lists.
i.e. if a collision happens, the object that is causing the collision will be stored in the next free row index rather than pushed to the head and first element of a linked list.
plus, the objects themselves must be copied to the hashtable, rather than referenced by pointers. (the objects do not live for the whole lifetime of the program but the table does).
I know that such an implementation might have serious efficiency drawbacks and is not the "standard way of hashing" but as I work on a very special system-architecture i need those characteristics.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一个超级简单的实现:
不要忘记检查
MAX_MEMORY
。A super simple implementation:
Don't forget to check against
MAX_MEMORY
.我的猜测是您的系统不允许动态内存分配。因此,您需要预先定义适合您的数据的数组边界(对象总数和最大预期冲突),并另外为您的对象定义一个自定义哈希函数,因此最好实现您自己的哈希表。
My guess is your system does not allow for dynamic memory allocation. Therefore you will need to define up front array bounds that are reasonable for your data (number of total objects and maximum expected collisions) and additionally a custom hash function for your objects so it might be best to implement your own hash table.
它不是用 C 编写的,而是用 C++ 编写的,但请看一下 Google Sparse Hash -可能会给你一些想法。关键要求是所存储的对象有办法成为
null
。It's not in C but in C++, but take a look at Google Sparse Hash - might give you some ideas. The key requirement is that the object being stored has a way to be
null
.