@@ -39,7 +39,7 @@ impl <T: Copy Ord> PriorityQueue<T> {
39
39
/// Pop the greatest item from the queue - fails if empty
40
40
fn pop ( & mut self ) -> T {
41
41
let mut item = self . data . pop ( ) ;
42
- if self . is_not_empty ( ) { item <-> self . data [ 0 ] ; self . siftup ( 0 ) ; }
42
+ if self . is_not_empty ( ) { item <-> self . data [ 0 ] ; self . siftdown ( 0 ) ; }
43
43
item
44
44
}
45
45
@@ -51,15 +51,15 @@ impl <T: Copy Ord> PriorityQueue<T> {
51
51
/// Push an item onto the queue
52
52
fn push ( & mut self , item : T ) {
53
53
self . data . push ( item) ;
54
- self . siftdown ( 0 , self . len ( ) - 1 ) ;
54
+ self . siftup ( 0 , self . len ( ) - 1 ) ;
55
55
}
56
56
57
57
/// Optimized version of a push followed by a pop
58
58
fn push_pop ( & mut self , item : T ) -> T {
59
59
let mut item = item;
60
60
if self . is_not_empty ( ) && self . data [ 0 ] > item {
61
61
item <-> self . data [ 0 ] ;
62
- self . siftup ( 0 ) ;
62
+ self . siftdown ( 0 ) ;
63
63
}
64
64
item
65
65
}
@@ -68,7 +68,7 @@ impl <T: Copy Ord> PriorityQueue<T> {
68
68
fn replace ( & mut self , item : T ) -> T {
69
69
let mut item = item;
70
70
item <-> self . data [ 0 ] ;
71
- self . siftup ( 0 ) ;
71
+ self . siftdown ( 0 ) ;
72
72
item
73
73
}
74
74
@@ -82,7 +82,7 @@ impl <T: Copy Ord> PriorityQueue<T> {
82
82
while end > 1 {
83
83
end -= 1 ;
84
84
q. data [ end] <-> q. data [ 0 ] ;
85
- unsafe { q. siftup_range ( 0 , end) } // purity-checking workaround
85
+ unsafe { q. siftdown_range ( 0 , end) } // purity-checking workaround
86
86
}
87
87
q. to_vec ( )
88
88
}
@@ -92,12 +92,12 @@ impl <T: Copy Ord> PriorityQueue<T> {
92
92
let mut n = q. len ( ) / 2 ;
93
93
while n > 0 {
94
94
n -= 1 ;
95
- unsafe { q. siftup ( n) } ; // purity-checking workaround
95
+ unsafe { q. siftdown ( n) } ; // purity-checking workaround
96
96
}
97
97
q
98
98
}
99
99
100
- priv fn siftdown ( & mut self , startpos : uint , pos : uint ) {
100
+ priv fn siftup ( & mut self , startpos : uint , pos : uint ) {
101
101
let mut pos = pos;
102
102
let newitem = self . data [ pos] ;
103
103
@@ -114,7 +114,7 @@ impl <T: Copy Ord> PriorityQueue<T> {
114
114
self . data [ pos] = newitem;
115
115
}
116
116
117
- priv fn siftup_range ( & mut self , pos : uint , endpos : uint ) {
117
+ priv fn siftdown_range ( & mut self , pos : uint , endpos : uint ) {
118
118
let mut pos = pos;
119
119
let startpos = pos;
120
120
let newitem = self . data [ pos] ;
@@ -131,11 +131,11 @@ impl <T: Copy Ord> PriorityQueue<T> {
131
131
childpos = 2 * pos + 1 ;
132
132
}
133
133
self . data [ pos] = newitem;
134
- self . siftdown ( startpos, pos) ;
134
+ self . siftup ( startpos, pos) ;
135
135
}
136
136
137
- priv fn siftup ( & mut self , pos : uint ) {
138
- self . siftup_range ( pos, self . len ( ) ) ;
137
+ priv fn siftdown ( & mut self , pos : uint ) {
138
+ self . siftdown_range ( pos, self . len ( ) ) ;
139
139
}
140
140
}
141
141
0 commit comments