-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
big refacto + emoji podium almost done
- Loading branch information
1 parent
20f477c
commit 6629aed
Showing
7 changed files
with
394 additions
and
225 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::{array::from_fn, collections::HashMap, hash::Hash}; | ||
|
||
|
||
pub struct FixedDeque<T, const N: usize = 1000> { | ||
pub data: [T; N], | ||
pos: usize | ||
} | ||
|
||
impl<T: Default, const N: usize> FixedDeque<T, N> { | ||
pub fn new() -> Self { | ||
FixedDeque { | ||
data: from_fn(|_| T::default()), | ||
pos: 0 | ||
} | ||
} | ||
} | ||
|
||
impl<T, const N: usize> FixedDeque<T, N> { | ||
pub fn push(&mut self, elem: T) { | ||
self.data[self.pos] = elem; | ||
self.pos += 1; | ||
if self.pos >= N { | ||
self.pos = 0; | ||
} | ||
} | ||
} | ||
|
||
impl<T: Hash + Eq + Clone, const N: usize> FixedDeque<T, N> { | ||
pub fn counts(&self) -> HashMap<T, usize> { | ||
let mut res = HashMap::new(); | ||
self.data.iter().cloned().for_each(|elem| { | ||
let count = res.entry(elem).or_default(); | ||
*count += 1; | ||
}); | ||
res | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.