pub fn update_hyperedge_vertices(
        &mut self,
        hyperedge_index: usize,
        vertices: &[usize],
    ) -> bool {
        match self.hyperedges.clone().get_index(hyperedge_index) {
            Some((key, value)) => {
                // Keep track of the initial indexes.
                let previous_vertices = self.get_hyperedge_vertices(hyperedge_index).unwrap();

                // Find the indexes which have been added.
                let added = vertices.iter().fold(vec![], |mut acc: Vec<usize>, index| {
                    if !previous_vertices.iter().any(|x| x == index) {
                        acc.push(*index)
                    }

                    acc
                });

                // Find the indexes which have been removed.
                let removed = previous_vertices
                    .iter()
                    .filter_map(|x| {
                        if !vertices.iter().any(|y| x == y) {
                            Some(*x)
                        } else {
                            None
                        }
                    })
                    .collect::<Vec<usize>>();

                // Finally get the unchanged ones.
                let unchanged = previous_vertices
                    .iter()
                    .filter_map(|x| {
                        if !removed.iter().any(|y| x == y) {
                            Some(*x)
                        } else {
                            None
                        }
                    })
                    .collect::<Vec<usize>>();

                // Process the updated ones.
                for index in unchanged.iter() {
                    if let Some((weight, vertex)) = self.vertices.clone().get_index(*index) {
                        self.vertices.insert(
                            *weight,
                            vertex
                                .iter()
                                .fold(IndexSet::new(), |mut new_index_set, hyperedge| {
                                    new_index_set.insert(
                                        // Insert the new ones if it's a match.
                                        if are_arrays_equal(hyperedge, &previous_vertices) {
                                            vertices.to_vec()
                                        } else {
                                            hyperedge.clone()
                                        },
                                    );

                                    new_index_set
                                }),
                        );
                    };
                }

                // Process the removed ones.
                for index in removed.iter() {
                    if let Some((weight, vertex)) = self.vertices.clone().get_index(*index) {
                        self.vertices.insert(
                            *weight,
                            vertex
                                .iter()
                                .fold(IndexSet::new(), |mut new_index_set, hyperedge| {
                                    // Skip the removed ones, i.e. if there's no match.
                                    if !are_arrays_equal(hyperedge, &previous_vertices) {
                                        new_index_set.insert(hyperedge.clone());
                                    }

                                    new_index_set
                                }),
                        );
                    };
                }

                // Process the added ones.
                for index in added.iter() {
                    if let Some((weight, vertex)) = self.vertices.clone().get_index_mut(*index) {
                        // Insert the new vertices.
                        vertex.insert(vertices.to_vec());

                        self.vertices.insert(*weight, vertex.clone());
                    };
                }

                // We need to use the insert and swap_remove trick here too,
                // see e.g. the update_vertex_weight method.
                self.hyperedges.insert(vertices.to_vec(), value.to_owned());
                self.hyperedges.swap_remove(key).is_some()
            }
            None => false,
        }
    }
/// Updates the vertices of a hyperedge based on its index.
Updates the vertices of a hyperedge based on its index.
Updates the vertices of a hyperedge based on its index .
pub fn update_hyperedge_vertices(
        &mut self,
        hyperedge_index: usize,
        vertices: &[usize],
    ) -> bool {
        match self.hyperedges.clone().get_index(hyperedge_index) {
            Some((key, value)) => {
                // Keep track of the initial indexes.
                let previous_vertices = self.get_hyperedge_vertices(hyperedge_index).unwrap();
                // Find the indexes which have been added.
                let added = vertices.iter().fold(vec![], |mut acc: Vec<usize>, index| {
                    if !previous_vertices.iter().any(|x| x == index) {
                        acc.push(*index)
                    }
                    acc
                });
                // Find the indexes which have been removed.
                let removed = previous_vertices
                    .iter()
                    .filter_map(|x| {
                        if !vertices.iter().any(|y| x == y) {
                            Some(*x)
                        } else {
                            None
                        }
                    })
                    .collect::<Vec<usize>>();
                // Finally get the unchanged ones.
                let unchanged = previous_vertices
                    .iter()
                    .filter_map(|x| {
                        if !removed.iter().any(|y| x == y) {
                            Some(*x)
                        } else {
                            None
                        }
                    })
                    .collect::<Vec<usize>>();
                // Process the updated ones.
                for index in unchanged.iter() {
                    if let Some((weight, vertex)) = self.vertices.clone().get_index(*index) {
                        self.vertices.insert(
                            *weight,
                            vertex
                                .iter()
                                .fold(IndexSet::new(), |mut new_index_set, hyperedge| {
                                    new_index_set.insert(
                                        // Insert the new ones if it's a match.
                                        if are_arrays_equal(hyperedge, &previous_vertices) {
                                            vertices.to_vec()
                                        } else {
                                            hyperedge.clone()
                                        },
                                    );
                                    new_index_set
                                }),
                        );
                    };
                }
                // Process the removed ones.
                for index in removed.iter() {
                    if let Some((weight, vertex)) = self.vertices.clone().get_index(*index) {
                        self.vertices.insert(
                            *weight,
                            vertex
                                .iter()
                                .fold(IndexSet::new(), |mut new_index_set, hyperedge| {
                                    // Skip the removed ones, i.e. if there's no match.
                                    if !are_arrays_equal(hyperedge, &previous_vertices) {
                                        new_index_set.insert(hyperedge.clone());
                                    }
                                    new_index_set
                                }),
                        );
                    };
                }
                // Process the added ones.
                for index in added.iter() {
                    if let Some((weight, vertex)) = self.vertices.clone().get_index_mut(*index) {
                        // Insert the new vertices.
                        vertex.insert(vertices.to_vec());
                        self.vertices.insert(*weight, vertex.clone());
                    };
                }
                // We need to use the insert and swap_remove trick here too,
                // see e.g. the update_vertex_weight method.
                self.hyperedges.insert(vertices.to_vec(), value.to_owned());
                self.hyperedges.swap_remove(key).is_some()
            }
            None => false,
        }
    }
