mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-04 08:50:41 +08:00
Added Builtin Voltage (#7850)
* Added Builtin Voltage * Update builtin_voltage.py * Update electronics/builtin_voltage.py Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com> * Update electronics/builtin_voltage.py Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Apply suggestions from code review Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Create elf.py Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
@ -2,19 +2,17 @@ def elf_hash(data: str) -> int:
|
||||
"""
|
||||
Implementation of ElfHash Algorithm, a variant of PJW hash function.
|
||||
|
||||
Returns:
|
||||
[int] -- [32 bit binary int]
|
||||
>>> elf_hash('lorem ipsum')
|
||||
253956621
|
||||
"""
|
||||
hash = x = 0
|
||||
hash_ = x = 0
|
||||
for letter in data:
|
||||
hash = (hash << 4) + ord(letter)
|
||||
x = hash & 0xF0000000
|
||||
hash_ = (hash_ << 4) + ord(letter)
|
||||
x = hash_ & 0xF0000000
|
||||
if x != 0:
|
||||
hash ^= x >> 24
|
||||
hash &= ~x
|
||||
return hash
|
||||
hash_ ^= x >> 24
|
||||
hash_ &= ~x
|
||||
return hash_
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user