use std::ops::{BitOrAssign, Shl};
use num::Integer;
pub(crate) fn get_ctrl_mask<T: Integer + BitOrAssign + Shl<usize, Output = T>>(
control: &[usize],
) -> T {
let mut control_mask = T::zero();
for c in control {
control_mask |= T::one() << *c;
}
control_mask
}
pub(crate) const fn bit_flip(state: usize, index: usize) -> usize {
state ^ (1 << index)
}
use smallvec::SmallVec;
pub type StateKey = SmallVec<[u64; 2]>;
pub(crate) fn bit_flip_vec(mut state: StateKey, index: usize) -> StateKey {
let (outer_index, inner_index) = index.div_mod_floor(&64);
state[outer_index] = bit_flip(usize::try_from(state[outer_index]).unwrap(), inner_index) as u64;
state
}
pub(crate) const fn is_one_at(state: usize, target: usize) -> bool {
state & (1 << target) != 0
}
pub(crate) fn is_one_at_vec(state: &[u64], target: usize) -> bool {
let (outer_index, inner_index) = target.div_mod_floor(&64);
state[outer_index] & (1 << inner_index) != 0
}
pub(crate) fn ctrl_check_vec(state: &[u64], control: &[usize]) -> bool {
control.iter().all(|control| is_one_at_vec(state, *control))
}