Skip to content

Commit

Permalink
3rd argument shows only exactly the same
Browse files Browse the repository at this point in the history
  • Loading branch information
helio-frota committed Jun 12, 2024
1 parent 351f14a commit 37b7616
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ Basic and not 100% accurate for finding duplicate code blocks in Rust projects.
clone and run

```shell
cargo run /home/foobar/Desktop/guac-rs
cargo run --release /home/foobar/Desktop/guac-rs
or
cargo run /home/foobar/Desktop/guac-rs > out.md
cargo run --release /home/foobar/Desktop/guac-rs > out.md

pass whatever 3rd argument to show only exactly the same information on report

cargo run --release /home/foobar/Desktop/guac-rs abcde > out.md
```

[Example](./out.md)
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ mod test;

fn main() -> Result<(), io::Error> {
let args: Vec<String> = env::args().collect();
let mut threshold = 0.98;
if args.len() < 2 {
eprintln!("Usage: dpc . or dpc /home/foobar/rust_project");
process::exit(1);
} else if args.len() == 3 {
threshold = 1.0;
}

let dir = &args[1];
Expand Down Expand Up @@ -45,7 +48,7 @@ fn main() -> Result<(), io::Error> {

// Like the 150 and 2 above ^, this 0.98 is total opinionated...
// if we lower this we have more "almost the same" stuff.
let similar_blocks = util::similar(filtered_code_blocks, 0.98);
let similar_blocks = util::similar(filtered_code_blocks, threshold);
util::report(similar_blocks);

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub fn similar(blocks: Vec<String>, threshold: f64) -> Vec<(String, String, f64)
let b2 = blocks[j].as_str();
let similarity = sorensen_dice(b1, b2);

if similarity > threshold {
if similarity >= threshold {
let t = (b1.to_string(), b2.to_string(), similarity);
result.push(t);
}
Expand Down

0 comments on commit 37b7616

Please sign in to comment.