如何在C中实现哈希表 [英] How to implement a Hash Table in C

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

问题描述



任何人都可以告诉我哪个ds最适合用C / C ++实现

哈希表


thanx。 in advanced

Hi
can anybody tell me that which ds will be best suited to implement a
hash table in C/C++

thanx. in advanced

推荐答案



" ravi" < dc ********** @ gmail.comwrote in message

news:11 ******************** **@i13g2000prf.googlegr oups.com ...

"ravi" <dc**********@gmail.comwrote in message
news:11**********************@i13g2000prf.googlegr oups.com...



任何人都可以告诉我哪些ds最适合实施一个用C / C ++表示的
哈希表


thanx。在高级
Hi
can anybody tell me that which ds will be best suited to implement a
hash table in C/C++

thanx. in advanced



哪个ds?

您可以在我的书基本算法中阅读所有关于哈希表的内容。哈希

表格章节是免费的。

-

免费游戏和编程好东西。
http://www.personal.leeds.ac.uk/~bgy1mm

Which ds?
You can read all about hash tables in my book, Basic Algorithms. The hash
tables chapter is free.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm


ravi写道:
ravi wrote:



任何人都可以告诉我哪个ds最适合用C / C ++实现一个

哈希表

thanx。 in advanced
Hi
can anybody tell me that which ds will be best suited to implement a
hash table in C/C++

thanx. in advanced



哈希表本身就是一个数据结构。它与哈希

函数一起使用。


< http://www.cs.auckland.ac.nz/software/AlgAnim/hash_tables。 html>

< http://www.cl.cam.ac.uk/~cwc22/hashtable/>

< http://www.monad .me.uk / algorithms / hash.html>

< http://cbfalconer.home.att.net/download/hashlib.zip>

< http ://en.wikipedia.org/wiki/Hash_table>

The hash table is itself a data structure. It works in conjunction with hash
function.

<http://www.cs.auckland.ac.nz/software/AlgAnim/hash_tables.html>
<http://www.cl.cam.ac.uk/~cwc22/hashtable/>
<http://www.monad.me.uk/algorithms/hash.html>
<http://cbfalconer.home.att.net/download/hashlib.zip>
<http://en.wikipedia.org/wiki/Hash_table>


" Malcolm McLean" < re ******* @ btinternet.comwrites:
"Malcolm McLean" <re*******@btinternet.comwrites:

" ravi" < dc ********** @ gmail.comwrote in message

news:11 ******************** **@i13g2000prf.googlegr oups.com ...
"ravi" <dc**********@gmail.comwrote in message
news:11**********************@i13g2000prf.googlegr oups.com...

>嗨
任何人都可以告诉我哪些ds最适合实现
C / C ++中的哈希表

thanx。在高级
>Hi
can anybody tell me that which ds will be best suited to implement a
hash table in C/C++

thanx. in advanced



哪个ds?

您可以在我的书基本算法中阅读所有关于哈希表的内容。

哈希表章节是免费的。

Which ds?
You can read all about hash tables in my book, Basic Algorithms. The
hash tables chapter is free.



我认为应该指出你的哈希表不像

最多。大多数哈希表都是动态结构,可以随着数据的增加而增长。你的是固定的。如果尝试在初始容量之外添加项目

,则界面应该有一个明确的警告

表失败(静默)。


我之前做的一点(当

表变满时函数循环无限期)仍然是正确的,但我现在看到添加函数

在达到这一点之前很久就会无声地失败。如果这个限制

是设计的,我认为文本应该非常清楚。


这是奇怪的(对初学者来说可能很混乱)添加

函数似乎返回成功/失败指示,但它确实没有用它来表示这个灾难性的情况。


[旁白:不应该有关于基本算法的书籍(或至少

描述)哈希表如何增长以容纳更多数据?]


到OP:

1)正确的哈希表可以随着数据的增加而增长。


2)add函数应该返回一个错误如果数据不能添加

- 例如,如果密钥已经存在,有些人会这样做但是如果操作会溢出分配的存储空间,那么肯定会是
。 br />

3)大多数设计师都会制作一个哈希表,至少在C中,没有重复密钥和数据。想法是将实际的

数据分配留给表用户。桌子本身只是
商店指针。


-

Ben。

I think it should be pointed out that your hash table is not like
most. Most hash tables are dynamic structures that can grow as data
are added. Yours is fixed. The interface should have a clear warning
that the table fails (silently) if an attempt is made to add an item
beyond the initial capacity.

The point I made before (that the function loop indefinitely when the
table becomes full) is still true, but I now see that the add function
will silently fail long before that point is reached. If this limit
is by design, I think the text should make that limitation very clear.

It is odd (and probably very confusing to a beginner) that the add
function seems to return a success/fail indication, but that it does
not use it to signal this disastrous case.

[Aside: shouldn''t a book on basic algorithms illustrate (or at least
describe) how a hash table can grow to accommodate more data?]

To the OP:
1) A proper hash table can grow as data are added.

2) The add function should return an error if the data can''t be added
-- for example, some do if the key already exists but it certainly
should if the operation would overflow allocated storage.

3) Most designers would make a hash table, in C at least, that did not
duplicate the key and the data. The idea being to leave the actual
data allocation up to the table user. The table itself would just
store pointers.

--
Ben.


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

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