# find leaf count and leaf depths leaves = [*self.leaves()] max_depth = len(leaves).bit_length() current_entry = None for leaf_depth, leaf_offset, leaf_data in leaves: # leaves that have depth that is too deep can be added to the index so as to find them quickly # or a parent of them could be added # when we find a leaf that is too deep, we can start an index entry # we can then continue moving on, and move the index entry to its parent to include adjacent leaves. # if we reach prev_flush as the only shared parent, then we write out the entry using the last too-deep item as the endpoint # instead if we find another too deep item, we make it the last, and continue on