MCPcopy Create free account
hub / github.com/tensorflow/datasets / hash_key

Method hash_key

tensorflow_datasets/core/hashing.py:79–95  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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)

Callers 5

test_intsMethod · 0.95
test_asciiMethod · 0.95
test_backslashMethod · 0.95
_serialize_exampleMethod · 0.80
addMethod · 0.80

Calls 3

_to_bytesFunction · 0.70
copyMethod · 0.45
updateMethod · 0.45

Tested by 3

test_intsMethod · 0.76
test_asciiMethod · 0.76
test_backslashMethod · 0.76