fix: clippy lint (#80)

* clippy(merge_iterator): fix `clippy::non_canonical_partial_ord_impl` lint.

* clippy(bloom): fix `clippy::manual_clamp` lint.

* clippy(compact): fix `clippy::assigning_clones` lint.

* clippy(key): fix `clippy::legacy_numeric_constants` lint.

* clippy(mem_table): fix `clippy::missing_transmute_annotations` lint.
This commit is contained in:
Foreverhighness
2024-06-24 00:45:56 +08:00
committed by GitHub
parent 2fb3932fb1
commit aa35a96dfc
10 changed files with 31 additions and 37 deletions

View File

@@ -14,27 +14,25 @@ struct HeapWrapper<I: StorageIterator>(pub usize, pub Box<I>);
impl<I: StorageIterator> PartialEq for HeapWrapper<I> {
fn eq(&self, other: &Self) -> bool {
self.partial_cmp(other).unwrap() == cmp::Ordering::Equal
self.cmp(other) == cmp::Ordering::Equal
}
}
impl<I: StorageIterator> Eq for HeapWrapper<I> {}
impl<I: StorageIterator> PartialOrd for HeapWrapper<I> {
#[allow(clippy::non_canonical_partial_ord_impl)]
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
match self.1.key().cmp(&other.1.key()) {
cmp::Ordering::Greater => Some(cmp::Ordering::Greater),
cmp::Ordering::Less => Some(cmp::Ordering::Less),
cmp::Ordering::Equal => self.0.partial_cmp(&other.0),
}
.map(|x| x.reverse())
Some(self.cmp(other))
}
}
impl<I: StorageIterator> Ord for HeapWrapper<I> {
fn cmp(&self, other: &Self) -> cmp::Ordering {
self.partial_cmp(other).unwrap()
self.1
.key()
.cmp(&other.1.key())
.then(self.0.cmp(&other.0))
.reverse()
}
}

View File

@@ -72,7 +72,7 @@ impl Bloom {
/// Build bloom filter from key hashes
pub fn build_from_key_hashes(keys: &[u32], bits_per_key: usize) -> Self {
let k = (bits_per_key as f64 * 0.69) as u32;
let k = k.min(30).max(1);
let k = k.clamp(1, 30);
let nbits = (keys.len() * bits_per_key).max(64);
let nbytes = (nbits + 7) / 8;
let nbits = nbytes * 8;