pthash 0.4.0

Rust bindings for PTHash
Documentation
// Copyright (C) 2024 The Software Heritage developers
// See the AUTHORS file at the top-level directory of this distribution
// License: GNU General Public License version 3, or any later version
// See top-level LICENSE file for more information

use std::pin::Pin;

use cxx::{Exception, UniquePtr};

use crate::build::Builder;
use crate::encoders::*;
use crate::hashing::Hash;

type Result<T> = std::result::Result<T, Exception>;

// Contains a cxx::bridge generated by build.rs, with a concrete C++ structure
// and an implementation of the `BackendPhf` trait for that structure.
include!(concat!(env!("OUT_DIR"), "/backends_codegen.rs.inc"));

pub(crate) trait BackendPhf: Sized + cxx::memory::UniquePtrTarget {
    type Hash: Hash;
    type Encoder: Encoder;
    type Builder: Builder<Hash = Self::Hash>;

    fn new() -> UniquePtr<Self>;
    fn position(&self, hash: Self::Hash) -> u64;
    fn num_bits(&self) -> usize;
    fn num_keys(&self) -> u64;
    fn table_size(&self) -> u64;
    fn seed(&self) -> u64;

    fn build(
        self: Pin<&mut Self>,
        builder: &Self::Builder,
        config: &ffi::build_configuration,
    ) -> Result<f64>;

    unsafe fn save(self: Pin<&mut Self>, filename: *const i8) -> Result<usize>;
    unsafe fn load(self: Pin<&mut Self>, filename: *const i8) -> Result<usize>;
}