Skip to content

Commit

Permalink
Fix cargo clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
regexident committed Dec 13, 2024
1 parent 15a2d26 commit d25d42a
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 50 deletions.
31 changes: 22 additions & 9 deletions ascent/src/aggregators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,29 @@ use std::iter::Sum;
use std::ops::Add;

/// computes the minimum of the input column
pub fn min<'a, N: 'a>(inp: impl Iterator<Item = (&'a N,)>) -> impl Iterator<Item = N>
where N: Ord + Clone {
pub fn min<'a, N>(inp: impl Iterator<Item = (&'a N,)>) -> impl Iterator<Item = N>
where
N: Ord + Clone,
N: 'a,
{
inp.map(|tuple| tuple.0).min().cloned().into_iter()
}

/// computes the maximum of the input column
pub fn max<'a, N: 'a>(inp: impl Iterator<Item = (&'a N,)>) -> impl Iterator<Item = N>
where N: Ord + Clone {
pub fn max<'a, N>(inp: impl Iterator<Item = (&'a N,)>) -> impl Iterator<Item = N>
where
N: Ord + Clone,
N: 'a,
{
inp.map(|tuple| tuple.0).max().cloned().into_iter()
}

/// computes the sum of the input column
pub fn sum<'a, N: 'a>(inp: impl Iterator<Item = (&'a N,)>) -> impl Iterator<Item = N>
where N: Ord + Add + Clone + Sum<N> {
pub fn sum<'a, N>(inp: impl Iterator<Item = (&'a N,)>) -> impl Iterator<Item = N>
where
N: Ord + Add + Clone + Sum<N>,
N: 'a,
{
let sum = inp.map(|tuple| tuple.0).cloned().sum::<N>();
std::iter::once(sum)
}
Expand Down Expand Up @@ -65,18 +74,22 @@ pub fn count(inp: impl Iterator<Item = ()>) -> impl Iterator<Item = usize> {
}

/// computes the average of the input column, returning an `f64`
pub fn mean<'a, N: 'a>(inp: impl Iterator<Item = (&'a N,)>) -> impl Iterator<Item = f64>
where N: Clone + Into<f64> {
pub fn mean<'a, N>(inp: impl Iterator<Item = (&'a N,)>) -> impl Iterator<Item = f64>
where
N: Clone + Into<f64>,
N: 'a,
{
let (sum, count) = inp.fold((0.0, 0usize), |(sum, count), tuple| (tuple.0.clone().into() + sum, count + 1));
let res = if count == 0 { None } else { Some(sum / count as f64) };
res.into_iter()
}

/// computes the value at the given percentile of the input column
pub fn percentile<'a, TItem: 'a, TInputIter>(p: f64) -> impl Fn(TInputIter) -> std::option::IntoIter<TItem>
pub fn percentile<'a, TItem, TInputIter>(p: f64) -> impl Fn(TInputIter) -> std::option::IntoIter<TItem>
where
TInputIter: Iterator<Item = (&'a TItem,)>,
TItem: Ord + Clone,
TItem: 'a,
{
move |inp| {
let mut sorted: Vec<_> = inp.map(|tuple| tuple.0.clone()).collect();
Expand Down
10 changes: 3 additions & 7 deletions ascent/src/c_lat_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ impl<'a, K: 'a + Clone + Hash + Eq, V: 'a + Clone + Hash + Eq + Sync> CRelIndexR
}
}

impl<'a, K: 'a + Clone + Hash + Eq + Send + Sync, V: 'a + Clone + Hash + Eq + Send + Sync> RelIndexWrite
for CLatIndex<K, V>
{
impl<K: Clone + Hash + Eq + Send + Sync, V: Clone + Hash + Eq + Send + Sync> RelIndexWrite for CLatIndex<K, V> {
type Key = K;
type Value = V;

Expand All @@ -143,9 +141,7 @@ impl<'a, K: 'a + Clone + Hash + Eq + Send + Sync, V: 'a + Clone + Hash + Eq + Se
}
}

impl<'a, K: 'a + Clone + Hash + Eq + Send + Sync, V: 'a + Clone + Hash + Eq + Send + Sync> RelIndexMerge
for CLatIndex<K, V>
{
impl<K: Clone + Hash + Eq + Send + Sync, V: Clone + Hash + Eq + Send + Sync> RelIndexMerge for CLatIndex<K, V> {
fn move_index_contents(from: &mut Self, to: &mut Self) {
let before = Instant::now();
let from = from.unwrap_mut_unfrozen();
Expand Down Expand Up @@ -219,7 +215,7 @@ impl<'a, K: 'a + Clone + Hash + Eq + Sync + Send, V: 'a + Clone + Hash + Eq + Sy
}
}

impl<'a, K: 'a + Clone + Hash + Eq, V: 'a + Clone + Hash + Eq> CRelIndexWrite for CLatIndex<K, V> {
impl<K: Clone + Hash + Eq, V: Clone + Hash + Eq> CRelIndexWrite for CLatIndex<K, V> {
type Key = K;
type Value = V;

Expand Down
12 changes: 6 additions & 6 deletions ascent/src/c_rel_full_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ impl<'a, K: 'a + Clone + Hash + Eq, V: 'a + Sync> CRelIndexRead<'a> for CRelFull
}
}

impl<'a, K: 'a + Clone + Hash + Eq, V: 'a> RelFullIndexRead<'a> for CRelFullIndex<K, V> {
impl<K: Clone + Hash + Eq, V> RelFullIndexRead<'_> for CRelFullIndex<K, V> {
type Key = K;

#[inline(always)]
fn contains_key(&self, key: &Self::Key) -> bool { self.unwrap_frozen().contains_key(key) }
}

impl<'a, K: 'a + Clone + Hash + Eq, V: 'a> RelFullIndexWrite for CRelFullIndex<K, V> {
impl<K: Clone + Hash + Eq, V> RelFullIndexWrite for CRelFullIndex<K, V> {
type Key = K;
type Value = V;

Expand All @@ -162,7 +162,7 @@ impl<'a, K: 'a + Clone + Hash + Eq, V: 'a> RelFullIndexWrite for CRelFullIndex<K
}
}

impl<'a, K: 'a + Clone + Hash + Eq, V: 'a> CRelFullIndexWrite for CRelFullIndex<K, V> {
impl<K: Clone + Hash + Eq, V> CRelFullIndexWrite for CRelFullIndex<K, V> {
type Key = K;
type Value = V;

Expand Down Expand Up @@ -222,7 +222,7 @@ impl<'a, K: 'a + Clone + Hash + Eq + Send + Sync, V: 'a + Clone + Send + Sync> C
}
}

impl<'a, K: 'a + Clone + Hash + Eq + Send + Sync, V: 'a + Send + Sync> RelIndexWrite for CRelFullIndex<K, V> {
impl<K: Clone + Hash + Eq + Send + Sync, V: Send + Sync> RelIndexWrite for CRelFullIndex<K, V> {
type Key = K;
type Value = V;

Expand All @@ -242,7 +242,7 @@ impl<'a, K: 'a + Clone + Hash + Eq + Send + Sync, V: 'a + Send + Sync> RelIndexW
}
}

impl<'a, K: 'a + Clone + Hash + Eq + Send + Sync, V: 'a + Send + Sync> RelIndexMerge for CRelFullIndex<K, V> {
impl<K: Clone + Hash + Eq + Send + Sync, V: Send + Sync> RelIndexMerge for CRelFullIndex<K, V> {
fn move_index_contents(from: &mut Self, to: &mut Self) {
let before = Instant::now();

Expand Down Expand Up @@ -270,7 +270,7 @@ impl<'a, K: 'a + Clone + Hash + Eq + Send + Sync, V: 'a + Send + Sync> RelIndexM
}
}

impl<'a, K: 'a + Clone + Hash + Eq, V: 'a> CRelIndexWrite for CRelFullIndex<K, V> {
impl<K: Clone + Hash + Eq, V> CRelIndexWrite for CRelFullIndex<K, V> {
type Key = K;
type Value = V;

Expand Down
14 changes: 5 additions & 9 deletions ascent/src/c_rel_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,10 @@ impl<K: Clone + Hash + Eq, V> CRelIndex<K, V> {
#[allow(dead_code)]
// TODO remove if not used
fn insert2(&self, key: K, value: V) {
use std::hash::Hasher;

use dashmap::Map;

let dm = self.unwrap_unfrozen();
let mut hasher = dm.hasher().build_hasher();
key.hash(&mut hasher);
let hash = hasher.finish();
let hash = dm.hasher().hash_one(&key);

let idx = dm.determine_shard(hash as usize);
let mut shard = unsafe { dm._yield_write_shard(idx) };
Expand Down Expand Up @@ -153,7 +149,7 @@ impl<'a, K: 'a + Clone + Hash + Eq, V: 'a + Sync> CRelIndexRead<'a> for CRelInde
}
}

impl<'a, K: 'a + Clone + Hash + Eq + Send + Sync, V: 'a + Send + Sync> RelIndexWrite for CRelIndex<K, V> {
impl<K: Clone + Hash + Eq + Send + Sync, V: Send + Sync> RelIndexWrite for CRelIndex<K, V> {
type Key = K;
type Value = V;

Expand All @@ -174,7 +170,7 @@ impl<'a, K: 'a + Clone + Hash + Eq + Send + Sync, V: 'a + Send + Sync> RelIndexW
}
}

impl<'a, K: 'a + Clone + Hash + Eq + Send + Sync, V: 'a + Send + Sync> RelIndexMerge for CRelIndex<K, V> {
impl<K: Clone + Hash + Eq + Send + Sync, V: Send + Sync> RelIndexMerge for CRelIndex<K, V> {
fn move_index_contents(from: &mut Self, to: &mut Self) {
let before = Instant::now();
let from = from.unwrap_mut_unfrozen();
Expand Down Expand Up @@ -229,7 +225,7 @@ pub struct DashMapViewParIter<'a, K, V, S> {
shards: &'a [RwLock<hashbrown::HashMap<K, SharedValue<V>, S>>],
}

impl<'a, K, V, S> Clone for DashMapViewParIter<'a, K, V, S> {
impl<K, V, S> Clone for DashMapViewParIter<'_, K, V, S> {
fn clone(&self) -> Self { Self { shards: self.shards } }
}

Expand Down Expand Up @@ -302,7 +298,7 @@ impl<'a, K: 'a + Clone + Hash + Eq + Sync + Send, V: Clone + 'a + Sync + Send> C
}
}

impl<'a, K: 'a + Clone + Hash + Eq, V: 'a> CRelIndexWrite for CRelIndex<K, V> {
impl<K: Clone + Hash + Eq, V> CRelIndexWrite for CRelIndex<K, V> {
type Key = K;
type Value = V;

Expand Down
6 changes: 3 additions & 3 deletions ascent/src/c_rel_no_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'a, V: 'a + Sync + Send> CRelIndexRead<'a> for CRelNoIndex<V> {
}
}

