ppvm_traits/config.rs
1// SPDX-FileCopyrightText: 2026 The PPVM Authors
2// SPDX-License-Identifier: Apache-2.0
3
4use std::hash::BuildHasher;
5
6use crate::traits::{ACMap, Coefficient, HashFinalize, PauliStorage, PauliWordTrait, Strategy};
7
8/// Compile-time configuration bundle for a `PauliSum`.
9///
10/// `Config` is a zero-cost generic dispatch mechanism: it pins down the
11/// storage backing (`Storage`), coefficient type (`Coeff`), truncation
12/// strategy (`Strategy`), hasher (`BuildHasher`), Pauli-word representation
13/// (`PauliWordType`), and concrete map (`Map`) used by a single
14/// `PauliSum` instantiation. Pre-built bundles live in the submodules
15/// (`fxhash`, `indexmap`, …); user code may define its own.
16pub trait Config: Clone {
17 /// Backing storage for an individual Pauli word — typically a `[u8; N]`
18 /// where `N` is the number of bytes packed.
19 type Storage: PauliStorage;
20 /// Numeric coefficient type (e.g. `f64`, `Complex<f64>`).
21 type Coeff: Coefficient;
22 /// Truncation strategy applied when
23 /// `PauliSum::truncate` runs.
24 type Strategy: Strategy;
25 /// Hasher used by the underlying map. It is also the hasher of the
26 /// [`PauliWordType`](Self::PauliWordType) keys, so it must declare its
27 /// cached-hash finalization via [`HashFinalize`].
28 type BuildHasher: BuildHasher + Clone + Default + HashFinalize;
29 /// Concrete [`PauliWordTrait`] implementation used as map keys.
30 type PauliWordType: PauliWordTrait;
31 /// Concrete map type satisfying [`ACMap`] over the chosen
32 /// storage / coefficient / hasher / word combination.
33 type Map: ACMap<Self::Storage, Self::Coeff, Self::BuildHasher, Self::PauliWordType>;
34}