Changeset - d72289ecc27b
[Not reviewed]
0 1 0
Christopher Esterhuyse - 5 years ago 2020-02-12 18:17:07
christopheresterhuyse@gmail.com
playing around with new predicate=>state,payload storages. toward faster querying but also toward deviation detection by way of intelligible error handling
1 file changed with 8 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/runtime/polyp.rs
Show inline comments
 
@@ -208,12 +208,14 @@ struct BitSetAndIter<'a> {
 
    sets: &'a [&'a [u32]],
 
    next_u32_index: usize, // invariant: in 0..32 while iterating
 
    next_bit_index: usize,
 
    cached: Option<u32>, // None <=> iterator is done
 
}
 
impl<'a> BitSetAndIter<'a> {
 
    /// a set of bitsets. the u32s of each are in ascending order of significant digits
 
    /// i.e., &[0,1] means {1<<32, 0} while &[0,1] is identical to &[1] and means {1}.
 
    fn new(sets: &'a [&'a [u32]]) -> Self {
 
        const EMPTY_SINGLETON: &[&[u32]] = &[&[]];
 
        let sets = if sets.is_empty() { EMPTY_SINGLETON } else { sets };
 
        Self { sets, next_u32_index: 0, next_bit_index: 0, cached: Self::nth_u32(sets, 0) }
 
    }
 
    fn nth_u32(sets: &'a [&'a [u32]], index: usize) -> Option<u32> {
 
@@ -229,12 +231,13 @@ impl<'a> BitSetAndIter<'a> {
 
    }
 
}
 
impl Iterator for BitSetAndIter<'_> {
 
    type Item = usize;
 
    fn next(&mut self) -> Option<Self::Item> {
 
        loop {
 
            println!("LOOP");
 
            // get cached chunk. If none exists, iterator is done.
 
            let mut chunk = self.cached?;
 
            if chunk == 0 {
 
                self.next_chunk();
 
                continue;
 
            }
 
@@ -244,12 +247,13 @@ impl Iterator for BitSetAndIter<'_> {
 
            #[inline(always)]
 
            fn shifty(chunk: &mut u32, shift_by: usize, next_bit_index: &mut usize) {
 
                if *chunk & ((1 << shift_by) - 1) == 0 {
 
                    *next_bit_index += shift_by;
 
                    *chunk >>= shift_by;
 
                }
 
                println!("{:#032b}", *chunk);
 
            }
 
            shifty(&mut chunk, 16, &mut self.next_bit_index);
 
            shifty(&mut chunk, 08, &mut self.next_bit_index);
 
            shifty(&mut chunk, 04, &mut self.next_bit_index);
 
            shifty(&mut chunk, 02, &mut self.next_bit_index);
 
            shifty(&mut chunk, 01, &mut self.next_bit_index);
 
@@ -268,13 +272,14 @@ impl Iterator for BitSetAndIter<'_> {
 
}
 

	
 
#[test]
 
fn test_bit_iter() {
 
    static SETS: &[&[u32]] = &[
 
        //
 
        &[0b100011000000100101101],
 
        &[0b100001000000000110100],
 
        &[0b100001000100010100110],
 
        &[0b1, 0b1, 0b1, 0b1, 0b1],
 
        &[0b1, 0b1, 0b1],
 
        &[0b1, 0b1, 0b0, 0b1],
 
        &[0b1, 0b1, 0b1, 0b1],
 
    ];
 
    let indices = BitSetAndIter::new(SETS).collect::<Vec<_>>();
 
    println!("indices {:?}", indices);
 
}
0 comments (0 inline, 0 general)