impl<'a, V: 'a> RelIndexWrite for CRelNoIndex<V> {
impl<V> RelIndexWrite for CRelNoIndex<V> {
type Key = ();
type Value = V;

Expand All @@ -89,7 +89,7 @@ impl<'a, V: 'a> RelIndexWrite for CRelNoIndex<V> {
}
}

impl<'a, V: 'a> RelIndexMerge for CRelNoIndex<V> {
impl<V> RelIndexMerge for CRelNoIndex<V> {
fn move_index_contents(from: &mut Self, to: &mut Self) {
let before = Instant::now();
assert_eq!(from.len(), to.len());
Expand All @@ -112,7 +112,7 @@ impl<'a, V: 'a> RelIndexMerge for CRelNoIndex<V> {
}
}

impl<'a, V: 'a> CRelIndexWrite for CRelNoIndex<V> {
impl<V> CRelIndexWrite for CRelNoIndex<V> {
type Key = ();
type Value = V;

Expand Down
2 changes: 1 addition & 1 deletion ascent/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl<K: Clone + Hash + Eq, V> RelFullIndexWrite for HashBrownRelFullIndexType<K,
}
}

impl<'a, K: Hash + Eq, V> RelFullIndexRead<'a> for HashBrownRelFullIndexType<K, V> {
impl<K: Hash + Eq, V> RelFullIndexRead<'_> for HashBrownRelFullIndexType<K, V> {
type Key = K;

fn contains_key(&self, key: &Self::Key) -> bool { self.contains_key(key) }
Expand Down
10 changes: 5 additions & 5 deletions ascent/src/rel_index_boilerplate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::internal::{
};
use crate::rel_index_read::{RelIndexRead, RelIndexReadAll};

impl<'a, T> RelIndexWrite for &'a mut T
impl<T> RelIndexWrite for &mut T
where T: RelIndexWrite
{
type Key = T::Key;
Expand All @@ -13,7 +13,7 @@ where T: RelIndexWrite
fn index_insert(&mut self, key: Self::Key, value: Self::Value) { (**self).index_insert(key, value) }
}

impl<'a, T> RelFullIndexWrite for &'a mut T
impl<T> RelFullIndexWrite for &mut T
where T: RelFullIndexWrite
{
type Key = T::Key;
Expand All @@ -25,7 +25,7 @@ where T: RelFullIndexWrite
}
}

impl<'a, T> CRelIndexWrite for &'a T
impl<T> CRelIndexWrite for &T
where T: CRelIndexWrite
{
type Key = T::Key;
Expand All @@ -35,7 +35,7 @@ where T: CRelIndexWrite
fn index_insert(&self, key: Self::Key, value: Self::Value) { (**self).index_insert(key, value) }
}

impl<'a, T> CRelFullIndexWrite for &'a T
impl<T> CRelFullIndexWrite for &T
where T: CRelFullIndexWrite
{
type Key = T::Key;
Expand All @@ -45,7 +45,7 @@ where T: CRelFullIndexWrite
fn insert_if_not_present(&self, key: &Self::Key, v: Self::Value) -> bool { (**self).insert_if_not_present(key, v) }
}

impl<'a, T> RelIndexMerge for &'a mut T
impl<T> RelIndexMerge for &mut T
where T: RelIndexMerge
{
fn move_index_contents(from: &mut Self, to: &mut Self) { T::move_index_contents(*from, *to) }
Expand Down
2 changes: 1 addition & 1 deletion ascent/src/tuple_of_borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl<'a, T1> TupleOfBorrowed for &'a (T1,) {
fn tuple_of_borrowed(self) -> Self::Tuple { (&self.0,) }
}

impl<'a, T1> TupleOfBorrowed for (&'a T1,) {
impl<T1> TupleOfBorrowed for (&T1,) {
type Tuple = Self;

#[inline(always)]
Expand Down
6 changes: 3 additions & 3 deletions ascent_base/src/lattice/constant_propagation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ fn test_constant_propagation() {
fn test_constant_propagation_lattice() {
let const_1 = ConstPropagation::Constant(1);

let mut x = const_1.clone();
assert!(!x.join_mut(const_1.clone()));
assert!(!x.meet_mut(const_1.clone()));
let mut x = const_1;
assert!(!x.join_mut(const_1));
assert!(!x.meet_mut(const_1));
assert!(!x.join_mut(ConstPropagation::Bottom));
assert!(!x.meet_mut(ConstPropagation::Top));

Expand Down
2 changes: 1 addition & 1 deletion ascent_base/src/lattice/ord_lattice.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::{Debug, Display, Formatter};
use std::fmt::{Debug, Formatter};

use crate::Lattice;

Expand Down
4 changes: 2 additions & 2 deletions ascent_macro/src/ascent_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,10 @@ impl Parse for DsAttributeContents {
let content = input;
// parenthesized!(content in input);

let path = syn::Path::parse_mod_style(&content)?;
let path = syn::Path::parse_mod_style(content)?;
let args = if content.peek(Token![:]) {
content.parse::<Token![:]>()?;
TokenStream::parse(&content)?
TokenStream::parse(content)?
} else {
TokenStream::default()
};
Expand Down
2 changes: 1 addition & 1 deletion ascent_macro/src/syn_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ pub fn token_stream_idents(ts: TokenStream) -> Vec<Ident> {

pub fn expr_visit_macros_mut(expr: &mut Expr, visitor: &mut dyn FnMut(&mut ExprMacro)) {
struct Visitor<'a>(&'a mut dyn FnMut(&mut ExprMacro));
impl<'a> syn::visit_mut::VisitMut for Visitor<'a> {
impl syn::visit_mut::VisitMut for Visitor<'_> {
fn visit_expr_macro_mut(&mut self, node: &mut ExprMacro) { (self.0)(node) }
}
Visitor(visitor).visit_expr_mut(expr)
Expand Down
4 changes: 2 additions & 2 deletions ascent_macro/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ fn exp_condensation() {
// ^ | ^ |
// | v | v
// d <---- c h <---- g
graph.extend_with_edges(&[(a, b), (b, c), (c, d), (d, a), (b, e), (e, f), (f, g), (g, h), (h, e)]);
graph.extend_with_edges([(a, b), (b, c), (c, d), (d, a), (b, e), (e, f), (f, g), (g, h), (h, e)]);
let acyclic_condensed_graph = condensation(graph.clone(), true);
#[allow(non_snake_case)]
let (A, B) = (NodeIndex::new(0), NodeIndex::new(1));
Expand Down Expand Up @@ -419,7 +419,7 @@ fn write_to_scratchpad_base(
let code_in_template = template.replace("todo!(\"here\");", &code.to_string());
std::fs::write("src/scratchpad.rs", prefix.to_string()).unwrap();
std::fs::write("src/scratchpad.rs", code_in_template).unwrap();
std::process::Command::new("rustfmt").args(&["src/scratchpad.rs"]).spawn().unwrap().wait().unwrap();
std::process::Command::new("rustfmt").args(["src/scratchpad.rs"]).spawn().unwrap().wait().unwrap();
code
}

Expand Down

0 comments on commit d25d42a

Please sign in to comment.