Implementation of djb2 hash algorithm that is popular because of it's magic constants. >>> djb2('Algorithms') 3782405311 >>> djb2('scramble bits') 1609059040
(s: str)
| 19 | |
| 20 | |
| 21 | def djb2(s: str) -> int: |
| 22 | """ |
| 23 | Implementation of djb2 hash algorithm that |
| 24 | is popular because of it's magic constants. |
| 25 | |
| 26 | >>> djb2('Algorithms') |
| 27 | 3782405311 |
| 28 | |
| 29 | >>> djb2('scramble bits') |
| 30 | 1609059040 |
| 31 | """ |
| 32 | hash_value = 5381 |
| 33 | for x in s: |
| 34 | hash_value = ((hash_value << 5) + hash_value) + ord(x) |
| 35 | return hash_value & 0xFFFFFFFF |
nothing calls this directly
no outgoing calls
no test coverage detected