@@ -18,6 +18,7 @@ use io;
1818use secp256k1:: { self , Secp256k1 } ;
1919
2020use core:: fmt;
21+ use core:: cmp:: Reverse ;
2122#[ cfg( feature = "std" ) ]
2223use std:: error;
2324
@@ -208,9 +209,9 @@ impl TaprootSpendInfo {
208209 I : IntoIterator < Item = ( u64 , Script ) > ,
209210 C : secp256k1:: Verification ,
210211 {
211- let mut node_weights = BinaryHeap :: < ( u128 , NodeInfo ) > :: new ( ) ;
212+ let mut node_weights = BinaryHeap :: < ( Reverse < u128 > , NodeInfo ) > :: new ( ) ;
212213 for ( p, leaf) in script_weights {
213- node_weights. push ( ( p as u128 , NodeInfo :: new_leaf_with_ver ( leaf, LeafVersion :: default ( ) ) ) ) ;
214+ node_weights. push ( ( Reverse ( p as u128 ) , NodeInfo :: new_leaf_with_ver ( leaf, LeafVersion :: default ( ) ) ) ) ;
214215 }
215216 if node_weights. is_empty ( ) {
216217 return Err ( TaprootBuilderError :: IncompleteTree ) ;
@@ -223,7 +224,7 @@ impl TaprootSpendInfo {
223224 // N.B.: p1 + p2 can never actually saturate as you would need to have 2**64 max u64s
224225 // from the input to overflow. However, saturating is a reasonable behavior here as
225226 // huffman tree construction would treat all such elements as "very likely".
226- let p = p1. saturating_add ( p2) ;
227+ let p = Reverse ( p1. 0 . saturating_add ( p2. 0 ) ) ;
227228 node_weights. push ( ( p, NodeInfo :: combine ( s1, s2) ?) ) ;
228229 }
229230 // Every iteration of the loop reduces the node_weights.len() by exactly 1
0 commit comments