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

Function json_hashing

monai/data/utils.py:1360–1377  ·  view source on GitHub ↗

Args: item: data item to be hashed Returns: the corresponding hash key

(item)

Source from the content-addressed store, hash-verified

1358
1359
1360def json_hashing(item) -> bytes:
1361 """
1362
1363 Args:
1364 item: data item to be hashed
1365
1366 Returns: the corresponding hash key
1367
1368 """
1369 # TODO: Find way to hash transforms content as part of the cache
1370 cache_key = ""
1371 if sys.version_info.minor < 9:
1372 cache_key = hashlib.md5(json.dumps(item, sort_keys=True).encode("utf-8")).hexdigest()
1373 else:
1374 cache_key = hashlib.md5(
1375 json.dumps(item, sort_keys=True).encode("utf-8"), usedforsecurity=False # type: ignore
1376 ).hexdigest()
1377 return f"{cache_key}".encode()
1378
1379
1380def pickle_hashing(item, protocol=pickle.HIGHEST_PROTOCOL) -> bytes:

Callers 2

test_pickleMethod · 0.90
test_jsonMethod · 0.90

Calls 1

encodeMethod · 0.45

Tested by 2

test_pickleMethod · 0.72
test_jsonMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…