HashMap 和 HashTable 的区别纯粹在数据结构上 [英] Difference between HashMap and HashTable purely in Data Structures

查看:13
本文介绍了HashMap 和 HashTable 的区别纯粹在数据结构上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HashTableHashMap 之间有什么区别纯粹在数据结构的上下文中(而不是在 Java 或任何其他语言中)?

What is the difference between HashTable and HashMap purely in context of data structures (and not in Java or any other language)?

我看到人们在同一概念上交替使用这些术语.纯粹在数据结构的上下文中是否完全没有区别?

I have seen people using these terms interchangeably for the same concept. Does it have no difference at all purely in context of data structures?

推荐答案

在计算科学术语中,map 是从键到值的关联容器映射.换句话说,您可以执行for key K remember value V"之类的操作.然后为键 K 获取值".映射可以通过多种方式实现 - 例如,使用(可选平衡的)二叉树、哈希表,甚至是存储键/值的连续结构数组.

In Computing Science terminology, a map is an associative container mapping from a key to a value. In other words, you can do operations like "for key K remember value V" and later "for key K get the value". A map can be implemented in many ways - for example, with a (optionally balanced) binary tree, or a hash table, or even a contiguous array of structs storing the key/value.

哈希表是一种用于存储任意数据的结构,并且该数据不一定由单独的键和值组成.例如,我可以有一个包含值 { 1, 10, 33, 97 } 的哈希表,这些值将是它们自己的键.当没有与键不同的值时,这有时称为集合",而散列表实现称为散列集合".哈希表的定义质量是哈希函数从键数据计算数组索引,不同的键倾向于产生不同的索引,允许恒定时间访问数组元素可能包含键.这是一种实现/性能质量,而不是像定义 map 这样的功能质量.

A hash table is a structure for storing arbitrary data, and that data does not necessarily consist of a separate key and value. For example, I could have a hash table containing the values { 1, 10, 33, 97 }, which would be their own keys. When there is no value distinct from the key, this is sometimes known as a "set", and with a hash table implementation a "hash set". The defining quality of a hash table is that a hash function calculates an array index from the key data, with different keys tending to yield different indices, allowing constant time access to an array element likely to contain the key. That's an implementation / performance quality, rather than a functional quality like that defining a map.

因此,哈希表存储元素,每个元素不必由不同的键和值组件组成,但如果包含,那么它也是哈希映射.

So, a hash table stores elements, each of which need not consist of distinct key and value components, but if it does then it's also a hash map.

这篇关于HashMap 和 HashTable 的区别纯粹在数据结构上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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