-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmonoid.rs
47 lines (40 loc) · 1.06 KB
/
monoid.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
use lift::{SemiGroup, Monoid};
use std::hash::Hash;
use std::collections::linked_list::LinkedList;
use std::collections::vec_deque::VecDeque;
use std::collections::{BTreeSet, HashSet, BinaryHeap};
//Implementation for numeric Monoids
monoid_num!(i8, 0);
monoid_num!(i16, 0);
monoid_num!(i32, 0);
monoid_num!(i64, 0);
monoid_num!(u8, 0);
monoid_num!(u16, 0);
monoid_num!(u32, 0);
monoid_num!(u64, 0);
monoid_num!(isize, 0);
monoid_num!(usize, 0);
monoid_num!(f32, 0.0);
monoid_num!(f64, 0.0);
//Implementation of Monoid for String
impl Monoid for String {
fn id() -> Self::A {
String::from("")
}
}
//Implementation of Monoid for HashSet
impl<T: Hash + Clone + Eq> Monoid for HashSet<T> {
fn id() -> Self::A {
HashSet::new()
}
}
//Implementation of Monoid for Vec<T>
monoid!(Vec);
//Implementation of Monoid for LinkedList<T>
monoid!(LinkedList);
//Implementation of Monoid for VecDeque<T>
monoid!(VecDeque);
//Implementation of Monoid for BinaryHeap<T>
monoid_ord!(BinaryHeap);
//Implementation of Monoid for BTreeSet<T>
monoid_ord!(BTreeSet);