Features and use hash table

Secure Hash Algorithm (secure hash algorithm, SHA) function; Given a string, SHA anti-return its hash value.

SHA can be used to determine whether two identical documents.

SHA-0, SHA-1, SHA-2, SHA-3>

Most secure cryptographic hash function: bcrypt.

Hash function time complexity is O (1).

A hash function that maps the input digital;

The hash function always maps to the same input of the same index.

Hash function different inputs are mapped to different indexes.

You know how much hash function array, returns only valid index.

Hash function and hash table may be created an array, a hash table data structure comprises an additional logic.

Array and list are directly mapped into memory, the hash table using the hash function to determine the location of the storage element.

The hash key and a value mapped to the key value.

Python provides a dictionary to implement a hash table.

Hash table can achieve DNS resolution function.

Hash table in terms of checking whether duplicate very fast (dict get method).

voted = {}
def check_voter(name):
if voted.get(name):
print("kick it out!")
else:
voted[name] = True
print("allow it to vote!")


if __name__ == '__main__':
check_voter("hello")
check_voter("hello")

Hash table in cache

Cache works: the site will remember the data no longer recalculated.

Cache is a common way to accelerate the large sites are using the cache, the cached data is stored in a hash table.

Cache maps a URL to a page of data.

Web site access model:

cache = {}
def get_page(url):
if cache.get(url):
return cache[url]
else:
data = get_data_from_server(url)
cache[url] = data
return data


if __name__ == '__main__':
get_page(xxx_url)

Guess you like

Origin www.cnblogs.com/songyuejie/p/11374277.html