Skip to content

Commit

Permalink
fix: panic_if_edge_exists (#32)
Browse files Browse the repository at this point in the history
* fix: `panic_if_edge_exists`

* fix: self-loop logic
  • Loading branch information
aMahanna authored Aug 19, 2024
1 parent 4d8e16a commit 103c075
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,11 @@ impl NetworkXGraph {
from_map.insert(to_id_str.clone(), properties.clone());

let to_map = self.adj_map_graph.get_mut(&to_id_str).unwrap();
panic_if_edge_exists(to_map, to_id_str.clone(), from_id_str.clone());
to_map.insert(from_id_str.clone(), properties.clone());
if from_id_str != to_id_str {
panic_if_edge_exists(to_map, to_id_str, from_id_str.clone());
}

to_map.insert(from_id_str, properties);
}

fn insert_adj_digraph(
Expand All @@ -460,7 +463,9 @@ impl NetworkXGraph {

if self.symmetrize_edges_if_directed {
let succ_to_map = _succ.get_mut(&to_id_str).unwrap();
panic_if_edge_exists(succ_to_map, to_id_str.clone(), from_id_str.clone());
if from_id_str != to_id_str {
panic_if_edge_exists(succ_to_map, to_id_str.clone(), from_id_str.clone());
}
succ_to_map.insert(from_id_str.clone(), properties.clone());
}

Expand All @@ -481,8 +486,10 @@ impl NetworkXGraph {

if self.symmetrize_edges_if_directed {
let pred_from_map = _pred.get_mut(&from_id_str).unwrap();
panic_if_edge_exists(pred_from_map, from_id_str.clone(), to_id_str.clone());
pred_from_map.insert(to_id_str.clone(), properties.clone());
if from_id_str != to_id_str {
panic_if_edge_exists(pred_from_map, from_id_str, to_id_str.clone());
}
pred_from_map.insert(to_id_str, properties);
}
}

Expand All @@ -508,8 +515,8 @@ impl NetworkXGraph {
from_to_map.insert(index, properties.clone());

let to_map = self.adj_map_multigraph.get_mut(&to_id_str).unwrap();
let to_from_map = to_map.entry(from_id_str.clone()).or_default();
to_from_map.insert(index, properties.clone());
let to_from_map = to_map.entry(from_id_str).or_default();
to_from_map.insert(index, properties);
}

fn insert_adj_multidigraph(
Expand Down Expand Up @@ -552,14 +559,15 @@ impl NetworkXGraph {
}

let pred_to_map = _pred.get_mut(&to_id_str).unwrap();
let pred_to_from_map = pred_to_map.entry(from_id_str.clone()).or_default();
let pred_to_from_map: &mut HashMap<usize, Map<String, Value>> =
pred_to_map.entry(from_id_str.clone()).or_default();
let index = pred_to_from_map.len();
pred_to_from_map.insert(index, properties.clone());

if self.symmetrize_edges_if_directed {
let pred_from_map = _pred.get_mut(&from_id_str).unwrap();
let pred_from_to_map = pred_from_map.entry(to_id_str.clone()).or_default();
pred_from_to_map.insert(index, properties.clone());
let pred_from_to_map = pred_from_map.entry(to_id_str).or_default();
pred_from_to_map.insert(index, properties);
}
}
}
Expand Down

0 comments on commit 103c075

Please sign in to comment.