Skip to content

Commit

Permalink
follow conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
azizkayumov committed Oct 5, 2023
1 parent c023a09 commit 52e203d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ impl LinkCutTree {
if !matches!(self.forest[v].parent, Parent::Root) || v == w {
return; // already connected
}
// assert_eq!(self.forest[v].left, None);
self.forest[v].left = Some(w);
self.forest[v].left = Some(w); // v is the root of its represented tree, so no need to check if it has a left child
self.forest[w].parent = Parent::Node(v);
}

Expand Down
16 changes: 8 additions & 8 deletions tests/test_connectivity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ enum Operation {
}

#[test]
pub fn test_connectivity() {
pub fn connectivity() {
let mut rng = create_random_generator();
let edges = create_random_tree(&mut rng);

// initialize link-cut tree, we start with a forest of single nodes
// (edges are not added yet):
let mut lctree = LinkCutTree::new(NUMBER_OF_NODES);
let mut edges_in_tree = HashSet::new();
let mut edges_in_forest = HashSet::new();
let mut component_ids = (0..NUMBER_OF_NODES).collect::<Vec<usize>>();

// perform random operations: link, cut, or connected:
Expand All @@ -87,19 +87,19 @@ pub fn test_connectivity() {
println!("Link {} {}", v, w);
lctree.link(*v, *w);

edges_in_tree.insert((*v, *w));
component_ids = connected_components(&edges_in_tree);
edges_in_forest.insert((*v, *w));
component_ids = connected_components(&edges_in_forest);
}
Operation::Cut => {
if edges_in_tree.is_empty() {
if edges_in_forest.is_empty() {
continue;
}
let (v, w) = edges_in_tree.iter().choose(&mut rng).unwrap();
let (v, w) = edges_in_forest.iter().choose(&mut rng).unwrap();
println!("Cut {} {}", v, w);
lctree.cut(*v);

edges_in_tree.remove(&(*v, *w));
component_ids = connected_components(&edges_in_tree);
edges_in_forest.remove(&(*v, *w));
component_ids = connected_components(&edges_in_forest);
}
Operation::Connected => {
let v = rng.gen_range(0..NUMBER_OF_NODES);
Expand Down

0 comments on commit 52e203d

Please sign in to comment.