@@ -24,7 +24,10 @@ and nodes identifier are in the interval [0 . . *n*).
24
24
25
25
*/
26
26
27
- use crate :: utils:: Granularity ;
27
+ use crate :: {
28
+ traits:: { LenderIntoIter , RandomAccessGraph } ,
29
+ utils:: Granularity ,
30
+ } ;
28
31
29
32
use super :: { LenderLabel , NodeLabelsLender , ParMapFold } ;
30
33
@@ -193,6 +196,30 @@ pub trait SequentialLabeling {
193
196
thread_pool,
194
197
)
195
198
}
199
+
200
+ /// Returns true if the two provided sorted labelings are equal.
201
+ fn equal_sorted < L0 : SequentialLabeling , L1 : SequentialLabeling < Label = L0 :: Label > > (
202
+ l0 : & L0 ,
203
+ l1 : & L1 ,
204
+ ) -> bool
205
+ where
206
+ for < ' a > L0 :: Lender < ' a > : SortedLender ,
207
+ for < ' a > L1 :: Lender < ' a > : SortedLender ,
208
+ for < ' a , ' b > LenderIntoIter < ' b , L0 :: Lender < ' a > > : SortedIterator ,
209
+ for < ' a , ' b > LenderIntoIter < ' b , L0 :: Lender < ' a > > : SortedIterator ,
210
+ L0 :: Label : PartialEq ,
211
+ {
212
+ if l0. num_nodes ( ) != l1. num_nodes ( ) {
213
+ return false ;
214
+ }
215
+ for_ ! ( ( ( node0, succ0) , ( node1, succ1) ) in l0. iter( ) . zip( l1. iter( ) ) {
216
+ debug_assert_eq!( node0, node1) ;
217
+ if !succ0. into_iter( ) . eq( succ1. into_iter( ) ) {
218
+ return false ;
219
+ }
220
+ } ) ;
221
+ true
222
+ }
196
223
}
197
224
198
225
/// Convenience type alias for the iterator over the labels of a node
@@ -316,6 +343,27 @@ pub trait RandomAccessLabeling: SequentialLabeling {
316
343
317
344
/// Returns the number of labels associated with a node.
318
345
fn outdegree ( & self , node_id : usize ) -> usize ;
346
+
347
+ /// Checks the sequential vs. random-access implementation of a sorted
348
+ /// random-access labeling.
349
+ ///
350
+ /// Note that this method will check that the sequential and random-access
351
+ /// iterators on labels of each node are identical, and that the number of
352
+ /// nodes returned by the sequential iterator is the same as the number of
353
+ /// nodes returned by [`num_nodes`](SequentialLabeling::num_nodes).
354
+ fn check_impl < L : RandomAccessLabeling > ( l : L ) -> bool
355
+ where
356
+ L :: Label : PartialEq ,
357
+ {
358
+ let mut num_nodes = 0 ;
359
+ for_ ! ( ( node, succ) in l. iter( ) {
360
+ num_nodes += 1 ;
361
+ if !succ. into_iter( ) . eq( l. labels( node) . into_iter( ) ) {
362
+ return false ;
363
+ }
364
+ } ) ;
365
+ num_nodes == l. num_nodes ( )
366
+ }
319
367
}
320
368
321
369
/// A struct used to make it easy to implement sequential access
0 commit comments