File tree Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Expand file tree Collapse file tree 1 file changed +5
-7
lines changed Original file line number Diff line number Diff line change @@ -10,14 +10,14 @@ where
10
10
{
11
11
count : usize ,
12
12
items : Vec < T > ,
13
- comparator : Box < dyn Fn ( & T , & T ) -> bool > ,
13
+ comparator : fn ( & T , & T ) -> bool ,
14
14
}
15
15
16
16
impl < T > Heap < T >
17
17
where
18
18
T : Default ,
19
19
{
20
- pub fn new ( comparator : Box < dyn Fn ( & T , & T ) -> bool > ) -> Self {
20
+ pub fn new ( comparator : fn ( & T , & T ) -> bool ) -> Self {
21
21
Self {
22
22
count : 0 ,
23
23
// Add a default in the first spot to offset indexes
@@ -113,8 +113,7 @@ impl MinHeap {
113
113
where
114
114
T : Default + Ord ,
115
115
{
116
- let comparator = |a : & T , b : & T | a < b;
117
- Heap :: new ( Box :: new ( comparator) )
116
+ Heap :: new ( |a, b| a < b)
118
117
}
119
118
}
120
119
@@ -125,8 +124,7 @@ impl MaxHeap {
125
124
where
126
125
T : Default + Ord ,
127
126
{
128
- let comparator = |a : & T , b : & T | a > b;
129
- Heap :: new ( Box :: new ( comparator) )
127
+ Heap :: new ( |a, b| a > b)
130
128
}
131
129
}
132
130
@@ -173,7 +171,7 @@ mod tests {
173
171
174
172
#[ test]
175
173
fn test_key_heap ( ) {
176
- let mut heap: Heap < Point > = Heap :: new ( Box :: new ( |a, b| a. 0 < b. 0 ) ) ;
174
+ let mut heap: Heap < Point > = Heap :: new ( |a, b| a. 0 < b. 0 ) ;
177
175
heap. add ( Point ( 1 , 5 ) ) ;
178
176
heap. add ( Point ( 3 , 10 ) ) ;
179
177
heap. add ( Point ( -2 , 4 ) ) ;
You can’t perform that action at this time.
0 commit comments