@@ -77,13 +77,21 @@ pure fn lt<K: Ord + TotalOrd, V>(a: &TreeMap<K, V>,
77
77
78
78
impl <K : Ord + TotalOrd , V > Ord for TreeMap < K , V > {
79
79
#[ inline( always) ]
80
- pure fn lt ( & self , other : & TreeMap < K , V > ) -> bool { lt ( self , other) }
80
+ pure fn lt ( & self , other : & TreeMap < K , V > ) -> bool {
81
+ lt ( self , other)
82
+ }
81
83
#[ inline( always) ]
82
- pure fn le ( & self , other : & TreeMap < K , V > ) -> bool { !lt ( other, self ) }
84
+ pure fn le ( & self , other : & TreeMap < K , V > ) -> bool {
85
+ !lt ( other, self )
86
+ }
83
87
#[ inline( always) ]
84
- pure fn ge ( & self , other : & TreeMap < K , V > ) -> bool { !lt ( self , other) }
88
+ pure fn ge ( & self , other : & TreeMap < K , V > ) -> bool {
89
+ !lt ( self , other)
90
+ }
85
91
#[ inline( always) ]
86
- pure fn gt ( & self , other : & TreeMap < K , V > ) -> bool { lt ( other, self ) }
92
+ pure fn gt ( & self , other : & TreeMap < K , V > ) -> bool {
93
+ lt ( other, self )
94
+ }
87
95
}
88
96
89
97
impl < ' self , K : TotalOrd , V > BaseIter < ( & ' self K , & ' self V ) > for TreeMap < K , V > {
@@ -141,9 +149,9 @@ impl<K: TotalOrd, V> Map<K, V> for TreeMap<K, V> {
141
149
match * current {
142
150
Some ( ref r) => {
143
151
match key. cmp ( & r. key ) {
144
- Less => current = & r. left ,
145
- Greater => current = & r. right ,
146
- Equal => return Some ( & r. value )
152
+ Less => current = & r. left ,
153
+ Greater => current = & r. right ,
154
+ Equal => return Some ( & r. value )
147
155
}
148
156
}
149
157
None => return None
@@ -236,24 +244,19 @@ pub struct TreeSet<T> {
236
244
237
245
impl < T : TotalOrd > BaseIter < T > for TreeSet < T > {
238
246
/// Visit all values in order
239
- #[ inline( always) ]
240
247
pure fn each ( & self , f : & fn ( & T ) -> bool ) { self . map . each_key ( f) }
241
- #[ inline( always) ]
242
248
pure fn size_hint ( & self ) -> Option < uint > { Some ( self . len ( ) ) }
243
249
}
244
250
245
251
impl < T : TotalOrd > ReverseIter < T > for TreeSet < T > {
246
252
/// Visit all values in reverse order
247
- #[ inline( always) ]
248
253
pure fn each_reverse ( & self , f : & fn ( & T ) -> bool ) {
249
254
self . map . each_key_reverse ( f)
250
255
}
251
256
}
252
257
253
258
impl < T : Eq + TotalOrd > Eq for TreeSet < T > {
254
- #[ inline( always) ]
255
259
pure fn eq ( & self , other : & TreeSet < T > ) -> bool { self . map == other. map }
256
- #[ inline( always) ]
257
260
pure fn ne ( & self , other : & TreeSet < T > ) -> bool { self . map != other. map }
258
261
}
259
262
@@ -270,35 +273,29 @@ impl<T: Ord + TotalOrd> Ord for TreeSet<T> {
270
273
271
274
impl < T : TotalOrd > Container for TreeSet < T > {
272
275
/// Return the number of elements in the set
273
- #[ inline( always) ]
274
276
pure fn len ( & self ) -> uint { self . map . len ( ) }
275
277
276
278
/// Return true if the set contains no elements
277
- #[ inline( always) ]
278
279
pure fn is_empty ( & self ) -> bool { self . map . is_empty ( ) }
279
280
}
280
281
281
282
impl < T : TotalOrd > Mutable for TreeSet < T > {
282
283
/// Clear the set, removing all values.
283
- #[ inline( always) ]
284
284
fn clear ( & mut self ) { self . map . clear ( ) }
285
285
}
286
286
287
287
impl < T : TotalOrd > Set < T > for TreeSet < T > {
288
288
/// Return true if the set contains a value
289
- #[ inline( always) ]
290
289
pure fn contains ( & self , value : & T ) -> bool {
291
290
self . map . contains_key ( value)
292
291
}
293
292
294
293
/// Add a value to the set. Return true if the value was not already
295
294
/// present in the set.
296
- #[ inline( always) ]
297
295
fn insert ( & mut self , value : T ) -> bool { self . map . insert ( value, ( ) ) }
298
296
299
297
/// Remove a value from the set. Return true if the value was
300
298
/// present in the set.
301
- #[ inline( always) ]
302
299
fn remove ( & mut self , value : & T ) -> bool { self . map . remove ( value) }
303
300
304
301
/// Return true if the set has no elements in common with `other`.
@@ -323,7 +320,6 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
323
320
}
324
321
325
322
/// Return true if the set is a subset of another
326
- #[ inline( always) ]
327
323
pure fn is_subset ( & self , other : & TreeSet < T > ) -> bool {
328
324
other. is_superset ( self )
329
325
}
@@ -492,12 +488,10 @@ impl<T: TotalOrd> Set<T> for TreeSet<T> {
492
488
493
489
pub impl < T : TotalOrd > TreeSet < T > {
494
490
/// Create an empty TreeSet
495
- #[ inline( always) ]
496
491
static pure fn new( ) -> TreeSet <T > { TreeSet { map: TreeMap :: new( ) } }
497
492
498
493
/// Get a lazy iterator over the values in the set.
499
494
/// Requires that it be frozen (immutable).
500
- #[ inline( always) ]
501
495
pure fn iter ( & self ) -> TreeSetIterator /& self <T > {
502
496
TreeSetIterator { iter: self . map . iter ( ) }
503
497
}
@@ -510,15 +504,13 @@ pub struct TreeSetIterator<T> {
510
504
511
505
/// Advance the iterator to the next node (in order). If this iterator is
512
506
/// finished, does nothing.
513
- #[ inline( always) ]
514
507
pub fn set_next<T >( iter: & mut TreeSetIterator /& r<T >) -> Option <& r/T > {
515
508
do map_next( & mut iter. iter) . map |& ( value, _) | { value }
516
509
}
517
510
518
511
/// Advance the iterator through the set
519
- #[ inline( always) ]
520
- pub fn set_advance<T >( iter: & mut TreeSetIterator /& r<T >,
521
- f: & fn ( & r/T ) -> bool ) {
512
+ fn set_advance<T >( iter: & mut TreeSetIterator /& r<T >,
513
+ f: & fn ( & r/T ) -> bool ) {
522
514
do map_advance( & mut iter. iter) |( k, _) | { f( k) }
523
515
}
524
516
@@ -540,15 +532,15 @@ pub impl<K: TotalOrd, V> TreeNode<K, V> {
540
532
}
541
533
542
534
pure fn each<K : TotalOrd , V >( node: & r/Option <~TreeNode <K , V >>,
543
- f: & fn ( & ( & r/K , & r/V ) ) -> bool ) {
535
+ f: & fn ( & ( & r/K , & r/V ) ) -> bool ) {
544
536
for node. each |x| {
545
537
each( & x. left, f) ;
546
538
if f( & ( & x. key, & x. value) ) { each( & x. right, f) }
547
539
}
548
540
}
549
541
550
542
pure fn each_reverse<K : TotalOrd , V >( node: & r/Option <~TreeNode <K , V >>,
551
- f: & fn ( & ( & r/K , & r/V ) ) -> bool ) {
543
+ f: & fn ( & ( & r/K , & r/V ) ) -> bool ) {
552
544
for node. each |x| {
553
545
each_reverse( & x. right, f) ;
554
546
if f( & ( & x. key, & x. value) ) { each_reverse( & x. left, f) }
@@ -673,20 +665,20 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
673
665
skew( save) ;
674
666
675
667
match save. right {
676
- Some ( ref mut right) => {
677
- skew( right) ;
678
- match right. right {
679
- Some ( ref mut x) => { skew( x) } ,
680
- None => ( )
668
+ Some ( ref mut right) => {
669
+ skew( right) ;
670
+ match right. right {
671
+ Some ( ref mut x) => { skew( x) } ,
672
+ None => ( )
673
+ }
681
674
}
682
- }
683
- None => ( )
675
+ None => ( )
684
676
}
685
677
686
678
split( save) ;
687
679
match save. right {
688
- Some ( ref mut x) => { split( x) } ,
689
- None => ( )
680
+ Some ( ref mut x) => { split( x) } ,
681
+ None => ( )
690
682
}
691
683
}
692
684
@@ -1141,30 +1133,25 @@ mod test_set {
1141
1133
1142
1134
#[ test]
1143
1135
fn test_difference( ) {
1144
- fn check_difference( a: & [ int] , b: & [ int] , expected: & [ int] ) {
1145
- let mut set_a = TreeSet :: new( ) ;
1146
- let mut set_b = TreeSet :: new( ) ;
1136
+ let mut a = TreeSet :: new( ) ;
1137
+ let mut b = TreeSet :: new( ) ;
1147
1138
1148
- for a. each |x| { fail_unless!( set_a. insert( * x) ) }
1149
- for b. each |y| { fail_unless!( set_b. insert( * y) ) }
1139
+ fail_unless!( a. insert( 1 ) ) ;
1140
+ fail_unless!( a. insert( 3 ) ) ;
1141
+ fail_unless!( a. insert( 5 ) ) ;
1142
+ fail_unless!( a. insert( 9 ) ) ;
1143
+ fail_unless!( a. insert( 11 ) ) ;
1150
1144
1151
- let mut i = 0 ;
1152
- for set_a. difference( & set_b) |x| {
1153
- fail_unless!( * x == expected[ i] ) ;
1154
- i += 1 ;
1155
- }
1156
- fail_unless!( i == expected. len( ) ) ;
1157
- }
1145
+ fail_unless!( b. insert( 3 ) ) ;
1146
+ fail_unless!( b. insert( 9 ) ) ;
1158
1147
1159
- check_difference( [ ] , [ ] , [ ] ) ;
1160
- check_difference( [ 1 , 12 ] , [ ] , [ 1 , 12 ] ) ;
1161
- check_difference( [ ] , [ 1 , 2 , 3 , 9 ] , [ ] ) ;
1162
- check_difference( [ 1 , 3 , 5 , 9 , 11 ] ,
1163
- [ 3 , 9 ] ,
1164
- [ 1 , 5 , 11 ] ) ;
1165
- check_difference( [ -5 , 11 , 22 , 33 , 40 , 42 ] ,
1166
- [ -12 , -5 , 14 , 23 , 34 , 38 , 39 , 50 ] ,
1167
- [ 11 , 22 , 33 , 40 , 42 ] ) ;
1148
+ let mut i = 0 ;
1149
+ let expected = [ 1 , 5 , 11 ] ;
1150
+ for a. difference( & b) |x| {
1151
+ fail_unless!( * x == expected[ i] ) ;
1152
+ i += 1
1153
+ }
1154
+ fail_unless!( i == expected. len( ) ) ;
1168
1155
}
1169
1156
1170
1157
#[ test]
0 commit comments