File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -681,13 +681,21 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
681681 /// and [`Policy::Threshold`] disjunctions for the `TapTree`.
682682 #[ cfg( feature = "compiler" ) ]
683683 fn num_tap_leaves ( & self ) -> usize {
684- match self {
685- Policy :: Or ( subs) => subs. iter ( ) . map ( |( _prob, pol) | pol. num_tap_leaves ( ) ) . sum ( ) ,
686- Policy :: Threshold ( k, subs) if * k == 1 => {
687- subs. iter ( ) . map ( |pol| pol. num_tap_leaves ( ) ) . sum ( )
688- }
689- _ => 1 ,
684+ use Policy :: * ;
685+
686+ let mut nums = vec ! [ ] ;
687+ for data in Arc :: new ( self ) . post_order_iter ( ) {
688+ let num_for_child_n = |n| nums[ data. child_indices [ n] ] ;
689+
690+ let num = match data. node {
691+ Or ( subs) => ( 0 ..subs. len ( ) ) . map ( num_for_child_n) . sum ( ) ,
692+ Threshold ( k, subs) if * k == 1 => ( 0 ..subs. len ( ) ) . map ( num_for_child_n) . sum ( ) ,
693+ _ => 1 ,
694+ } ;
695+ nums. push ( num) ;
690696 }
697+ // Ok to unwrap because we know we processed at least one node.
698+ nums. pop ( ) . unwrap ( )
691699 }
692700
693701 /// Does checks on the number of `TapLeaf`s.
You can’t perform that action at this time.
0 commit comments