Home >Web Front-end >Front-end Q&A >Is there hash in javascript?
There is hash in JavaScript. Hash refers to "hash table", which is a data structure that directly accesses the memory storage location based on keywords; JavaScript uses the hash table to establish a certain correspondence between the storage location of the data element and the keyword of the data element. , the function that establishes this correspondence is called a hash function.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
In javascript, hash refers to the hash table, which is a data structure that directly accesses the memory storage location based on keywords; through the hash table, data A certain correspondence is established between the storage location of the element and the key of the data element. The function that establishes this correspondence is called a hash function.
hash is a value assignment method with many meanings. The knowledge and methods searched are also very complicated, but the actual use does not need to be too complicated. Diandian, the writing method is also very simple. There are many ways to write hash.
my hash = {}←Object { } my hash = { "a" : 1}← >Object { a: 1 } my hash.a← 1 > my_hash['a']←1 my_hash = { b: 2}← >Object { b: 2} my hash = { a:l, b: 2} ←>Object { a: 1. b:2} > my_hash.a← 1 > my_hash['a' ]← 1
Construction method of hash table:
Assume that the number of data elements to be stored is n, and set a length of m(m > n) consecutive storage units, respectively, using the keyword Ki (0
From a mathematical point of view, the hash function is actually a mapping of keywords to memory units, so we hope that the Huaxi address calculated by the hash function will be as uniform as possible through the simplest operation possible. Back mapping to a series of memory units, there are three key points in constructing a hash function:
(1) The operation process should be as simple and efficient as possible to improve the insertion and retrieval efficiency of the hash table;
(2) The hash function should have a better hash type to reduce the probability of hash collision;
(3) The hash function should have greater compression to save memory.
【Related recommendations: javascript video tutorial, web front-end】
The above is the detailed content of Is there hash in javascript?. For more information, please follow other related articles on the PHP Chinese website!