pub fn update_hyperedge_vertices ( & mut self , hyperedge_index : usize , vertices : & [ usize ] , ) -> bool { match self . hyperedges . clone ( ) . get_index ( hyperedge_index ) { Some ( ( key , value ) ) => { // Keep track of the initial indexes. let previous_vertices = self . get_hyperedge_vertices ( hyperedge_index ) . unwrap ( ) ; // Find the indexes which have been added. let added = vertices . iter ( ) . fold ( vec ! [ ] , | mut acc : Vec < usize > , index | { if ! previous_vertices . iter ( ) . any ( | x | x == index ) { acc . push ( * index ) } acc } ) ; // Find the indexes which have been removed. let removed = previous_vertices . iter ( ) . filter_map ( | x | { if ! vertices . iter ( ) . any ( | y | x == y ) { Some ( * x ) } else { None } } ) . collect :: < Vec < usize > > ( ) ; // Finally get the unchanged ones. let unchanged = previous_vertices . iter ( ) . filter_map ( | x | { if ! removed . iter ( ) . any ( | y | x == y ) { Some ( * x ) } else { None } } ) . collect :: < Vec < usize > > ( ) ; // Process the updated ones. for index in unchanged . iter ( ) { if let Some ( ( weight , vertex ) ) = self . vertices . clone ( ) . get_index ( * index ) { self . vertices . insert ( * weight , vertex . iter ( ) . fold ( IndexSet :: new ( ) , | mut new_index_set , hyperedge | { new_index_set . insert ( // Insert the new ones if it's a match. if are_arrays_equal ( hyperedge , & previous_vertices ) { vertices . to_vec ( ) } else { hyperedge . clone ( ) } , ) ; new_index_set } ) , ) ; } ; } // Process the removed ones. for index in removed . iter ( ) { if let Some ( ( weight , vertex ) ) = self . vertices . clone ( ) . get_index ( * index ) { self . vertices . insert ( * weight , vertex . iter ( ) . fold ( IndexSet :: new ( ) , | mut new_index_set , hyperedge | { // Skip the removed ones, i.e. if there's no match. if ! are_arrays_equal ( hyperedge , & previous_vertices ) { new_index_set . insert ( hyperedge . clone ( ) ) ; } new_index_set } ) , ) ; } ; } // Process the added ones. for index in added . iter ( ) { if let Some ( ( weight , vertex ) ) = self . vertices . clone ( ) . get_index_mut ( * index ) { // Insert the new vertices. vertex . insert ( vertices . to_vec ( ) ) ; self . vertices . insert ( * weight , vertex . clone ( ) ) ; } ; } // We need to use the insert and swap_remove trick here too, // see e.g. the update_vertex_weight method. self . hyperedges . insert ( vertices . to_vec ( ) , value . to_owned ( ) ) ; self . hyperedges . swap_remove ( key ) . is_some ( ) } None => false , } }
Updates the vertices of a hyperedge based on its index.
Updates the vertices of a hyperedge based on its index .
&mut self
hyperedge_index
usize
vertices
&[usize]
&mut self
hyperedge_index
usize
vertices
&[usize]