Changeset - 71bf91201a18
[Not reviewed]
0 1 0
Christopher Esterhuyse - 5 years ago 2020-02-21 17:24:08
christopher.esterhuyse@gmail.com
laying out communications with bitmatrix
1 file changed with 8 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/runtime/experimental/api.rs
Show inline comments
 
@@ -550,101 +550,107 @@ impl Connected {
 
        // For every component, take its state and make a singleton machine
 
        for (component_index, component) in self.components.iter_mut().enumerate() {
 
            let machine = Machine { component_index, state: component.state.take().unwrap() };
 
            self.ephemeral.machines.push(machine);
 
        }
 
        // Grow property matrix. has |machines| entities and {to_run => 0, to_remove => 1} properties
 
        const PROP_TO_RUN: usize = 0;
 
        const PROP_TO_REMOVE: usize = 1;
 
        self.ephemeral
 
            .bit_matrix
 
            .grow_to(Pair { property: 2, entity: self.ephemeral.machines.len() as u32 });
 
        // Set to_run property for all existing machines
 
        self.ephemeral.bit_matrix.batch_mut(move |p| p[PROP_TO_RUN] = TRUE_CHUNK);
 

	
 
        /////////////
 
        // perform mono runs, adding and removing TO_RUN property bits
 
        let mut usize_buf = vec![];
 
        let mut another_pass = true;
 
        while another_pass {
 
            another_pass = false;
 
            let machine_index_iter = self
 
                .ephemeral
 
                .bit_matrix
 
                .iter_entities_where(&mut usize_buf, move |p| p[PROP_TO_RUN]);
 
            for machine_index in machine_index_iter {
 
                let machine = &mut self.ephemeral.machines[machine_index as usize];
 
                let component = self.components.get_occupied(machine.component_index).unwrap();
 
                let mut ctx = MonoCtx { another_pass: &mut another_pass };
 
                match machine.state.pre_sync_run(&mut ctx, &component.protocol) {
 
                    MonoBlocker::Inconsistent => todo!(),
 
                    MonoBlocker::ComponentExit => self
 
                        .ephemeral
 
                        .bit_matrix
 
                        .set(Pair { entity: machine_index, property: PROP_TO_REMOVE as u32 }),
 
                    MonoBlocker::SyncBlockStart => self
 
                        .ephemeral
 
                        .bit_matrix
 
                        .unset(Pair { entity: machine_index, property: PROP_TO_RUN as u32 }),
 
                }
 
            }
 
        }
 
        // no machines have property TO_RUN
 

	
 
        // from back to front, swap_remove all machines with PROP_TO_REMOVE
 
        let machine_index_iter = self
 
            .ephemeral
 
            .bit_matrix
 
            .iter_entities_where_rev(&mut usize_buf, move |p| p[PROP_TO_REMOVE]);
 
        self.ephemeral.bit_matrix = Default::default(); // clear matrix
 
        for machine_index in machine_index_iter {
 
            self.ephemeral.machines.swap_remove(machine_index as usize);
 
            let machine = self.ephemeral.machines.swap_remove(machine_index as usize);
 
            drop(machine);
 
        }
 

	
 
        // from now on, the number
 
        let matrix_bounds = Pair { entity: self.ephemeral.machines.len() as u32 * 2, property: 8 };
 
        self.ephemeral.bit_matrix = BitMatrix::new(matrix_bounds); // clear propertties
 

	
 
        // !!! TODO poly run until solution is found
 

	
 
        // logically destructure self so we can read and write to different fields interleaved...
 
        let solution_assignments: Vec<(ChannelId, bool)> = vec![];
 
        let Self {
 
            components,
 
            ephemeral: Ephemeral { bit_matrix, assignment_to_bit_property, usize_buf, machines },
 
            ..
 
        } = self;
 

	
 
        // !!!!!!! TODO MORE HERE
 

	
 
        let machine_index_iter = bit_matrix.iter_entities_where(usize_buf, move |p| {
 
            solution_assignments.iter().fold(TRUE_CHUNK, |chunk, assignment| {
 
                let &bit_property = assignment_to_bit_property.get(assignment).unwrap();
 
                chunk & p[bit_property]
 
            })
 
        });
 
        for machine_index in machine_index_iter {
 
            let machine = &machines[machine_index as usize];
 
            let component = &mut components.get_occupied_mut(machine.component_index).unwrap();
 
            component.state = Some(machine.state.clone());
 
            println!("visiting machine at index {:?}", machine_index);
 
        }
 
        self.ephemeral.clear();
 
        println!("B {:#?}", self);
 
        Ok(())
 
    }
 
    pub fn sync_subsets(
 
        &mut self,
 
        _inbuf: &mut [u8],
 
        _ops: &mut [PortOpRs],
 
        bit_subsets: &[&[usize]],
 
    ) -> Result<usize, ()> {
 
        for (batch_index, bit_subset) in bit_subsets.iter().enumerate() {
 
            println!("batch_index {:?}", batch_index);
 
            let chunk_iter = bit_subset.iter().copied();
 
            for index in BitChunkIter::new(chunk_iter) {
 
                println!("  index {:?}", index);
 
            }
 
        }
 
        Ok(0)
 
    }
 
}
 

	
 
macro_rules! bitslice {
 
    ($( $num:expr  ),*) => {{
 
        &[0 $( | (1usize << $num)  )*]
 
    }};
 
}
0 comments (0 inline, 0 general)