@@ -521,11 +521,12 @@ impl<CT: ComponentType> Graph<CT> {
521521 ) ?;
522522 // only add edge if both nodes already exist
523523 if let ( Some ( source) , Some ( target) ) = ( source, target)
524- && let Ok ( ctype) = CT :: from_str ( component_type) {
525- let c = Component :: new ( ctype, layer. into ( ) , component_name. into ( ) ) ;
526- let gs = self . get_or_create_writable ( & c) ?;
527- gs. add_edge ( Edge { source, target } ) ?;
528- }
524+ && let Ok ( ctype) = CT :: from_str ( component_type)
525+ {
526+ let c = Component :: new ( ctype, layer. into ( ) , component_name. into ( ) ) ;
527+ let gs = self . get_or_create_writable ( & c) ?;
528+ gs. add_edge ( Edge { source, target } ) ?;
529+ }
529530 }
530531 UpdateEvent :: DeleteEdge {
531532 source_node,
@@ -543,12 +544,13 @@ impl<CT: ComponentType> Graph<CT> {
543544 & mut node_id_cache,
544545 ) ?;
545546 if let ( Some ( source) , Some ( target) ) = ( source, target)
546- && let Ok ( ctype) = CT :: from_str ( component_type) {
547- let c = Component :: new ( ctype, layer. into ( ) , component_name. into ( ) ) ;
547+ && let Ok ( ctype) = CT :: from_str ( component_type)
548+ {
549+ let c = Component :: new ( ctype, layer. into ( ) , component_name. into ( ) ) ;
548550
549- let gs = self . get_or_create_writable ( & c) ?;
550- gs. delete_edge ( & Edge { source, target } ) ?;
551- }
551+ let gs = self . get_or_create_writable ( & c) ?;
552+ gs. delete_edge ( & Edge { source, target } ) ?;
553+ }
552554 }
553555 UpdateEvent :: AddEdgeLabel {
554556 source_node,
@@ -569,22 +571,23 @@ impl<CT: ComponentType> Graph<CT> {
569571 & mut node_id_cache,
570572 ) ?;
571573 if let ( Some ( source) , Some ( target) ) = ( source, target)
572- && let Ok ( ctype) = CT :: from_str ( component_type) {
573- let c = Component :: new ( ctype , layer . into ( ) , component_name . into ( ) ) ;
574- let gs = self . get_or_create_writable ( & c ) ? ;
575- // only add label if the edge already exists
576- let e = Edge { source , target } ;
577- if gs . is_connected ( source, target, 1 , Included ( 1 ) ) ? {
578- let anno = Annotation {
579- key : AnnoKey {
580- ns : anno_ns . into ( ) ,
581- name : anno_name . into ( ) ,
582- } ,
583- val : anno_value . into ( ) ,
584- } ;
585- gs . add_edge_annotation ( e , anno ) ? ;
586- }
574+ && let Ok ( ctype) = CT :: from_str ( component_type)
575+ {
576+ let c = Component :: new ( ctype , layer . into ( ) , component_name . into ( ) ) ;
577+ let gs = self . get_or_create_writable ( & c ) ? ;
578+ // only add label if the edge already exists
579+ let e = Edge { source, target } ;
580+ if gs . is_connected ( source , target , 1 , Included ( 1 ) ) ? {
581+ let anno = Annotation {
582+ key : AnnoKey {
583+ ns : anno_ns . into ( ) ,
584+ name : anno_name . into ( ) ,
585+ } ,
586+ val : anno_value . into ( ) ,
587+ } ;
588+ gs . add_edge_annotation ( e , anno ) ? ;
587589 }
590+ }
588591 }
589592 UpdateEvent :: DeleteEdgeLabel {
590593 source_node,
@@ -604,19 +607,20 @@ impl<CT: ComponentType> Graph<CT> {
604607 & mut node_id_cache,
605608 ) ?;
606609 if let ( Some ( source) , Some ( target) ) = ( source, target)
607- && let Ok ( ctype) = CT :: from_str ( component_type) {
608- let c = Component :: new ( ctype , layer . into ( ) , component_name . into ( ) ) ;
609- let gs = self . get_or_create_writable ( & c ) ? ;
610- // only add label if the edge already exists
611- let e = Edge { source , target } ;
612- if gs . is_connected ( source, target, 1 , Included ( 1 ) ) ? {
613- let key = AnnoKey {
614- ns : anno_ns . into ( ) ,
615- name : anno_name . into ( ) ,
616- } ;
617- gs . delete_edge_annotation ( & e , & key ) ? ;
618- }
610+ && let Ok ( ctype) = CT :: from_str ( component_type)
611+ {
612+ let c = Component :: new ( ctype , layer . into ( ) , component_name . into ( ) ) ;
613+ let gs = self . get_or_create_writable ( & c ) ? ;
614+ // only add label if the edge already exists
615+ let e = Edge { source, target } ;
616+ if gs . is_connected ( source , target , 1 , Included ( 1 ) ) ? {
617+ let key = AnnoKey {
618+ ns : anno_ns . into ( ) ,
619+ name : anno_name . into ( ) ,
620+ } ;
621+ gs . delete_edge_annotation ( & e , & key ) ? ;
619622 }
623+ }
620624 }
621625 } // end match update entry type
622626 ComponentType :: after_update_event ( change, self , & mut update_graph_index) ?;
@@ -886,9 +890,10 @@ impl<CT: ComponentType> Graph<CT> {
886890 pub fn is_loaded ( & self , c : & Component < CT > ) -> bool {
887891 let entry: Option < & Option < Arc < dyn GraphStorage > > > = self . components . get ( c) ;
888892 if let Some ( gs_opt) = entry
889- && gs_opt. is_some ( ) {
890- return true ;
891- }
893+ && gs_opt. is_some ( )
894+ {
895+ return true ;
896+ }
892897 false
893898 }
894899
@@ -1018,32 +1023,33 @@ impl<CT: ComponentType> Graph<CT> {
10181023
10191024 pub fn optimize_gs_impl ( & mut self , c : & Component < CT > ) -> Result < ( ) > {
10201025 if let Some ( gs) = self . get_graphstorage ( c)
1021- && let Some ( stats) = gs. get_statistics ( ) {
1022- let opt_info = registry :: get_optimal_impl_heuristic ( self , stats ) ;
1023-
1024- // convert if necessary
1025- if opt_info . id != gs . serialization_id ( ) {
1026- let mut new_gs = registry :: create_from_info ( & opt_info ) ? ;
1027- let converted = if let Some ( new_gs_mut ) = Arc :: get_mut ( & mut new_gs ) {
1028- info ! (
1029- "converting component {} to implementation {}" ,
1030- c , opt_info . id ,
1031- ) ;
1032- new_gs_mut . copy ( self . get_node_annos ( ) , gs . as_ref ( ) ) ? ;
1033- true
1034- } else {
1035- false
1036- } ;
1037- if converted {
1038- // insert into components map
1039- info ! (
1040- "finished conversion of component {} to implementation {}" ,
1041- c , opt_info . id ,
1042- ) ;
1043- self . components . insert ( c . clone ( ) , Some ( new_gs . clone ( ) ) ) ;
1044- }
1026+ && let Some ( stats) = gs. get_statistics ( )
1027+ {
1028+ let opt_info = registry :: get_optimal_impl_heuristic ( self , stats ) ;
1029+
1030+ // convert if necessary
1031+ if opt_info . id != gs . serialization_id ( ) {
1032+ let mut new_gs = registry :: create_from_info ( & opt_info ) ? ;
1033+ let converted = if let Some ( new_gs_mut ) = Arc :: get_mut ( & mut new_gs ) {
1034+ info ! (
1035+ "converting component {} to implementation {}" ,
1036+ c , opt_info . id ,
1037+ ) ;
1038+ new_gs_mut . copy ( self . get_node_annos ( ) , gs . as_ref ( ) ) ? ;
1039+ true
1040+ } else {
1041+ false
1042+ } ;
1043+ if converted {
1044+ // insert into components map
1045+ info ! (
1046+ "finished conversion of component {} to implementation {}" ,
1047+ c , opt_info . id ,
1048+ ) ;
1049+ self . components . insert ( c . clone ( ) , Some ( new_gs . clone ( ) ) ) ;
10451050 }
10461051 }
1052+ }
10471053
10481054 Ok ( ( ) )
10491055 }
@@ -1114,13 +1120,15 @@ impl<CT: ComponentType> Graph<CT> {
11141120 . keys ( )
11151121 . filter ( move |c| {
11161122 if let Some ( ctype) = ctype. clone ( )
1117- && ctype != c. get_type ( ) {
1118- return false ;
1119- }
1123+ && ctype != c. get_type ( )
1124+ {
1125+ return false ;
1126+ }
11201127 if let Some ( name) = name
1121- && name != c. name {
1122- return false ;
1123- }
1128+ && name != c. name
1129+ {
1130+ return false ;
1131+ }
11241132 true
11251133 } )
11261134 . cloned ( ) ;
0 commit comments