1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct StackMap {
bits: Box<[u32]>,
mapped_words: u32,
}
impl StackMap {
pub fn new(mapped_words: u32, bits: impl Iterator<Item = u32>) -> StackMap {
StackMap {
bits: bits.collect(),
mapped_words,
}
}
pub fn get_bit(&self, bit_index: usize) -> bool {
assert!(bit_index < 32 * self.bits.len());
let word_index = bit_index / 32;
let word_offset = bit_index % 32;
(self.bits[word_index] & (1 << word_offset)) != 0
}
pub fn mapped_words(&self) -> u32 {
self.mapped_words
}
}