-
Notifications
You must be signed in to change notification settings - Fork 70
/
lieon.rs
87 lines (69 loc) · 1.95 KB
/
lieon.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Shim for single-threaded rayon replacement
// Unlike other code in this project, this file is licensed
// under both CC0 and AGPL-3.0, whichever you prefer.
// <https://creativecommons.org/public-domain/cc0/>
pub mod prelude {
pub use super::*;
pub use itertools::Itertools;
}
pub trait ParIterator: Sized {
fn with_min_len(self, _one: usize) -> Self { self }
}
impl<T: Iterator> ParIterator for T {
}
pub trait ParSliceLie<T> {
fn par_chunks(&self, n: usize) -> std::slice::Chunks<'_, T>;
}
pub trait ParSliceMutLie<T> {
fn par_chunks_exact_mut(&mut self, n: usize) -> std::slice::ChunksExactMut<'_, T>;
}
pub trait ParIntoIterLie<T> {
type IntoIter;
fn into_par_iter(self) -> Self::IntoIter;
}
pub trait ParIterLie<T> {
type Iter;
fn par_iter(&self) -> Self::Iter;
}
pub trait ParIterMutLie<'a, T> {
type Iter;
fn par_iter_mut(&'a mut self) -> Self::Iter;
}
pub fn join<A, B>(a: impl FnOnce() -> A, b: impl FnOnce() -> B) -> (A, B) {
let a = a();
let b = b();
(a, b)
}
impl<'a, T> ParSliceLie<T> for &'a [T] {
fn par_chunks(&self, n: usize) -> std::slice::Chunks<'_, T> {
self.chunks(n)
}
}
impl<'a, T> ParSliceLie<T> for &'a mut [T] {
fn par_chunks(&self, n: usize) -> std::slice::Chunks<'_, T> {
self.chunks(n)
}
}
impl<'a, T> ParSliceMutLie<T> for &'a mut [T] {
fn par_chunks_exact_mut(&mut self, n: usize) -> std::slice::ChunksExactMut<'_, T> {
self.chunks_exact_mut(n)
}
}
impl<'a, T> ParIterLie<T> for &'a [T] {
type Iter = std::slice::Iter<'a, T>;
fn par_iter(&self) -> Self::Iter {
self.iter()
}
}
impl<'a, T> ParIterMutLie<'a, T> for &'a mut [T] {
type Iter = std::slice::IterMut<'a, T>;
fn par_iter_mut(&'a mut self) -> Self::Iter {
self.iter_mut()
}
}
impl<T> ParIntoIterLie<T> for Vec<T> {
type IntoIter = std::vec::IntoIter<T>;
fn into_par_iter(self) -> Self::IntoIter {
self.into_iter()
}
}