To understand what a key/value database is, you must understand the data structure of the hash table.
Google searches for headlines:
A hash table (also known as a hash table) is a data structure that is accessed directly from a key code value, which means that it accesses records by mapping key code values to a location in the table to speed up the search.
This mapping function is called a hash function, and the array that holds the record is called the hash table.
Advantages of a hash table:
In the data structure, there is a time algorithm complexity O (n) concept to measure the efficiency of an algorithm in the advantages and disadvantages of time.
The ideal algorithm complexity of the hash table is O (1), that is, the use of a hash table to find a value, the system is used in the ideal time to set the value, which is its advantage.
So how does a hash table do that?
We define a very large ordered array, and want to get the value in the nth position of the array, its algorithm complexity is O (1).
A hash table uses a hashing function to convert the key value of the content that needs to be stored to a value in this ordered array, establishing a mapping between the stored content and the ordered array.
So, the next time we look at this value, we can just find the value of the array by using the same hash function to convert the key value.
Analogy Examples:
Suppose we want to make a storage structure that needs to store the characters in the Three Kingdoms, as well as their detailed information.
We use their names as key values for storage, such as: Liu Bei, Cao, Sun Quan, Guan Yu, Zhang Fei ... Wait a minute.
At this time, if we want to use the general method to find these heroes, we need to traverse the entire storage space, if these heroes total N, then the time algorithm complexity is O (n). Obviously if the n value is large, it takes a long time to find a hero each time. We first define a large array of ordered structures hashvalue[m], which is used to store the information of your heroes. Then write a hash function changetohashvalue (name), the specific contents of the function is not detailed, anyway, this function will be the name of the key value into a hashvalue[m] a subscript value x. You can then put the hero's information into the hashvalue[x]. This way, you can store all of your heroes ' information. Use the hash function Changetohashvalue (name) to get this subscript value when querying, so it is easy to get the message of this hero.
For example: Changetohashvalue (Liu Bei) is 10, then the Liu Bei is stored in HashValue [10]. When the query again using Changetohashvalue (Liu Bei) to get 10, this time we can easily find all the information of Liu Bei. In practical applications, if we want to store all heroes in the system, we need to define m>n. Is that the size of the array is larger than the amount of information that needs to be stored, so a hash table is a data structure that takes space for time.
then another problem arises:
When Changetohashvalue (Guan Yu) and Changetohashvalue (Zhang Fei) get the same value, are 250, we are not in the storage process will encounter trouble, how to arrange their two places (can not let two people fight, who won who stay there), This requires a way to resolve the conflict.
When this happens, we can deal with this, first store the Guan Yu, when Zhang Fei entered the system will find that Guan Yu is 250, then we add one, 251 won, this does not solve.
We look for Zhang Fei's time also, a look at 250 is not Zhang Fei, then add a 1, found.
At this time there is still a problem, the direct use of Changetohashvalue (Zhao Yun) for 251, Zhang Fei has taken his place early, then add 1 to 252 chant.
We found that when the probability of a hash function collision is high, a group of heroes may queue up after the value of 250. At this point, the time algorithm complexity is already not O (1) (so we say that ideally, the time algorithm complexity of the hash table is O (1)).
This means that the hash function is written as a key issue in the hash table and involves a statistical distribution of the stored value in the Hashtable. If the hash function is already defined, the conflict resolution becomes a key factor in changing the performance of the system. In fact, there are many ways to solve the problem of storage and lookup in conflict situations, not necessarily linear backward queuing, if there is a good hash table conflict resolution can greatly improve the efficiency of the system.