@@ -3,7 +3,7 @@ use crate::internal_type_traits::{BoundedAbove, BoundedBelow, One, Zero};
3
3
use std:: cmp:: { max, min} ;
4
4
use std:: convert:: Infallible ;
5
5
use std:: marker:: PhantomData ;
6
- use std:: ops:: { Add , Mul } ;
6
+ use std:: ops:: { Add , BitAnd , BitOr , BitXor , Mul , Not } ;
7
7
8
8
// TODO Should I split monoid-related traits to another module?
9
9
pub trait Monoid {
68
68
}
69
69
}
70
70
71
+ pub struct BitOrOper < S > ( Infallible , PhantomData < fn ( ) -> S > ) ;
72
+ impl < S > Monoid for BitOrOper < S >
73
+ where
74
+ S : Copy + BitOr < Output = S > + Default ,
75
+ {
76
+ type S = S ;
77
+ fn identity ( ) -> Self :: S {
78
+ S :: default ( )
79
+ }
80
+ fn binary_operation ( a : & Self :: S , b : & Self :: S ) -> Self :: S {
81
+ * a | * b
82
+ }
83
+ }
84
+
85
+ pub struct BitAndOper < S > ( Infallible , PhantomData < fn ( ) -> S > ) ;
86
+ impl < S > Monoid for BitAndOper < S >
87
+ where
88
+ S : Copy + BitAnd < Output = S > + Not < Output = S > + Default ,
89
+ {
90
+ type S = S ;
91
+ fn identity ( ) -> Self :: S {
92
+ !S :: default ( )
93
+ }
94
+ fn binary_operation ( a : & Self :: S , b : & Self :: S ) -> Self :: S {
95
+ * a & * b
96
+ }
97
+ }
98
+
99
+ pub struct BitXorOper < S > ( Infallible , PhantomData < fn ( ) -> S > ) ;
100
+ impl < S > Monoid for BitXorOper < S >
101
+ where
102
+ S : Copy + BitXor < Output = S > + Default ,
103
+ {
104
+ type S = S ;
105
+ fn identity ( ) -> Self :: S {
106
+ S :: default ( )
107
+ }
108
+ fn binary_operation ( a : & Self :: S , b : & Self :: S ) -> Self :: S {
109
+ * a ^ * b
110
+ }
111
+ }
112
+
71
113
impl < M : Monoid > Default for Segtree < M > {
72
114
fn default ( ) -> Self {
73
115
Segtree :: new ( 0 )
0 commit comments