Skip to main content

ppvm_pauli_sum/config/
fx64hash.rs

1// SPDX-FileCopyrightText: 2026 The PPVM Authors
2// SPDX-License-Identifier: Apache-2.0
3
4use std::collections::HashMap;
5use std::marker::PhantomData;
6
7use ppvm_pauli_word::word::PauliWord;
8use ppvm_traits::config::Config;
9use ppvm_traits::traits::{Coefficient, NoStrategy, PauliWordTrait, Strategy};
10
11/// `HashMap`-backed [`Config`] with native-word (`[usize; N]`) storage and
12/// `FxHasher`.
13///
14/// The storage element is `usize`, i.e. the target's native machine word:
15/// `u64` on 64-bit targets (identical layout and performance to a hardcoded
16/// `[u64; N]`) and `u32` on 32-bit targets such as `wasm32`. Using `usize`
17/// rather than `u64` keeps this config available on every target — `bitvec`
18/// only implements `BitStore` for `u64` on 64-bit pointer widths, but always
19/// implements it for `usize`. (The `Byte8` name refers to the 64-bit word
20/// this config packs into on native targets.)
21#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
22pub struct Byte8<
23    const N: usize,
24    C: Coefficient,
25    St: Strategy = NoStrategy,
26    W: PauliWordTrait = PauliWord<[usize; N], fxhash::FxBuildHasher>,
27>(PhantomData<(C, St, W)>);
28
29impl<const N: usize, C: Coefficient, St: Strategy, W: PauliWordTrait> Config
30    for Byte8<N, C, St, W>
31{
32    type Storage = [usize; N];
33    type Coeff = C;
34    type BuildHasher = fxhash::FxBuildHasher;
35    type PauliWordType = W;
36    type Map = HashMap<W, C, Self::BuildHasher>;
37    type Strategy = St;
38}
39
40/// [`Byte8`] specialised to `f64` coefficients.
41pub type Byte8F64<const N: usize, St = NoStrategy> = Byte8<N, f64, St>;