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
37
38
39
40
41
use storage::BlockType;

/// Types that can be accessed as immutable arrays of integers of
/// limited width.
pub trait IntVector {
    /// The type of primitive value to represent elements.
    type Block: BlockType;

    /// The number of elements.
    fn len(&self) -> u64;

    /// Is the vector empty?
    #[inline]
    fn is_empty(&self) -> bool {
        self.len() == 0
    }

    /// The bit width of each element.
    fn element_bits(&self) -> usize;

    /// Fetches the value of the `index`th element.
    ///
    /// # Panics
    ///
    /// Panics if `index` is out of bounds.
    fn get(&self, index: u64) -> Self::Block;
}

/// Types that can be accessed as mutable arrays of integers of limited
/// width.
pub trait IntVectorMut: IntVector {
    /// Updates the value of the `index`th element.
    ///
    /// # Panics
    ///
    ///   - Panics if `index` is out of bounds.
    ///
    ///   - May panic (?) if `element_value` is too large to
    ///     fit in the element size. (TODO: What’s the right thing here?)
    fn set(&mut self, index: u64, value: Self::Block);
}