Changeset View
Changeset View
Standalone View
Standalone View
swh/journal/replay.py
Show First 20 Lines • Show All 255 Lines • ▼ Show 20 Lines | def is_hash_in_bytearray(hash_, array, nb_hashes, hash_size=SHA1_SIZE): | ||||
""" | """ | ||||
Checks if the given hash is in the provided `array`. The array must be | Checks if the given hash is in the provided `array`. The array must be | ||||
a *sorted* list of sha1 hashes, and contain `nb_hashes` hashes | a *sorted* list of sha1 hashes, and contain `nb_hashes` hashes | ||||
(so its size must by `nb_hashes*hash_size` bytes). | (so its size must by `nb_hashes*hash_size` bytes). | ||||
Args: | Args: | ||||
hash_ (bytes): the hash to look for | hash_ (bytes): the hash to look for | ||||
array (bytes): a sorted concatenated array of hashes (may be of | array (bytes): a sorted concatenated array of hashes (may be of | ||||
any type supporting slice indexing, eg. :py:cls:`mmap.mmap`) | any type supporting slice indexing, eg. :class:`mmap.mmap`) | ||||
nb_hashes (int): number of hashes in the array | nb_hashes (int): number of hashes in the array | ||||
hash_size (int): size of a hash (defaults to 20, for SHA1) | hash_size (int): size of a hash (defaults to 20, for SHA1) | ||||
Example: | Example: | ||||
>>> import os | >>> import os | ||||
>>> hash1 = os.urandom(20) | >>> hash1 = os.urandom(20) | ||||
>>> hash2 = os.urandom(20) | >>> hash2 = os.urandom(20) | ||||
▲ Show 20 Lines • Show All 144 Lines • Show Last 20 Lines |