@@ -789,14 +789,27 @@ function all_partitions(t::RootedTree)
789
789
skeletons = [partition_skeleton (t, edge_set)]
790
790
791
791
for edge_set_value in 1 : (2 ^ length (edge_set) - 1 )
792
- digits ! (edge_set, edge_set_value, base = 2 )
792
+ binary_digits ! (edge_set, edge_set_value)
793
793
push! (forests, partition_forest (t, edge_set))
794
794
push! (skeletons, partition_skeleton (t, edge_set))
795
795
end
796
796
797
797
return (; forests, skeletons)
798
798
end
799
799
800
+ # A helper function to comute the binary representation of an integer `n` as
801
+ # a vector of `Bool`s. This is a more efficient version of
802
+ # binary_digits!(digits, n) = digits!(digits, n, base=2)
803
+ function binary_digits! (digits:: Vector{Bool} , n:: Int )
804
+ bit = 1
805
+ for i in eachindex (digits)
806
+ digits[i] = n & bit > 0
807
+ bit = bit << 1
808
+ end
809
+ digits
810
+ end
811
+
812
+
800
813
801
814
"""
802
815
PartitionIterator(t::RootedTree)
@@ -856,7 +869,7 @@ function Base.iterate(partitions::PartitionIterator, edge_set_value)
856
869
edge_set = partitions. edge_set
857
870
edge_set_tmp = partitions. edge_set_tmp
858
871
859
- digits ! (edge_set, edge_set_value, base = 2 )
872
+ binary_digits ! (edge_set, edge_set_value)
860
873
861
874
# Compute the partition skeleton.
862
875
# The following is a more efficient version of
@@ -919,7 +932,7 @@ function all_splittings(t::RootedTree)
919
932
subtrees = Vector {RootedTree{T, Vector{T}}} () # ordered subtrees
920
933
921
934
for node_set_value in 0 : (2 ^ order (t) - 1 )
922
- digits ! (node_set, node_set_value, base = 2 )
935
+ binary_digits ! (node_set, node_set_value)
923
936
924
937
# Check that if a node is removed then all of its descendants are removed
925
938
subtree_root_index = 1
@@ -1001,7 +1014,7 @@ function Base.iterate(splittings::SplittingIterator, node_set_value)
1001
1014
forest = Vector {RootedTree{T, Vector{T}}} ()
1002
1015
1003
1016
while node_set_value <= splittings. max_node_set_value
1004
- digits ! (node_set, node_set_value, base = 2 )
1017
+ binary_digits ! (node_set, node_set_value)
1005
1018
1006
1019
# Check that if a node is removed then all of its descendants are removed
1007
1020
subtree_root_index = 1
0 commit comments