MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / pickle_hashing

Function pickle_hashing

monai/data/utils.py:1380–1398  ·  view source on GitHub ↗

Args: item: data item to be hashed protocol: protocol version used for pickling, defaults to `pickle.HIGHEST_PROTOCOL`. Returns: the corresponding hash key

(item, protocol=pickle.HIGHEST_PROTOCOL)

Source from the content-addressed store, hash-verified

1378
1379
1380def pickle_hashing(item, protocol=pickle.HIGHEST_PROTOCOL) -> bytes:
1381 """
1382
1383 Args:
1384 item: data item to be hashed
1385 protocol: protocol version used for pickling,
1386 defaults to `pickle.HIGHEST_PROTOCOL`.
1387
1388 Returns: the corresponding hash key
1389
1390 """
1391 cache_key = ""
1392 if sys.version_info.minor < 9:
1393 cache_key = hashlib.md5(pickle.dumps(sorted_dict(item), protocol=protocol)).hexdigest()
1394 else:
1395 cache_key = hashlib.md5(
1396 pickle.dumps(sorted_dict(item), protocol=protocol), usedforsecurity=False # type: ignore
1397 ).hexdigest()
1398 return f"{cache_key}".encode()
1399
1400
1401def sorted_dict(item, key=None, reverse=False):

Callers 1

test_pickleMethod · 0.90

Calls 2

sorted_dictFunction · 0.85
encodeMethod · 0.45

Tested by 1

test_pickleMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…