@@ -30,7 +30,6 @@ use gen_combinations::CombinationIterator;
30
30
use num_bigint:: BigUint ;
31
31
use num_traits:: { Num , ToPrimitive } ;
32
32
pub use small_boolean_function:: SmallBooleanFunction ;
33
- use std:: any:: Any ;
34
33
use std:: collections:: { HashMap , HashSet } ;
35
34
use std:: fmt:: Debug ;
36
35
use std:: ops:: { BitXor , BitXorAssign , Not } ;
@@ -49,7 +48,7 @@ pub enum BooleanFunctionType {
49
48
///
50
49
/// You could use this trait via the [BooleanFunction] type, which encapsulates the [BooleanFunctionImpl] trait.
51
50
#[ enum_dispatch]
52
- pub trait BooleanFunctionImpl : Debug + Any {
51
+ pub trait BooleanFunctionImpl : Debug {
53
52
/// Variable count of the Boolean function.
54
53
fn variables_count ( & self ) -> usize ;
55
54
@@ -63,7 +62,6 @@ pub trait BooleanFunctionImpl: Debug + Any {
63
62
/// Maximum input value for the Boolean function, as unsigned 32-bit integer.
64
63
///
65
64
/// This is equal to $2^n - 1$, where $n$ is the number of variables.
66
- #[ inline]
67
65
fn get_max_input_value ( & self ) -> u32 {
68
66
( 1 << self . variables_count ( ) ) - 1
69
67
}
@@ -623,16 +621,6 @@ pub trait BooleanFunctionImpl: Debug + Any {
623
621
self . biguint_truth_table ( ) . to_u64 ( )
624
622
}
625
623
626
- /// Returns Boolean function as `dyn Any` object.
627
- ///
628
- /// See [core::any::Any]
629
- fn as_any ( & self ) -> & dyn Any ;
630
-
631
- /// Returns Boolean function as mutable `dyn Any` object.
632
- ///
633
- /// See [core::any::Any]
634
- fn as_any_mut ( & mut self ) -> & mut dyn Any ;
635
-
636
624
// TODO almost bent, mul (and tt), iterate on values
637
625
}
638
626
@@ -662,57 +650,32 @@ impl BitXorAssign for BooleanFunction {
662
650
panic ! ( "{}" , XOR_DIFFERENT_VAR_COUNT_PANIC_MSG ) ;
663
651
}
664
652
match (
665
- self . get_boolean_function_type ( ) ,
666
- rhs. get_boolean_function_type ( ) ,
653
+ self ,
654
+ rhs,
667
655
) {
668
- ( BooleanFunctionType :: Small , BooleanFunctionType :: Small ) => {
669
- let self_small_boolean_function = self
670
- . as_any_mut ( )
671
- . downcast_mut :: < SmallBooleanFunction > ( )
672
- . unwrap ( ) ;
673
- let rhs_small_boolean_function =
674
- rhs. as_any ( ) . downcast_ref :: < SmallBooleanFunction > ( ) . unwrap ( ) ;
675
- * self_small_boolean_function ^= * rhs_small_boolean_function;
676
- }
677
- ( BooleanFunctionType :: Small , BooleanFunctionType :: Big ) => {
678
- let self_small_boolean_function = self
679
- . as_any_mut ( )
680
- . downcast_mut :: < SmallBooleanFunction > ( )
681
- . unwrap ( ) ;
656
+ ( BooleanFunction :: Small ( self_small_boolean_function) , BooleanFunction :: Small ( rhs_small_boolean_function) ) => {
657
+ * self_small_boolean_function ^= rhs_small_boolean_function;
658
+ } ,
659
+ ( BooleanFunction :: Small ( self_small_boolean_function) , BooleanFunction :: Big ( rhs_big_boolean_function) ) => {
682
660
let rhs_small_boolean_function = SmallBooleanFunction :: from_truth_table (
683
- rhs. as_any ( )
684
- . downcast_ref :: < BigBooleanFunction > ( )
685
- . unwrap ( )
661
+ rhs_big_boolean_function
686
662
. biguint_truth_table ( )
687
663
. to_u64 ( )
688
664
. unwrap ( ) ,
689
665
self_num_variables,
690
666
)
691
667
. unwrap ( ) ;
692
668
* self_small_boolean_function ^= rhs_small_boolean_function;
693
- }
694
- ( BooleanFunctionType :: Big , BooleanFunctionType :: Small ) => {
695
- let self_big_boolean_function = self
696
- . as_any_mut ( )
697
- . downcast_mut :: < BigBooleanFunction > ( )
698
- . unwrap ( ) ;
699
- let rhs_small_boolean_function = BigBooleanFunction :: from_truth_table (
700
- rhs. as_any ( )
701
- . downcast_ref :: < SmallBooleanFunction > ( )
702
- . unwrap ( )
703
- . biguint_truth_table ( ) ,
669
+ } ,
670
+ ( BooleanFunction :: Big ( self_big_boolean_function) , BooleanFunction :: Small ( rhs_small_boolean_function) ) => {
671
+ let rhs_big_boolean_function = BigBooleanFunction :: from_truth_table (
672
+ rhs_small_boolean_function. biguint_truth_table ( ) ,
704
673
rhs_num_variables,
705
674
) ;
706
- * self_big_boolean_function ^= rhs_small_boolean_function;
707
- }
708
- ( BooleanFunctionType :: Big , BooleanFunctionType :: Big ) => {
709
- let self_big_boolean_function = self
710
- . as_any_mut ( )
711
- . downcast_mut :: < BigBooleanFunction > ( )
712
- . unwrap ( ) ;
713
- let rhs_big_boolean_function =
714
- rhs. as_any ( ) . downcast_ref :: < BigBooleanFunction > ( ) . unwrap ( ) ;
715
- * self_big_boolean_function ^= rhs_big_boolean_function. clone ( ) ;
675
+ * self_big_boolean_function ^= rhs_big_boolean_function;
676
+ } ,
677
+ ( BooleanFunction :: Big ( self_big_boolean_function) , BooleanFunction :: Big ( rhs_big_boolean_function) ) => {
678
+ * self_big_boolean_function ^= rhs_big_boolean_function;
716
679
}
717
680
}
718
681
}
@@ -880,7 +843,7 @@ impl BooleanFunction {
880
843
) ?)
881
844
. into ( ) ) ;
882
845
}
883
- Ok ( ( BigBooleanFunction :: from_truth_table ( truth_table. clone ( ) , num_variables) ) . into ( ) )
846
+ Ok ( BigBooleanFunction :: from_truth_table ( truth_table. clone ( ) , num_variables) . into ( ) )
884
847
}
885
848
}
886
849
0 commit comments