Struct graph_csr::compute::ComputeGraph
source · [−]pub struct ComputeGraph<'a, T, DataType> { /* private fields */ }Expand description
This is the compute abstraction over a graph.
It contains an underlying representation of the data that can support running algorithms over it.
Each node contains DataType data, and a status indicating whether or not it is active in the next iteration.
Its methods are parallelized using atomics, and will yield good multi-threaded performance.
Implementations
sourceimpl<'a, T, DataType> ComputeGraph<'a, T, DataType> where
T: ValidGraphType + Send + Sync,
DataType: GraphData,
impl<'a, T, DataType> ComputeGraph<'a, T, DataType> where
T: ValidGraphType + Send + Sync,
DataType: GraphData,
sourcepub fn new(graph: &'a Graph<'a, T>) -> Self
pub fn new(graph: &'a Graph<'a, T>) -> Self
Creates a new graph that can run algorithms and can keep track of node data as well as the active nodes.
sourcepub fn set_active(&mut self, idx: usize, status: bool)
pub fn set_active(&mut self, idx: usize, status: bool)
Set a single node’s activity in the next iteration as status.
sourcepub fn set_data(&mut self, idx: usize, data: DataType)
pub fn set_data(&mut self, idx: usize, data: DataType)
Sets a single node’s data in the next iteration as data.
sourcepub fn fill_active(&mut self, status: bool)
pub fn fill_active(&mut self, status: bool)
Sets all nodes’ activity in the next iteration as status.
sourcepub fn fill_data(&mut self, data: DataType)
pub fn fill_data(&mut self, data: DataType)
Sets all nodes’ data in the next iteration as data.
sourcepub fn step(&mut self)
pub fn step(&mut self)
Performs a global iteration step, useful in many algorithms. The previous status of all nodes is now updated to the new status. The new status is reset to false.
sourcepub fn n_active(&self) -> usize
pub fn n_active(&self) -> usize
Returns how many nodes are active in the last iteration. This function calculates the value every time, so it is recommended to store its value.
sourcepub fn push<F>(&mut self, func: F) where
F: Fn(DataType, &Atomic<DataType>) -> bool + Sync,
pub fn push<F>(&mut self, func: F) where
F: Fn(DataType, &Atomic<DataType>) -> bool + Sync,
This function iterates over the active nodes in the last iteration and applies func on them.
func receives two arguments: old, which is the last state of the node, and new, which is the current state.
pub fn get_data_as_slice(&self) -> &[Atomic<DataType>]
sourcepub fn save_data_to_file(&self, filename: &str) -> Result<()>
pub fn save_data_to_file(&self, filename: &str) -> Result<()>
Saves the computation’s data to the specified file in binary format, following the local machine’s endianness.
Auto Trait Implementations
impl<'a, T, DataType> !RefUnwindSafe for ComputeGraph<'a, T, DataType>
impl<'a, T, DataType> !Send for ComputeGraph<'a, T, DataType>
impl<'a, T, DataType> !Sync for ComputeGraph<'a, T, DataType>
impl<'a, T, DataType> Unpin for ComputeGraph<'a, T, DataType> where
DataType: Unpin,
impl<'a, T, DataType> UnwindSafe for ComputeGraph<'a, T, DataType> where
DataType: UnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more