ruby - 为什么 Ruby 哈希被称为哈希,而不是映射、字典、表或关联数组?

标签 ruby language-design

在Ruby 中,有一个名为Hash 的内置类。 .根据the docs :

A Hash is a dictionary-like collection of unique keys and their values. Also called associative arrays, they are similar to Arrays, but where an Array uses integers as its index, a Hash allows you to use any object type.

...

A Hash can be easily created by using its implicit form:

grades = { "Jane Doe" => 10, "Jim Doe" => 6 }

所以基本上,它们是 associative arrays .如果是这样,那么为什么将它们称为哈希?在计算机科学中,术语“散列”不是通常用来指代通过 hash function 运行某些数据生成的某种数字或某种十六进制字符串吗? ?事实上,Ruby 对象甚至有一个名为 hash 的方法。它“为此对象生成一个 Fixnum 哈希值”。

我知道 Hash在 Ruby 中实现为 hash table ,但考虑到我上面所说的,似乎没有足够的理由在 TableMap 之类的东西上使用名称 Hash,特别是考虑到 Ruby 似乎没有任何其他内置的 associative arrays 实现.为什么选择这个名字?

最佳答案

Ruby 从 Perl 中汲取了大量灵感,Perl 将其称为散列。

更新:

由 Ruby 的创造者 Yukihiro Matsumoto 确认:https://twitter.com/yukihiro_matz/status/547516495249428480

关于ruby - 为什么 Ruby 哈希被称为哈希,而不是映射、字典、表或关联数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24293147/

相关文章:

ruby - Windows 上的 BlueCloth 错误

c# - VB.NET 中的 foreach 是否比 c# 中的更快?

php - 是什么让 PHP 比 Java 或 C# 慢?

language-design - 鸭子类型(duck typing),必须是动态的吗?

c - C宏有什么用?

Ruby 打印出带有可选数字的 float

ruby-on-rails - 如何使用 Ruby 从 Active Directory 中检索已删除的对象?

python - 解析的部分评估

javascript - 如何在 Rails 中自动获取元描述和关键字?

ruby - Ruby 中 yield 和 return 的使用