Skip to content
Snippets Groups Projects
Commit c73d0bd2 authored by Valerian Wintner's avatar Valerian Wintner
Browse files

Remove unnecessary changing of predecessor-set.

parent 539a5f7c
No related branches found
No related tags found
No related merge requests found
......@@ -71,7 +71,7 @@ When done, remove the image:
- It checks if some successor of the green node is in the winning set.
- If that is the case, the green node is added to the winning set, and removed from the nodes being iterated on.
- Any time a node is added to the winning set, any red nodes that are a predecessor of this newly added node have their counter reduced by 1.
- If the counter of a red node reaches 0, it is added to the winning set and removed from the predecessor-set of the added node.
- If the counter of a red node reaches 0, it is added to the winning set.
- The loop runs until no new nodes are added in the `pre`-step.
# Libraries used
......
......@@ -11,20 +11,18 @@ fn insert_node(
let mut to_insert = vec![node];
while let Some(node) = to_insert.pop() {
additional_winning.insert(node.clone());
let predecessors = pred.entry(node);
predecessors.and_modify(|predecessors| {
let mut changed_predecessors = HashSet::new();
for predecessor in predecessors.iter() {
let counter = predecessor.counter.take() - 1;
if counter == 0 {
to_insert.push(predecessor.id.clone());
} else {
predecessor.counter.replace(counter);
changed_predecessors.insert(predecessor.clone());
if let Some(predecessors) = pred.get(&node) {
for predecessor in predecessors {
let mut counter = predecessor.counter.borrow_mut();
if *counter >= 1 {
// This is the last successor needed for the red node to get added
if *counter == 1 {
to_insert.push(predecessor.id.clone());
}
*counter -= 1;
}
}
*predecessors = changed_predecessors
});
}
}
}
......@@ -70,6 +68,7 @@ pub fn winning_positions(
"[prestep] Winning positions after adding final positions: {:?}",
winning_positions
);
debug!("[prestep] Predecessors: {:#?}", pred);
}
// Remove green nodes that have already been added to winners due to being final positions
greens = greens
......@@ -89,6 +88,7 @@ pub fn winning_positions(
if additional_winnings.is_empty() {
return winning_positions;
}
debug!("[iter] Predecessors: {:#?}", pred);
greens = changed_greens;
winning_positions.extend(additional_winnings);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment