Skip to main content

Performs binary search in binary files

Project description

Dichoseek

Dichoseek tests the membership of a n-byte encoded integer in a sorted binary file consisting of a succession of n-byte integers.

The name comes from the fact that the algorithm is a dichotomy (binary search) using the file seek function.

Instal

pip install dichoseek

Basic usage

Assuming that you are looking for a 4-byte unsigned integer (you can change this assumption):

from dichoseek import dichoseek
elem = 124
is_elem_in_file = dichoseek("path/to/file", elem)

Or using a file object:

from dichoseek import dichoseek
elem = 124
with open("path/to/file", "rb") as f:
  is_elem_in_file = dichoseek(f, elem)

Other parameters

  • block_size: number of bytes per integer. We assume that the size of the file is a multiple of this block_size. Default is 4.

  • block_interpretation_function is the function that is used to transform bytes into int. Default is unsigned, big-endian parsing: lambda b: int.from_bytes(b, byteorder="big").

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dichoseek-0.2.3.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file dichoseek-0.2.3.tar.gz.

File metadata

  • Download URL: dichoseek-0.2.3.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.63.0 CPython/3.8.10

File hashes

Hashes for dichoseek-0.2.3.tar.gz
Algorithm Hash digest
SHA256 3033a9f67f26fccbd49962235e5377c544aba890307b7a5bdc693b6c6f8277f1
MD5 7bac72b458937b5849dbeb80f5cb168e
BLAKE2b-256 5af13989711c13f9e0b01828f71fc5a834404fcee6ef45802d2da6364fb709c8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page