Skip to content
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

MRG: adjust Signature::name() to return Option<String> instead of filename() and md5sum() #3434

Merged
merged 19 commits into from
Dec 18, 2024
Merged
10 changes: 9 additions & 1 deletion src/core/src/index/revindex/disk_revindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,15 @@ impl RevIndexOps for RevIndex {
.collection
.record_for_dataset(dataset_id)
.expect("dataset not found");
Some((row.name().into(), size))

let mut name = row.name();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is ugly - is there an idiomatic way to do this??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@luizirber luizirber Dec 17, 2024

Choose a reason for hiding this comment

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

maybe?

let name = [row.name(), row.filename(), row.md5()]
    .into_iter()
    .skip_while(|v| v.is_empty())
    .next()
    .unwrap();  // guaranteed to succeed because `md5` always exists

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeh.... :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in 0ed80c1

if name == "" {
name = row.filename();
}
if name == "" {
name = row.md5();
}
Some((name.into(), size))
} else {
None
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/index/revindex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ mod test {
)?;

assert_eq!(matches.len(), 1);
assert_eq!(matches[0].name(), "../genome-s10.fa.gz");
assert_eq!(matches[0].name(), ""); // signature name is empty
assert_eq!(matches[0].f_match(), 1.0);

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions src/core/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,8 @@ impl Signature {
pub fn name(&self) -> String {
Copy link
Member

Choose a reason for hiding this comment

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

since r0.18.0 is not released yet, do we want to make this
pub fn name(&self) -> Option<String> {
instead? This wil change calls around in other places, but seems to communicate better that the name exists or not instead of getting a .name() call that might return ""

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ooh, I like it! let me give it a try 🙇

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if let Some(name) = &self.name {
name.clone()
} else if let Some(filename) = &self.filename {
filename.clone()
} else {
self.md5sum()
"".into()
}
}

Expand Down Expand Up @@ -982,6 +980,8 @@ mod test {
assert_eq!(sig.signatures[0].size(), 3);
assert_eq!(sig.signatures[1].size(), 2);
assert_eq!(sig.signatures[2].size(), 1);

assert_eq!(sig.name(), "");
}

#[test]
Expand Down
Loading