Returns 128 bits hash of given key. Args: key (bytes, string or anything convertible to a string): key to be hashed. If the key is a string, it will be encoded to bytes using utf-8. If the key is neither a string nor bytes, it will be converted to a str, then to by
(self, key: HashKey)
| 77 | self._md5 = hashlib.md5(_to_bytes(salt)) |
| 78 | |
| 79 | def hash_key(self, key: HashKey) -> int: |
| 80 | """Returns 128 bits hash of given key. |
| 81 | |
| 82 | Args: |
| 83 | key (bytes, string or anything convertible to a string): key to be hashed. |
| 84 | If the key is a string, it will be encoded to bytes using utf-8. If the |
| 85 | key is neither a string nor bytes, it will be converted to a str, then |
| 86 | to bytes. This means that `"1"` (str) and `1` (int) will have the same |
| 87 | hash. The intent of the hash being to shuffle keys, it is recommended |
| 88 | that all keys of a given set to shuffle use a single type. |
| 89 | |
| 90 | Returns: |
| 91 | 128 bits integer, hash of key. |
| 92 | """ |
| 93 | md5 = self._md5.copy() |
| 94 | md5.update(_to_bytes(key)) |
| 95 | return int(md5.hexdigest(), 16) |