1use crate::sse::Hamiltonian;
2
3pub(crate) struct Ham<'a, H, E>
5where
6 H: Fn(&[usize], usize, &[bool], &[bool]) -> f64,
7 E: Fn(usize) -> (&'a [usize], bool),
8{
9 h: H,
10 n_bonds: usize,
11 e_fn: E,
12}
13
14impl<'a, H, E> Ham<'a, H, E>
15where
16 H: Fn(&[usize], usize, &[bool], &[bool]) -> f64,
17 E: Fn(usize) -> (&'a [usize], bool),
18{
19 pub(crate) fn new(hamiltonian: H, edge_fn: E, num_bonds: usize) -> Self {
21 Self {
22 h: hamiltonian,
23 n_bonds: num_bonds,
24 e_fn: edge_fn,
25 }
26 }
27}
28
29impl<'a, H, E> Hamiltonian<'a> for Ham<'a, H, E>
30where
31 H: Fn(&[usize], usize, &[bool], &[bool]) -> f64,
32 E: Fn(usize) -> (&'a [usize], bool),
33{
34 fn hamiltonian(&self, vars: &[usize], bond: usize, inputs: &[bool], outputs: &[bool]) -> f64 {
35 (self.h)(vars, bond, inputs, outputs)
36 }
37
38 fn edge_fn(&self, bond: usize) -> (&'a [usize], bool) {
39 (self.e_fn)(bond)
40 }
41
42 fn num_bonds(&self) -> usize {
43 self.n_bonds
44 }
45}