[TIL] What is Hash Map

Jiwan Jeon·2022년 1월 12일
1

TIL

목록 보기
6/7
post-thumbnail

Hash Map

  • Type of data structure that stores key-value pairs
  • Retrieve a certain value by using the key for that value
  • A hash Table transforms a key into an integerr index using a hash function, and the index will decide where to store key/value pairr memory

Big O

: fast search, insertion, and delete operations

Hash Table in JS

  • Create a HashTable class with table and size initial properties
  • Add a hash() function to transform keys into indices
  • Add the set() and get() methods for adding and retrieving key/value pairs from the table.

Test the Code

How to Hnadle Index Collision

Sometimes, the hash function in a Hash Table may return the same index number. In the test case above, the string "Spain" and "ǻ" both return the same hash value because the number 507 is the sum of both of their ASCII code.

The same hash value will cause the index to collide, overwriting the previous entry with the new one.

To handle the index number collision, you need to store the key/value pair in a second array so that the end result looks as follows:

To Create Second Array

: We need to upadate set, get, remove function

profile
Jiwan Jeon

4개의 댓글

comment-user-thumbnail
2022년 1월 12일

Wow!! Good summary for hash!! :)

답글 달기
comment-user-thumbnail
2022년 1월 13일

크 영어로 작성. 지리네요!!!

답글 달기
comment-user-thumbnail
2023년 4월 5일

who need help improving their coding skills bubble slides, daily game solve cross

답글 달기
comment-user-thumbnail
2023년 5월 24일

If you're moving to or from a rural area, you may need to pay more for transport, as there may be fewer carriers servicing those areas. Additionally, if you need door-to-door service, you may need to pay extra for the convenience.
https://www.youtube.com/watch?v=kRNUVD760WM

답글 달기