寻找在C好的哈希表实现 [英] Looking for a good hash table implementation in C

查看:175
本文介绍了寻找在C好的哈希表实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在字符串键感兴趣。有人能指出我朝着库?

I am primarily interested in string keys. Can someone point me towards a library?

推荐答案

我有同样的需求,并做了一些研究,并最终使用的 libcfu

I had the same need and did some research and ended up using libcfu

它的简单性和可读性,所以如果我有需要修改,​​我可以不用花太多时间去了解。这是BSD许可证也。无需更改我的结构(以嵌入说下一个指针)

It's simple and readable so if I have a need to modify, I can do it without spending too much time to understand. It's also of BSD license. No need to change my structs (to embed say a next pointer)

我不得不拒绝理由如下其他选项(我个人的原因,情况因人而异):

I had to reject the other options for following reasons (my personal reasons, YMMV):


  • sglib - >这是一个宏观的迷宫,我是不舒服的调试/制作
    只用宏这样的code碱基变化

  • cbfalconer - >很多牌redflags,而网站已经关闭,并在有关支持/作者网站太多不利的讨论;不想冒这个风险

  • 谷歌sparce哈希 - >如前所述,它是C ++,不是C

  • 油嘴滑舌(GNOME哈希) - >看起来非常有前途的;但我无法找到任何简单的方法来安装开发工具包;我只需要在C例程/文件 - 而不是完全成熟的研究与开发环境

  • 朱迪 - >似乎是一个简单的使用太复杂..还没有准备调试自己,如果我不得不遇到任何问题

  • npsml(这里提到) - >无法找到源

  • strmap 发现非常简单而有用的 - 它只是过于简单化,这两个键和值必须是字符串;值为字符串似乎过于严格(应该接受的void *)

  • uthash - >似乎不错(已经提到在维基百科上的哈希表);发现它需要结构被修改 - 不想做,因为服务表现是不是真的为我用一个问题--IT是更多的发展速度。

  • sglib --> it's a macro maze and I wasn't comfortable debugging/making changes on such a code base using just macros
  • cbfalconer --> lot of licensing redflags, and the site was down and too many unfavorable discussions on web about support/author; didn't want to take the risk
  • google sparce-hash --> as stated already, it's for C++, not C
  • glib (gnome hash) --> looked very promising; but I couldn't find any easy way to install the developer kit; I just needed the C routines/files -- not the full blown developement environment
  • Judy --> seems too complex for a simple use.. also was not ready to debug myself if I had to run into any issues
  • npsml (mentioned here) --> can't find the source
  • strmap found very simple and useful -- it's just too simplistic that both key and value must be strings; value being string seems too restrictive (should accept void *)
  • uthash --> seems good (has been mentioned on wikipedia on hashtable); found that it requires struct to be modified -- didn't want to do that as performace is not really a concern for my use --it's more of development velocity.

在摘要非常简单的应用strmap好;如果您担心额外的内存使用uthash。如果开发或易用性不仅仅是速度是首要目标,libcfu胜[注意libcfu内部做内存分配,以保持节点/哈希表。令人惊讶的是有可用的不是很多简单的C哈希实现。

In summary for very simple use strmap is good; uthash if you are concerned with additional memory use. If just speed of development or ease of use is primary objective, libcfu wins [note libcfu internally does memory allocation to maintain the nodes/hashtables]. It's surprising that there aren't many simple C hash implementations available.

这篇关于寻找在C好的哈希表实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