master > master: code-rs - minor

This commit is contained in:
RD 2022-04-18 19:03:28 +02:00
parent dc831a91c7
commit 5be654e5db
3 changed files with 13 additions and 12 deletions

View File

@ -48,7 +48,7 @@ fn tarjan_visit<T>(gph: &Graph<T>, &u: &T, ctx: &mut Context<T>)
{
// Place node on stack + initialise visit-index + component-index.
ctx.max_index += 1;
ctx.push(&u);
ctx.stack_push(&u);
ctx.set_root(&u, ctx.max_index);
ctx.set_index(&u, ctx.max_index);
ctx.set_state(&u, State::PENDING);
@ -63,18 +63,19 @@ fn tarjan_visit<T>(gph: &Graph<T>, &u: &T, ctx: &mut Context<T>)
tarjan_visit(gph, &v, ctx);
}
// Update associated component-index of parent node, if in same component as child:
if ctx.stack.contains(&v) {
if ctx.stack_contains(&v) {
ctx.set_root(&u, value_min!(ctx.get_root(&u), ctx.get_root(&v)));
}
}
ctx.set_state(&u, State::FINISHED);
ctx.log_info(&u);
// If at root of component pop everything from stack up to root and add component:
if ctx.get_index(&u) == ctx.get_root(&u) {
let mut component: Vec<T> = Vec::new();
loop {
let v = ctx.top();
ctx.pop();
let v = ctx.stack_top();
ctx.stack_pop();
component.push(v.clone());
if u == v { break; }
}
@ -119,15 +120,15 @@ impl<T> Context<T>
};
}
fn push(self: &mut Self, u: &T) {
fn stack_push(self: &mut Self, u: &T) {
self.stack.push(u.clone());
}
fn top(self: &mut Self) -> T {
fn stack_top(self: &mut Self) -> T {
return self.stack.top();
}
fn pop(self: &mut Self) -> T {
fn stack_pop(self: &mut Self) -> T {
return self.stack.pop();
}
@ -153,6 +154,10 @@ impl<T> Context<T>
self.update_infos(u, info);
}
fn stack_contains(self: &Self, u: &T) -> bool {
return self.stack.contains(u);
}
fn get_info(self: &Self, u: &T) -> NodeInformation<T> {
return *self.infos.get(u).unwrap();
}

View File

@ -55,7 +55,7 @@ fn fixture_graph3() -> graph::Graph<i32> {
}
// ----------------------------------------------------------------
// Test Graph
// Test Tarjan-Algorithm
// ----------------------------------------------------------------
#[rstest]

View File

@ -7,10 +7,6 @@ extern crate closure;
use ads2::stacks::stack;
// ----------------------------------------------------------------
// Test regex
// ----------------------------------------------------------------
// ----------------------------------------------------------------
// Test stack
// ----------------------------------------------------------------