Skip to content

Commit da9d548

Browse files
committed
chore: Formatting README.md, clippy lint
1 parent 6d3372c commit da9d548

File tree

5 files changed

+43
-41
lines changed

5 files changed

+43
-41
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
[![Crates.io](https://img.shields.io/crates/v/jam-rs.svg)](https://crates.io/crates/jam-rs)
44
[![Codecov](https://codecov.io/github/St4NNi/jam-rs/coverage.svg?branch=main)](https://codecov.io/gh/St4NNi/jam-rs)
55
[![Dependency status](https://deps.rs/repo/github/St4NNi/jam-rs/status.svg)](https://deps.rs/repo/github/St4NNi/jam-rs)
6-
___
7-
86
# jam-rs
97

108
Just another minhash (jam) implementation. A high performance minhash variant to screen extremely large (metagenomic) datasets in a very short timeframe.

src/compare.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,18 @@ impl<'a> Comparator<'a> {
183183
if self.reverse {
184184
if !larger_stats.compare(smaller_stats, self.gc_bounds) {
185185
self.num_skipped += 1;
186-
}else{
186+
} else {
187187
self.num_common += 1;
188188
}
189+
} else if !smaller_stats.compare(larger_stats, self.gc_bounds) {
190+
self.num_skipped += 1;
189191
} else {
190-
if !smaller_stats.compare(larger_stats, self.gc_bounds) {
191-
self.num_skipped += 1;
192-
}else{
193-
self.num_common += 1;
194-
}
192+
self.num_common += 1;
195193
}
196194
};
197195
}
198196
} else {
199-
for (hash, _) in &self.smaller.hashes {
197+
for hash in self.smaller.hashes.keys() {
200198
self.num_kmers += 1;
201199
if self.larger.hashes.contains_key(hash) {
202200
self.num_common += 1;
@@ -247,10 +245,7 @@ impl<'a> Comparator<'a> {
247245
mod tests {
248246
use std::collections::HashMap;
249247

250-
use crate::{
251-
compare::CompareResult,
252-
signature::Signature, sketch::Stats,
253-
};
248+
use crate::{compare::CompareResult, signature::Signature, sketch::Stats};
254249

255250
use super::MultiComp;
256251

@@ -362,6 +357,9 @@ mod tests {
362357
};
363358
assert_eq!(res[0], expected);
364359

365-
assert_eq!(res[0].to_string(), "test\ttest2\t2\t4\t50\t50\t2".to_string());
360+
assert_eq!(
361+
res[0].to_string(),
362+
"test\ttest2\t2\t4\t50\t50\t2".to_string()
363+
);
366364
}
367365
}

src/hash_functions.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn xxhash3_u64(kmer: u64) -> u64 {
2323
pub fn ahash(kmer: u64) -> u64 {
2424
let temp = (kmer ^ KEY1) as u128 * 6364136223846793005_u128;
2525
let temp2 = ((temp & 0xffff_ffff_ffff_ffff) as u64) ^ ((temp >> 64) as u64); // XOR the lower 64 bits with the upper 64 bits.
26-
return temp2.rotate_left(KEY2);
26+
temp2.rotate_left(KEY2)
2727
}
2828

2929
// Faster version of murmur3 with equivalent output
@@ -108,13 +108,25 @@ mod tests {
108108
#[test]
109109
fn function_test() {
110110
let f = Function::from_alg(HashAlgorithms::Ahash, 21);
111-
assert_eq!(f.get_small().unwrap()(0xAAAAAAAAAAAAAAA), 6369629604220809163);
111+
assert_eq!(
112+
f.get_small().unwrap()(0xAAAAAAAAAAAAAAA),
113+
6369629604220809163
114+
);
112115
let f = Function::from_alg(HashAlgorithms::Murmur3, 21);
113-
assert_eq!(f.get_small().unwrap()(0xAAAAAAAAAAAAAAA), 442865051503200633);
116+
assert_eq!(
117+
f.get_small().unwrap()(0xAAAAAAAAAAAAAAA),
118+
442865051503200633
119+
);
114120
let f = Function::from_alg(HashAlgorithms::Xxhash, 21);
115-
assert_eq!(f.get_small().unwrap()(0xAAAAAAAAAAAAAAA), 5855080426738543665);
121+
assert_eq!(
122+
f.get_small().unwrap()(0xAAAAAAAAAAAAAAA),
123+
5855080426738543665
124+
);
116125
let f = Function::from_alg(HashAlgorithms::Default, 21);
117-
assert_eq!(f.get_small().unwrap()(0xAAAAAAAAAAAAAAA), 6369629604220809163);
126+
assert_eq!(
127+
f.get_small().unwrap()(0xAAAAAAAAAAAAAAA),
128+
6369629604220809163
129+
);
118130
let f = Function::from_alg(HashAlgorithms::Murmur3, 32);
119131
assert_eq!(f.get_large().unwrap()(b"AAAAAAAAAAA"), 7773142420371383521);
120132
let f = Function::from_alg(HashAlgorithms::Xxhash, 32);

src/signature.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ pub struct Signature {
1616
pub max_hash: u64,
1717
}
1818

19-
impl Into<SourmashSignature> for Signature {
20-
fn into(self) -> SourmashSignature {
19+
impl From<Signature> for SourmashSignature {
20+
fn from(val: Signature) -> Self {
2121
SourmashSignature::builder()
22-
.hash_function(format!("{:?}", self.algorithm))
23-
.filename(Some(self.file_name))
22+
.hash_function(format!("{:?}", val.algorithm))
23+
.filename(Some(val.file_name))
2424
.email("".to_string())
2525
.license("CC0".to_string())
2626
.name(None)
2727
.signatures(
28-
self.sketches
28+
val.sketches
2929
.into_iter()
30-
.map(|sketch| sketch.into_sourmash(self.max_hash))
30+
.map(|sketch| sketch.into_sourmash(val.max_hash))
3131
.collect(),
3232
)
3333
.build()

src/sketcher.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,16 @@ struct SketchHelper {
2727

2828
impl SketchHelper {
2929
pub fn new(kmer_budget: u64, max_hash: u64, nmin: Option<u64>, nmax: Option<u64>) -> Self {
30-
let local_heap = if let Some(nmin) = nmin {
31-
Some((nmin, BinaryHeap::with_capacity((nmin * 2) as usize)))
32-
} else {
33-
None
34-
};
30+
let local_heap = nmin.map(|nmin| (nmin, BinaryHeap::with_capacity((nmin * 2) as usize)));
3531

3632
SketchHelper {
3733
kmer_budget,
3834
nmax,
3935
global_counter: 0,
4036
kmer_seq_counter: 0,
41-
max_hash: max_hash,
37+
max_hash,
4238
last_max_hash: 0,
43-
global_heap: BinaryHeap::with_capacity(10_000_000 as usize),
39+
global_heap: BinaryHeap::with_capacity(10_000_000_usize),
4440
local_heap,
4541
hashes: HashMap::with_capacity_and_hasher(
4642
10_000_000,
@@ -79,17 +75,15 @@ impl SketchHelper {
7975
self.hashes.remove(&max);
8076
}
8177
}
78+
} else if self.global_heap.len() < self.kmer_budget as usize {
79+
self.global_heap.push(hash);
80+
self.hashes.insert(hash, self.current_stat.clone());
8281
} else {
83-
if self.global_heap.len() < self.kmer_budget as usize {
84-
self.global_heap.push(hash);
82+
let mut max = self.global_heap.peek_mut().unwrap();
83+
if hash < *max {
84+
*max = hash;
8585
self.hashes.insert(hash, self.current_stat.clone());
86-
} else {
87-
let mut max = self.global_heap.peek_mut().unwrap();
88-
if hash < *max {
89-
*max = hash;
90-
self.hashes.insert(hash, self.current_stat.clone());
91-
self.hashes.remove(&max);
92-
}
86+
self.hashes.remove(&max);
9387
}
9488
}
9589
}

0 commit comments

Comments
 (0)