Skip to content

Add flood fill in Rust #745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

fanninpm
Copy link
Contributor

@fanninpm fanninpm commented Aug 7, 2020

This implementation makes use of the ndarray crate, which is accessible from the Rust Playground.

@berquist berquist added the Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) label Oct 3, 2020
@ntindle
Copy link
Member

ntindle commented Aug 28, 2021

[lang: rust]

@github-actions github-actions bot added the lang: rust Rust programming language label Aug 28, 2021
@Amaras Amaras requested a review from ShadowMitia December 8, 2021 17:57
Copy link
Contributor

@ShadowMitia ShadowMitia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've taken the liberty of adding a Cargo.toml file to your project, as we are moving to an automated build system. You could still see if a more recent version of ndarray works, though!

Overall it looks good, I don't really know ndarray and I think it's overkill to use it here.
Maybe you have a good reason to recommend it?

Otherwise just a few changes, clippy had a few warnings that need to be fixed.

@@ -0,0 +1,151 @@
use ndarray::prelude::*; // 0.13.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to pick from prelude directly, and you can remove the comment for the version

Suggested change
use ndarray::prelude::*; // 0.13.1
use ndarray::*;

queue.push_back(*loc);

// color the initial location
color(canvas, &loc, old_val, new_val);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a clippy warning about needless borrow for *loc

Suggested change
color(canvas, &loc, old_val, new_val);
color(canvas, loc, old_val, new_val);

return;
}

color(canvas, &loc, old_val, new_val);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a clippy warning about needless borrow for *loc

Suggested change
color(canvas, &loc, old_val, new_val);
color(canvas, loc, old_val, new_val);


color(canvas, &loc, old_val, new_val);

let up_next = find_neighbors(canvas, &loc, old_val);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a clippy warning about needless borrow for *loc

Suggested change
let up_next = find_neighbors(canvas, &loc, old_val);
let up_next = find_neighbors(canvas, loc, old_val);


fn find_neighbors(canvas: &Array<usize, Ix2>, loc: &[usize; 2], val: usize) -> Vec<[usize; 2]> {
// find neighbors
let mut possible_neighbors: Vec<[usize; 2]> = vec![[loc[0] + 1, loc[1]], [loc[0], loc[1] + 1]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary to be explicit about types here

Suggested change
let mut possible_neighbors: Vec<[usize; 2]> = vec![[loc[0] + 1, loc[1]], [loc[0], loc[1] + 1]];
let mut possible_neighbors = vec![[loc[0] + 1, loc[1]], [loc[0], loc[1] + 1]];

}

// set up the stack
let mut stack: Vec<[usize; 2]> = Vec::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary to be explicit about the types here.

Suggested change
let mut stack: Vec<[usize; 2]> = Vec::new();
let mut stack = Vec::new();

@ShadowMitia
Copy link
Contributor

And you also need to solve conflicts in the .md, but I think all the line numbers are good.

@ujjwal3067
Copy link

It's very old PR. Are we still going to continue reviewing it ? author doesn't seems to be active on this PR for 2 years.

@leios
Copy link
Member

leios commented Mar 14, 2022

If there are quick and obvious changes to make, we can split it off into another PR and merge that

@fanninpm
Copy link
Contributor Author

I don't particularly have time to go back through this PR and make changes. Feel free to supersede/cherry-pick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) lang: rust Rust programming language
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants