为什么C标准库中没有哈希表? [英] Why are there no hashtables in the C standard library?

查看:116
本文介绍了为什么C标准库中没有哈希表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么标准C库中没有Hashtable支持?

Why is that there is no Hashtable support as part of Standard C Library? Is there any specific reason for this?

推荐答案

标准C库中没有哈希表,原因之一是:

There is no hashtable in the standard C library because either:


  • 没有人向工作组提交过提案;或

  • 工作组认为没有必要。

ISO就是这样工作的。提案被提出并被接受或拒绝。

That's the way ISO works. Proposals are put forward and accepted or rejected.

您必须小心添加到标准库中,因为您有两个相互冲突的组。作为用户,您可能希望将太阳下的每个数据结构都添加到标准中,以使该语言更有用。

You have to be careful what you add to the standard library since you have two conflicting groups. As a user, you might want every data structure under the sun to be added to the standard to make the language more useful.

但是,作为一种语言 implementor (顺便说一句,这些人可能是构成各个工作组中大多数的人,因此他们的观点可能会产生更大的影响),您真的不希望不必实施可能不是每个人都可以使用的东西的麻烦。 C89出现时出现的所有内容都与以下事实有关,即主要目的是编纂现有实践而不是引入新实践。从那时起,所有标准的迭代在执行功能上都比较自由,但是向后兼容仍然是一个重要的问题。

But, as a language implementor (as an aside, these are probably the people that tend to make up most of the various working groups so their view is likely to have more impact), you don't really want the hassle of having to implement stuff that may not be used by everyone. All the stuff that was there when C89 appeared was to do with the fact that the primary purpose was to codify existing practice rather than introduce new practices. All iterations of the standards since then have been a little freer in what they can do but backwards compatibility is still an important issue.

我自己,我也有冲突。我很想在Java中使用Java,C ++或Python库的所有功能。当然,这会使为新手学习所有内容变得更加困难,而且正如一位评论者所述,可能代码猴子可以抽出有用的代码,从而在此过程中降低我的价值:-)

Myself, I also have conflicts. I'd love to have all the features of the Java, C++ or Python libraries at my disposal in C. Of course, that would make it so much harder to learn everything for newcomers and, as one commenter stated, probably make it so any code monkey can pump out useful code, reducing my value in the process :-)

我几乎拥有我所有的数据结构在我漫长而辉煌的职业中,我将永远需要。您不仅限于这类资料的标准库。

And I pretty much have all the data structures I'll ever need, from my long and (mostly) illustrious career. You're not limited to the standard library for this sort of stuff. There are plenty of third-party tools you can get to do the job and (like me) you can also roll your own.

如果您想知道为什么某些决定,可以使用很多第三方工具来完成任务,并且(像我一样)也可以自己动手做。是在每次迭代中进行的,因此ISO(通常在ISO接管之前是ANSI)通常会发布基本原理文档。可以在此处找到ANSI的C89。它在范围内包含了这个小小的美感:

If you want to know why certain decisions were made in each iteration, ISO (and ANSI originally, before ISO took over) usually publish rationale documents. The C89 one from ANSI can be found here. It contains this little beauty in the scope:


此基本原理主要集中于对语言的补充,说明和更改,如基本文件。对于整个C语言来说,这并不是一个理由:委员会负责将现有的语言编成代码,而不是设计一种新的语言。在此基本原理中,未尝试捍卫该语言的现有语法,例如声明的语法或运算符的绑定。

This Rationale focuses primarily on additions, clarifications, and changes made to the language as described in the Base Documents. It is not a rationale for the C language as a whole: the Committee was charged with codifying an existing language, not designing a new one. No attempt is made in this Rationale to defend the pre-existing syntax of the language, such as the syntax of declarations or the binding of operators.

我特别喜欢承认他们不对任何可能在标准化之前的邪恶行为负责。

I especially enjoy the admission that they're not responsible for any unholy mess that may have predated their attempts to standardise.

但是,也许是对您的真正答案问题在于指导原则之一:

But, perhaps the real answer to your question lies in this bit, one of the guiding principles:

保持C的精神。委员会一直将保留C的传统精神作为主要目标。C的精神有很多方面,但是本质是C语言所基于的基本原则的共同体情感。 C精神的某些方面可以用以下短语概括:

Keep the spirit of C. The Committee kept as a major goal to preserve the traditional spirit of C. There are many facets of the spirit of C, but the essence is a community sentiment of the underlying principles upon which the C language is based. Some of the facets of the spirit of C can be summarized in phrases like:


  • 信任程序员。

  • 不要阻止程序员完成需要做的事情。

  • 使语言保持小巧简单。

  • 仅提供一种方式进行操作。

  • 即使不能保证可移植,也要使其快速运行。

  • Trust the programmer.
  • Don't prevent the programmer from doing what needs to be done.
  • Keep the language small and simple.
  • Provide only one way to do an operation.
  • Make it fast, even if it is not guaranteed to be portable.

第三个原因可能是图书馆未大规模扩展的主要原因通过最初的标准化工作-并且这样的扩展实际上可能导致ANSI C被标记为C2038而不是C89。

That third one is probably the main reason why the library wasn't massively expanded with the initial standardisation effort - that, and the fact that such an expansion from a committee would probably have resulted in ANSI C being labeled C2038 rather than C89.

这篇关于为什么C标准库中没有哈希表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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