Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/cassandra/storage.py
Show First 20 Lines • Show All 436 Lines • ▼ Show 20 Lines | ) -> Iterable[bytes]: | ||||
# Check if there is a found_content that matches all hashes in the | # Check if there is a found_content that matches all hashes in the | ||||
# missing_content. | # missing_content. | ||||
# This is functionally equivalent to 'for found_content in | # This is functionally equivalent to 'for found_content in | ||||
# found_contents', but runs almost in constant time (it is linear | # found_contents', but runs almost in constant time (it is linear | ||||
# in the number of hash collisions) instead of linear. | # in the number of hash collisions) instead of linear. | ||||
# This allows this function to run in linear time overall instead of | # This allows this function to run in linear time overall instead of | ||||
# quadratic. | # quadratic. | ||||
for found_content in found_contents_with_same_hash: | for found_content in found_contents_with_same_hash: | ||||
# check if the found_content.hashes() dictionary contains a superset | |||||
# of the (key, value) pairs in missing_content | |||||
if missing_content.items() <= found_content.hashes().items(): | if missing_content.items() <= found_content.hashes().items(): | ||||
# Found! | # Found! | ||||
break | break | ||||
else: | else: | ||||
# Not found | # Not found | ||||
yield missing_content[key_hash] | yield missing_content[key_hash] | ||||
@timed | @timed | ||||
▲ Show 20 Lines • Show All 1,297 Lines • Show Last 20 Lines |