哈希实现_如何实现哈希图

哈希实现

Arrays are amazing for looking up elements at specific indices as all elements in memory are contiguous, allowing for O(1) or constant time lookups. But often we don't, or can't, perform lookups via indices. Hash maps and hash tables are a way around this, enabling us to lookup via keys instead.

数组非常适合在特定索引处查找元素,因为内存中的所有元素都是连续的,允许进行O(1)或恒定时间的查找。 但是,我们经常不通过索引进行查找,或者不能通过索引进行查找。 哈希映射和哈希表是解决此问题的一种方法,使我们能够通过keys进行查找。

Can you implement the Map class from scratch? Only two methods are necessary-- get and set. Many programming languages have a built-in hash or dictionary primitive (like Javascript Objects and {} notation), but we don't want to use that for this exercise.

您可以从头开始实现Map类吗? 仅需要两种方法getset 。 许多编程语言都有内置的哈希或字典原语(例如Javascript Object{}表示法),但是我们不想在本练习中使用它。

This lesson was originally published at https://algodaily.com, where I maintain a technical interview course and write think-pieces for ambitious developers.

本课程最初在 https://algodaily.com上 发布 ,我 那里维护技术面试课程,并为雄心勃勃的开发人员撰写思想著作。

Note: Regular Javascript objects and the Map class are both simple key-value hash tables/associative arrays, with a few key differences:

注意:常规Javascript对象和Map类都是简单的键值哈希表/关联数组,但有一些关键区别:

A Map object can iterate through its elements in insertion order, whereas JavaScript's Objects don't guarantee order. In addition, Objects have default keys due to their prototype, and Maps don't come with default keys. Here's a good breakdown of the two. For the purpose of this exercise, let's assume the same functionality for both.

一个 Map 对象可通过其插入顺序的元素迭代,而JavaScript的 Object ,说自己是为了保证。 另外, 由于 Object 的原型

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值