CityHash is a family of fast non-cryptographic hash functions for strings, originally developed by Google. FarmHash is a successor designed for improved performance and collision resistance on modern CPUs. This library, `python-cityhash`, provides Python bindings for both CityHash and FarmHash, enabling high-performance hashing in Python applications. It is currently at version 0.4.10 and receives updates for Python version compatibility and Cython build fixes.
pip install cityhashVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use CityHash and FarmHash functions. It highlights the necessity of encoding strings to bytes and converting integers to a fixed-size byte representation for consistent hashing.
Upgrade to Python 3 or pin the library version to <0.4.0 if Python 2 compatibility is essential.
Ensure all string inputs are explicitly encoded to bytes using a consistent encoding (e.g., `my_string.encode('utf-8')`).Convert integers to a fixed-size byte sequence: `integer_value.to_bytes(8, 'big')` (or 'little' depending on desired endianness).
For stream processing or incremental hashing needs, use a library that explicitly supports this feature (e.g., MetroHash or xxHash).
For cryptographic security requirements, use standard library `hashlib` functions (e.g., SHA256, Blake2b).
Use `numpy.ascontiguousarray()` to convert non-contiguous arrays before hashing: `cityhash.CityHash64(numpy.ascontiguousarray(arr))`.
pip install cityhash
Ensure you have a C++ compiler (e.g., build-essential on Linux, Xcode Command Line Tools on macOS, or Visual C++ Build Tools on Windows) and Python development headers installed. Then retry installation: On Linux/macOS: `sudo apt-get install build-essential python3-dev` (for Python 3) or `sudo yum install gcc-c++ python3-devel` On Windows: Install 'Desktop development with C++' workload from Visual Studio Installer. After dependencies are met: `pip install cityhash`
Encode your string to bytes before passing it to the hash function, typically using UTF-8 encoding. For example: `cityhash.CityHash64('your string'.encode('utf-8'))`Ensure you are using a Python version supported by the latest `cityhash` (currently Python 3.6+). Upgrade `pip` and `setuptools` to their latest versions: `pip install --upgrade pip setuptools wheel`. If the problem persists, ensure your C++ compiler and Python development headers are correctly configured and up-to-date for your Python installation.
No dependency data recorded yet.