151
151
#![ allow( missing_docs) ]
152
152
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
153
153
154
- use core:: iter:: { FromIterator } ;
154
+ use core:: iter:: FromIterator ;
155
155
use core:: mem:: swap;
156
156
use core:: ptr;
157
157
use core:: fmt;
@@ -186,7 +186,9 @@ impl<T: Clone> Clone for BinaryHeap<T> {
186
186
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
187
187
impl < T : Ord > Default for BinaryHeap < T > {
188
188
#[ inline]
189
- fn default ( ) -> BinaryHeap < T > { BinaryHeap :: new ( ) }
189
+ fn default ( ) -> BinaryHeap < T > {
190
+ BinaryHeap :: new ( )
191
+ }
190
192
}
191
193
192
194
#[ stable( feature = "binaryheap_debug" , since = "1.4.0" ) ]
@@ -207,7 +209,9 @@ impl<T: Ord> BinaryHeap<T> {
207
209
/// heap.push(4);
208
210
/// ```
209
211
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
210
- pub fn new ( ) -> BinaryHeap < T > { BinaryHeap { data : vec ! [ ] } }
212
+ pub fn new ( ) -> BinaryHeap < T > {
213
+ BinaryHeap { data : vec ! [ ] }
214
+ }
211
215
212
216
/// Creates an empty `BinaryHeap` with a specific capacity.
213
217
/// This preallocates enough memory for `capacity` elements,
@@ -296,7 +300,9 @@ impl<T: Ord> BinaryHeap<T> {
296
300
/// heap.push(4);
297
301
/// ```
298
302
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
299
- pub fn capacity ( & self ) -> usize { self . data . capacity ( ) }
303
+ pub fn capacity ( & self ) -> usize {
304
+ self . data . capacity ( )
305
+ }
300
306
301
307
/// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
302
308
/// given `BinaryHeap`. Does nothing if the capacity is already sufficient.
@@ -419,11 +425,13 @@ impl<T: Ord> BinaryHeap<T> {
419
425
pub fn push_pop ( & mut self , mut item : T ) -> T {
420
426
match self . data . get_mut ( 0 ) {
421
427
None => return item,
422
- Some ( top) => if * top > item {
423
- swap ( & mut item, top) ;
424
- } else {
425
- return item;
426
- } ,
428
+ Some ( top) => {
429
+ if * top > item {
430
+ swap ( & mut item, top) ;
431
+ } else {
432
+ return item;
433
+ }
434
+ }
427
435
}
428
436
429
437
self . sift_down ( 0 ) ;
@@ -522,7 +530,9 @@ impl<T: Ord> BinaryHeap<T> {
522
530
523
531
while hole. pos ( ) > start {
524
532
let parent = ( hole. pos ( ) - 1 ) / 2 ;
525
- if hole. element ( ) <= hole. get ( parent) { break ; }
533
+ if hole. element ( ) <= hole. get ( parent) {
534
+ break ;
535
+ }
526
536
hole. move_to ( parent) ;
527
537
}
528
538
}
@@ -541,7 +551,9 @@ impl<T: Ord> BinaryHeap<T> {
541
551
child = right;
542
552
}
543
553
// if we are already in order, stop.
544
- if hole. element ( ) >= hole. get ( child) { break ; }
554
+ if hole. element ( ) >= hole. get ( child) {
555
+ break ;
556
+ }
545
557
hole. move_to ( child) ;
546
558
child = 2 * hole. pos ( ) + 1 ;
547
559
}
@@ -555,11 +567,15 @@ impl<T: Ord> BinaryHeap<T> {
555
567
556
568
/// Returns the length of the binary heap.
557
569
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
558
- pub fn len ( & self ) -> usize { self . data . len ( ) }
570
+ pub fn len ( & self ) -> usize {
571
+ self . data . len ( )
572
+ }
559
573
560
574
/// Checks if the binary heap is empty.
561
575
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
562
- pub fn is_empty ( & self ) -> bool { self . len ( ) == 0 }
576
+ pub fn is_empty ( & self ) -> bool {
577
+ self . len ( ) == 0
578
+ }
563
579
564
580
/// Clears the binary heap, returning an iterator over the removed elements.
565
581
///
@@ -575,7 +591,9 @@ impl<T: Ord> BinaryHeap<T> {
575
591
576
592
/// Drops all items from the binary heap.
577
593
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
578
- pub fn clear ( & mut self ) { self . drain ( ) ; }
594
+ pub fn clear ( & mut self ) {
595
+ self . drain ( ) ;
596
+ }
579
597
}
580
598
581
599
/// Hole represents a hole in a slice i.e. an index without valid value
@@ -603,7 +621,9 @@ impl<'a, T> Hole<'a, T> {
603
621
}
604
622
605
623
#[ inline( always) ]
606
- fn pos ( & self ) -> usize { self . pos }
624
+ fn pos ( & self ) -> usize {
625
+ self . pos
626
+ }
607
627
608
628
/// Return a reference to the element removed
609
629
#[ inline( always) ]
@@ -647,7 +667,7 @@ impl<'a, T> Drop for Hole<'a, T> {
647
667
648
668
/// `BinaryHeap` iterator.
649
669
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
650
- pub struct Iter < ' a , T : ' a > {
670
+ pub struct Iter < ' a , T : ' a > {
651
671
iter : slice:: Iter < ' a , T > ,
652
672
}
653
673
@@ -664,16 +684,22 @@ impl<'a, T> Iterator for Iter<'a, T> {
664
684
type Item = & ' a T ;
665
685
666
686
#[ inline]
667
- fn next ( & mut self ) -> Option < & ' a T > { self . iter . next ( ) }
687
+ fn next ( & mut self ) -> Option < & ' a T > {
688
+ self . iter . next ( )
689
+ }
668
690
669
691
#[ inline]
670
- fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . iter . size_hint ( ) }
692
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
693
+ self . iter . size_hint ( )
694
+ }
671
695
}
672
696
673
697
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
674
698
impl < ' a , T > DoubleEndedIterator for Iter < ' a , T > {
675
699
#[ inline]
676
- fn next_back ( & mut self ) -> Option < & ' a T > { self . iter . next_back ( ) }
700
+ fn next_back ( & mut self ) -> Option < & ' a T > {
701
+ self . iter . next_back ( )
702
+ }
677
703
}
678
704
679
705
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -690,16 +716,22 @@ impl<T> Iterator for IntoIter<T> {
690
716
type Item = T ;
691
717
692
718
#[ inline]
693
- fn next ( & mut self ) -> Option < T > { self . iter . next ( ) }
719
+ fn next ( & mut self ) -> Option < T > {
720
+ self . iter . next ( )
721
+ }
694
722
695
723
#[ inline]
696
- fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . iter . size_hint ( ) }
724
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
725
+ self . iter . size_hint ( )
726
+ }
697
727
}
698
728
699
729
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
700
730
impl < T > DoubleEndedIterator for IntoIter < T > {
701
731
#[ inline]
702
- fn next_back ( & mut self ) -> Option < T > { self . iter . next_back ( ) }
732
+ fn next_back ( & mut self ) -> Option < T > {
733
+ self . iter . next_back ( )
734
+ }
703
735
}
704
736
705
737
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -716,16 +748,22 @@ impl<'a, T: 'a> Iterator for Drain<'a, T> {
716
748
type Item = T ;
717
749
718
750
#[ inline]
719
- fn next ( & mut self ) -> Option < T > { self . iter . next ( ) }
751
+ fn next ( & mut self ) -> Option < T > {
752
+ self . iter . next ( )
753
+ }
720
754
721
755
#[ inline]
722
- fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . iter . size_hint ( ) }
756
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
757
+ self . iter . size_hint ( )
758
+ }
723
759
}
724
760
725
761
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
726
762
impl < ' a , T : ' a > DoubleEndedIterator for Drain < ' a , T > {
727
763
#[ inline]
728
- fn next_back ( & mut self ) -> Option < T > { self . iter . next_back ( ) }
764
+ fn next_back ( & mut self ) -> Option < T > {
765
+ self . iter . next_back ( )
766
+ }
729
767
}
730
768
731
769
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -753,7 +791,7 @@ impl<T> From<BinaryHeap<T>> for Vec<T> {
753
791
754
792
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
755
793
impl < T : Ord > FromIterator < T > for BinaryHeap < T > {
756
- fn from_iter < I : IntoIterator < Item = T > > ( iter : I ) -> BinaryHeap < T > {
794
+ fn from_iter < I : IntoIterator < Item = T > > ( iter : I ) -> BinaryHeap < T > {
757
795
BinaryHeap :: from ( iter. into_iter ( ) . collect :: < Vec < _ > > ( ) )
758
796
}
759
797
}
@@ -796,7 +834,7 @@ impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord {
796
834
797
835
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
798
836
impl < T : Ord > Extend < T > for BinaryHeap < T > {
799
- fn extend < I : IntoIterator < Item = T > > ( & mut self , iterable : I ) {
837
+ fn extend < I : IntoIterator < Item = T > > ( & mut self , iterable : I ) {
800
838
let iter = iterable. into_iter ( ) ;
801
839
let ( lower, _) = iter. size_hint ( ) ;
802
840
@@ -810,7 +848,7 @@ impl<T: Ord> Extend<T> for BinaryHeap<T> {
810
848
811
849
#[ stable( feature = "extend_ref" , since = "1.2.0" ) ]
812
850
impl < ' a , T : ' a + Ord + Copy > Extend < & ' a T > for BinaryHeap < T > {
813
- fn extend < I : IntoIterator < Item = & ' a T > > ( & mut self , iter : I ) {
851
+ fn extend < I : IntoIterator < Item = & ' a T > > ( & mut self , iter : I ) {
814
852
self . extend ( iter. into_iter ( ) . cloned ( ) ) ;
815
853
}
816
854
}
0 commit comments