@@ -49,7 +49,7 @@ struct Edge {
49
49
target : Index ,
50
50
}
51
51
52
- impl < T : Eq + Hash > TransitiveRelation < T > {
52
+ impl < T : Eq + Hash + Copy > TransitiveRelation < T > {
53
53
pub fn is_empty ( & self ) -> bool {
54
54
self . edges . is_empty ( )
55
55
}
@@ -58,8 +58,8 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
58
58
self . elements . iter ( )
59
59
}
60
60
61
- fn index ( & self , a : & T ) -> Option < Index > {
62
- self . elements . get_index_of ( a) . map ( Index )
61
+ fn index ( & self , a : T ) -> Option < Index > {
62
+ self . elements . get_index_of ( & a) . map ( Index )
63
63
}
64
64
65
65
fn add_index ( & mut self , a : T ) -> Index {
@@ -76,12 +76,12 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
76
76
/// `None`.
77
77
pub fn maybe_map < F , U > ( & self , mut f : F ) -> Option < TransitiveRelation < U > >
78
78
where
79
- F : FnMut ( & T ) -> Option < U > ,
80
- U : Clone + Debug + Eq + Hash + Clone ,
79
+ F : FnMut ( T ) -> Option < U > ,
80
+ U : Clone + Debug + Eq + Hash + Copy ,
81
81
{
82
82
let mut result = TransitiveRelation :: default ( ) ;
83
83
for edge in & self . edges {
84
- result. add ( f ( & self . elements [ edge. source . 0 ] ) ?, f ( & self . elements [ edge. target . 0 ] ) ?) ;
84
+ result. add ( f ( self . elements [ edge. source . 0 ] ) ?, f ( self . elements [ edge. target . 0 ] ) ?) ;
85
85
}
86
86
Some ( result)
87
87
}
@@ -100,7 +100,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
100
100
}
101
101
102
102
/// Checks whether `a < target` (transitively)
103
- pub fn contains ( & self , a : & T , b : & T ) -> bool {
103
+ pub fn contains ( & self , a : T , b : T ) -> bool {
104
104
match ( self . index ( a) , self . index ( b) ) {
105
105
( Some ( a) , Some ( b) ) => self . with_closure ( |closure| closure. contains ( a. 0 , b. 0 ) ) ,
106
106
( None , _) | ( _, None ) => false ,
@@ -113,10 +113,10 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
113
113
/// Really this probably ought to be `impl Iterator<Item = &T>`, but
114
114
/// I'm too lazy to make that work, and -- given the caching
115
115
/// strategy -- it'd be a touch tricky anyhow.
116
- pub fn reachable_from ( & self , a : & T ) -> Vec < & T > {
116
+ pub fn reachable_from ( & self , a : T ) -> Vec < T > {
117
117
match self . index ( a) {
118
118
Some ( a) => {
119
- self . with_closure ( |closure| closure. iter ( a. 0 ) . map ( |i| & self . elements [ i] ) . collect ( ) )
119
+ self . with_closure ( |closure| closure. iter ( a. 0 ) . map ( |i| self . elements [ i] ) . collect ( ) )
120
120
}
121
121
None => vec ! [ ] ,
122
122
}
@@ -157,15 +157,15 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
157
157
/// a -> a1
158
158
/// b -> b1
159
159
/// ```
160
- pub fn postdom_upper_bound ( & self , a : & T , b : & T ) -> Option < & T > {
160
+ pub fn postdom_upper_bound ( & self , a : T , b : T ) -> Option < T > {
161
161
let mubs = self . minimal_upper_bounds ( a, b) ;
162
162
self . mutual_immediate_postdominator ( mubs)
163
163
}
164
164
165
165
/// Viewing the relation as a graph, computes the "mutual
166
166
/// immediate postdominator" of a set of points (if one
167
167
/// exists). See `postdom_upper_bound` for details.
168
- pub fn mutual_immediate_postdominator < ' a > ( & ' a self , mut mubs : Vec < & ' a T > ) -> Option < & ' a T > {
168
+ pub fn mutual_immediate_postdominator < ' a > ( & ' a self , mut mubs : Vec < T > ) -> Option < T > {
169
169
loop {
170
170
match mubs. len ( ) {
171
171
0 => return None ,
@@ -189,7 +189,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
189
189
/// internal indices).
190
190
///
191
191
/// Note that this set can, in principle, have any size.
192
- pub fn minimal_upper_bounds ( & self , a : & T , b : & T ) -> Vec < & T > {
192
+ pub fn minimal_upper_bounds ( & self , a : T , b : T ) -> Vec < T > {
193
193
let ( Some ( mut a) , Some ( mut b) ) = ( self . index ( a) , self . index ( b) ) else {
194
194
return vec ! [ ] ;
195
195
} ;
@@ -267,7 +267,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
267
267
lub_indices
268
268
. into_iter ( )
269
269
. rev ( ) // (4)
270
- . map ( |i| & self . elements [ i] )
270
+ . map ( |i| self . elements [ i] )
271
271
. collect ( )
272
272
}
273
273
@@ -290,7 +290,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
290
290
///
291
291
/// then `parents(a)` returns `[b, c]`. The `postdom_parent` function
292
292
/// would further reduce this to just `f`.
293
- pub fn parents ( & self , a : & T ) -> Vec < & T > {
293
+ pub fn parents ( & self , a : T ) -> Vec < T > {
294
294
let Some ( a) = self . index ( a) else {
295
295
return vec ! [ ] ;
296
296
} ;
@@ -314,7 +314,7 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
314
314
ancestors
315
315
. into_iter ( )
316
316
. rev ( ) // (4)
317
- . map ( |i| & self . elements [ i] )
317
+ . map ( |i| self . elements [ i] )
318
318
. collect ( )
319
319
}
320
320
@@ -350,10 +350,10 @@ impl<T: Eq + Hash> TransitiveRelation<T> {
350
350
351
351
/// Lists all the base edges in the graph: the initial _non-transitive_ set of element
352
352
/// relations, which will be later used as the basis for the transitive closure computation.
353
- pub fn base_edges ( & self ) -> impl Iterator < Item = ( & T , & T ) > {
353
+ pub fn base_edges ( & self ) -> impl Iterator < Item = ( T , T ) > + ' _ {
354
354
self . edges
355
355
. iter ( )
356
- . map ( move |edge| ( & self . elements [ edge. source . 0 ] , & self . elements [ edge. target . 0 ] ) )
356
+ . map ( move |edge| ( self . elements [ edge. source . 0 ] , self . elements [ edge. target . 0 ] ) )
357
357
}
358
358
}
359
359
0 commit comments