honeycomb_core/cmap/components/
unused.rs1use std::{
2 ops::{Index, IndexMut},
3 slice::Iter,
4};
5
6#[cfg(feature = "par-internals")]
7use rayon::prelude::*;
8
9use crate::stm::TVar;
10
11use super::identifiers::DartIdType;
12
13pub struct UnusedDarts(Vec<TVar<bool>>);
15
16#[allow(unused)]
17impl UnusedDarts {
18 #[cfg(not(feature = "par-internals"))]
19 pub fn new(n_darts: usize) -> Self {
21 Self((0..n_darts).map(|_| TVar::new(false)).collect())
22 }
23
24 #[cfg(feature = "par-internals")]
25 pub fn new(n_darts: usize) -> Self {
27 Self(
28 (0..n_darts)
29 .into_par_iter()
30 .map(|_| TVar::new(false))
31 .collect(),
32 )
33 }
34
35 #[cfg(not(feature = "par-internals"))]
36 pub fn extend_with(&mut self, len: usize, val: bool) {
38 self.0.extend((0..len).map(|_| TVar::new(val)));
39 }
40
41 #[cfg(feature = "par-internals")]
42 pub fn extend_with(&mut self, len: usize, val: bool) {
44 self.0
45 .par_extend((0..len).into_par_iter().map(|_| TVar::new(val)));
46 }
47
48 pub fn len(&self) -> usize {
50 self.0.len()
51 }
52
53 pub fn iter(&self) -> Iter<'_, TVar<bool>> {
54 self.0.iter()
55 }
56}
57
58impl Index<DartIdType> for UnusedDarts {
59 type Output = TVar<bool>;
60
61 fn index(&self, dart_id: DartIdType) -> &Self::Output {
62 &self.0[dart_id as usize]
63 }
64}
65
66impl IndexMut<DartIdType> for UnusedDarts {
67 fn index_mut(&mut self, dart_id: DartIdType) -> &mut Self::Output {
68 &mut self.0[dart_id as usize]
69 }
70}