pub fn add_hyperedge(
        &mut self,
        vertices: &[usize],
        weight: HE,
    ) -> Option<WeightedHyperedgeIndex> {
        // Safe check to avoid out of bound index!
        if *max(vertices).unwrap() + 1 > self.vertices.len() {
            return None;
        }

        // Update the vertices so that we keep directly track of the hyperedge.
        for vertex in vertices.iter() {
            let mut index_set = self.vertices[*vertex].clone();

            index_set.insert(vertices.to_vec());

            self.vertices.insert(
                self.vertices.get_index(*vertex).unwrap().0.to_owned(),
                index_set,
            );
        }

        // Insert the new hyperedge with the corresponding weight, get back the indexes.
        Some(match self.hyperedges.get(vertices) {
            Some(weights) => {
                let mut new_weights = weights.clone();
                let (weight_index, _) = new_weights.insert_full(weight);
                let (hyperedge_index, _) = self
                    .hyperedges
                    .insert_full(vertices.to_owned(), new_weights);

                [hyperedge_index, weight_index]
            }
            None => {
                let mut weights = IndexSet::new();
                let (weight_index, _) = weights.insert_full(weight);
                let (hyperedge_index, _) =
                    self.hyperedges.insert_full(vertices.to_owned(), weights);

                [hyperedge_index, weight_index]
            }
        })
    }
/// Adds a hyperedge as an array of vertices indexes and a custom weight in the hypergraph.
/// Returns the weighted index of the hyperedge.
Adds a hyperedge as an array of vertices indexes and a custom weight in the hypergraph.
Returns the weighted index of the hyperedge.
Adds a hyperedge as an array of vertices indexes and a custom weight in the hypergraph . Returns the weighted index of the hyperedge .
pub fn add_hyperedge(
        &mut self,
        vertices: &[usize],
        weight: HE,
    ) -> Option<WeightedHyperedgeIndex> {
        // Safe check to avoid out of bound index!
        if *max(vertices).unwrap() + 1 > self.vertices.len() {
            return None;
        }
        // Update the vertices so that we keep directly track of the hyperedge.
        for vertex in vertices.iter() {
            let mut index_set = self.vertices[*vertex].clone();
            index_set.insert(vertices.to_vec());
            self.vertices.insert(
                self.vertices.get_index(*vertex).unwrap().0.to_owned(),
                index_set,
            );
        }
        // Insert the new hyperedge with the corresponding weight, get back the indexes.
        Some(match self.hyperedges.get(vertices) {
            Some(weights) => {
                let mut new_weights = weights.clone();
                let (weight_index, _) = new_weights.insert_full(weight);
                let (hyperedge_index, _) = self
                    .hyperedges
                    .insert_full(vertices.to_owned(), new_weights);
                [hyperedge_index, weight_index]
            }
            None => {
                let mut weights = IndexSet::new();
                let (weight_index, _) = weights.insert_full(weight);
                let (hyperedge_index, _) =
                    self.hyperedges.insert_full(vertices.to_owned(), weights);
                [hyperedge_index, weight_index]
            }
        })
    }
pub fn add_hyperedge ( & mut self , vertices : & [ usize ] , weight : HE , ) -> Option < WeightedHyperedgeIndex > { // Safe check to avoid out of bound index! if * max ( vertices ) . unwrap ( ) + 1 > self . vertices . len ( ) { return None ; } // Update the vertices so that we keep directly track of the hyperedge. for vertex in vertices . iter ( ) { let mut index_set = self . vertices [ * vertex ] . clone ( ) ; index_set . insert ( vertices . to_vec ( ) ) ; self . vertices . insert ( self . vertices . get_index ( * vertex ) . unwrap ( ) . 0 . to_owned ( ) , index_set , ) ; } // Insert the new hyperedge with the corresponding weight, get back the indexes. Some ( match self . hyperedges . get ( vertices ) { Some ( weights ) => { let mut new_weights = weights . clone ( ) ; let ( weight_index , _ ) = new_weights . insert_full ( weight ) ; let ( hyperedge_index , _ ) = self . hyperedges . insert_full ( vertices . to_owned ( ) , new_weights ) ; [ hyperedge_index , weight_index ] } None => { let mut weights = IndexSet :: new ( ) ; let ( weight_index , _ ) = weights . insert_full ( weight ) ; let ( hyperedge_index , _ ) = self . hyperedges . insert_full ( vertices . to_owned ( ) , weights ) ; [ hyperedge_index , weight_index ] } } ) }
Adds a hyperedge as an array of vertices indexes and a custom weight in the hypergraph.
Adds a hyperedge as an array of vertices indexes and a custom weight in the hypergraph .
&mut self
vertices
&[usize]
weight
HE
&mut self
vertices
&[usize]
weight
HE