mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-09 21:56:47 +08:00
Set the Python file maximum line length to 88 characters (#2122)
* flake8 --max-line-length=88 * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -1,13 +1,17 @@
|
||||
"""
|
||||
This algorithm was created for sdbm (a public-domain reimplementation of ndbm) database library.
|
||||
It was found to do well in scrambling bits, causing better distribution of the keys and fewer splits.
|
||||
This algorithm was created for sdbm (a public-domain reimplementation of ndbm)
|
||||
database library.
|
||||
It was found to do well in scrambling bits, causing better distribution of the keys
|
||||
and fewer splits.
|
||||
It also happens to be a good general hashing function with good distribution.
|
||||
The actual function (pseudo code) is:
|
||||
for i in i..len(str):
|
||||
hash(i) = hash(i - 1) * 65599 + str[i];
|
||||
|
||||
What is included below is the faster version used in gawk. [there is even a faster, duff-device version]
|
||||
The magic constant 65599 was picked out of thin air while experimenting with different constants.
|
||||
What is included below is the faster version used in gawk. [there is even a faster,
|
||||
duff-device version]
|
||||
The magic constant 65599 was picked out of thin air while experimenting with
|
||||
different constants.
|
||||
It turns out to be a prime.
|
||||
This is one of the algorithms used in berkeley db (see sleepycat) and elsewhere.
|
||||
|
||||
@ -18,7 +22,8 @@
|
||||
def sdbm(plain_text: str) -> str:
|
||||
"""
|
||||
Function implements sdbm hash, easy to use, great for bits scrambling.
|
||||
iterates over each character in the given string and applies function to each of them.
|
||||
iterates over each character in the given string and applies function to each of
|
||||
them.
|
||||
|
||||
>>> sdbm('Algorithms')
|
||||
1462174910723540325254304520539387479031000036
|
||||
|
Reference in New Issue
Block a user