Skip to content

Commit 362c704

Browse files
committed
mostly finish release stuff
1 parent 17b4fc4 commit 362c704

35 files changed

+531
-560
lines changed

data-lib/Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

data-lib/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ edition = "2024"
77
chrono = "0.4.41"
88
chumsky = {version = "0.10.1", features = ["unstable"]}
99
hashbrown = {version = "0.15.3", features = ["serde"]}
10-
itertools = "0.14.0"
1110
js-sys = "0.3.77"
1211
rayon = "1.10.0"
1312
regex = "1.11.1"

data-lib/src/common.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,3 @@ pub struct StackedNamedDataPoint {
158158
pub layer: String,
159159
pub value: f64,
160160
}
161-
162-
pub fn group_by<'a, T, K: Hash + Eq, TFn: Fn(&T) -> K>(
163-
items: impl IntoIterator<Item = &'a T>,
164-
key_fn: TFn,
165-
) -> HashMap<K, Vec<&'a T>> {
166-
let mut map: HashMap<K, Vec<&T>> = HashMap::new();
167-
for item in items {
168-
let key = key_fn(item);
169-
map.entry(key).or_default().push(item);
170-
}
171-
map
172-
}
173-
174-
pub trait GroupByExt<'a, T, K: Hash + Eq> {
175-
fn group_by<F: Fn(&T) -> K>(self, key_fn: F) -> HashMap<K, Vec<&'a T>>;
176-
}
177-
178-
impl<'a, T: 'a, K: Hash + Eq, I: IntoIterator<Item = &'a T>> GroupByExt<'a, T, K> for I {
179-
fn group_by<F: Fn(&T) -> K>(self, key_fn: F) -> HashMap<K, Vec<&'a T>> {
180-
group_by(self, key_fn)
181-
}
182-
}

data-lib/src/date.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ pub struct Date {
88
pub day: u32,
99
}
1010

11+
impl Default for Date {
12+
fn default() -> Self {
13+
Date {
14+
year: 0,
15+
month: 1,
16+
day: 1,
17+
}
18+
}
19+
}
20+
1121
impl Date {
1222
pub fn new(year: u32, month: u32, day: u32) -> Self {
1323
Date { year, month, day }

data-lib/src/iter_ext.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use hashbrown::HashMap;
2+
use std::hash::Hash;
3+
4+
pub fn group_by<T, K: Hash + Eq, TFn: Fn(&T) -> K>(
5+
items: impl IntoIterator<Item = T>,
6+
key_fn: TFn,
7+
) -> HashMap<K, Vec<T>> {
8+
let mut map: HashMap<K, Vec<T>> = HashMap::new();
9+
for item in items {
10+
let key = key_fn(&item);
11+
map.entry(key).or_default().push(item);
12+
}
13+
map
14+
}
15+
16+
pub trait GroupByExt<T, K: Hash + Eq> {
17+
fn group_by<F: Fn(&T) -> K>(self, key_fn: F) -> impl Iterator<Item = (K, Vec<T>)>;
18+
}
19+
20+
impl<T, K: Hash + Eq, I: IntoIterator<Item = T>> GroupByExt<T, K> for I {
21+
fn group_by<F: Fn(&T) -> K>(self, key_fn: F) -> impl Iterator<Item = (K, Vec<T>)> {
22+
group_by(self, key_fn).into_iter()
23+
}
24+
}
25+
26+
pub trait SortExt<T> {
27+
/// Sort the items in the iterator using a custom comparison function.
28+
/// This collects the items into a vector, sorts them, and returns an iterator over the sorted items.
29+
fn sort_by<F: Fn(&T, &T) -> std::cmp::Ordering>(self, compare_fn: F)
30+
-> impl Iterator<Item = T>;
31+
}
32+
33+
impl<T, I: Iterator<Item = T>> SortExt<T> for I {
34+
fn sort_by<F: Fn(&T, &T) -> std::cmp::Ordering>(
35+
self,
36+
compare_fn: F,
37+
) -> impl Iterator<Item = T> {
38+
let mut items: Vec<T> = self.collect();
39+
items.sort_by(compare_fn);
40+
items.into_iter()
41+
}
42+
}
43+
44+
pub trait DedupExt<T> {
45+
/// Deduplicate the items in the iterator based on a custom equality function.
46+
/// This collects the items into a vector, deduplicates them, and returns an iterator over the unique items.
47+
/// This is O(n^2) in the worst case, but I don't care.
48+
fn dedup_by<F: Fn(&T, &T) -> bool>(self, eq_fn: F) -> impl Iterator<Item = T>;
49+
}
50+
51+
impl<T, I: Iterator<Item = T>> DedupExt<T> for I {
52+
fn dedup_by<F: Fn(&T, &T) -> bool>(self, eq_fn: F) -> impl Iterator<Item = T> {
53+
let mut items: Vec<T> = vec![];
54+
for item in self {
55+
if items.iter().all(|existing| !eq_fn(existing, &item)) {
56+
items.push(item);
57+
}
58+
}
59+
items.into_iter()
60+
}
61+
}

data-lib/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub mod commit;
22
pub mod common;
33
pub mod date;
44
pub mod input_data;
5+
pub mod iter_ext;
56
pub mod license;
67
pub mod plugin;
78
pub mod release;

data-lib/src/plugin/data_array.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::ops::Index;
22

3-
use itertools::Itertools;
43
use wasm_bindgen::prelude::wasm_bindgen;
54

65
use crate::{
@@ -250,7 +249,7 @@ impl PluginDataArrayView {
250249

251250
Some((index, downloads_new as u32, downloads_start_date))
252251
})
253-
.collect_vec();
252+
.collect::<Vec<_>>();
254253
tmp.sort_by(|a, b| b.1.cmp(&a.1)); // Sort by downloads_new in descending order
255254
tmp.truncate(count);
256255

@@ -283,7 +282,7 @@ impl PluginDataArrayView {
283282
data,
284283
}
285284
})
286-
.collect_vec()
285+
.collect()
287286
}
288287

289288
pub fn monthly_count(&self, data: &PluginDataArray) -> Vec<CountMonthlyDataPoint> {

0 commit comments

Comments
 (0)