use of tech.pegasys.teku.infrastructure.ssz.schema.SszSchemaHints.SszSuperNodeHint in project teku by ConsenSys.
the class AbstractSszVectorSchema method createDefaultTree.
@Override
protected TreeNode createDefaultTree() {
if (isListBacking) {
Optional<SszSuperNodeHint> sszSuperNodeHint = getHints().getHint(SszSuperNodeHint.class);
if (sszSuperNodeHint.isPresent()) {
int superNodeDepth = sszSuperNodeHint.get().getDepth();
SszSuperNode defaultSuperSszNode = new SszSuperNode(superNodeDepth, elementSszSupernodeTemplate.get(), Bytes.EMPTY);
int binaryDepth = treeDepth() - superNodeDepth;
return TreeUtil.createTree(emptyList(), defaultSuperSszNode, binaryDepth);
} else {
return TreeUtil.createDefaultTree(maxChunks(), LeafNode.EMPTY_LEAF);
}
} else if (getElementsPerChunk() == 1) {
return TreeUtil.createDefaultTree(maxChunks(), getElementSchema().getDefaultTree());
} else {
// packed vector
int fullZeroNodesCount = getLength() / getElementsPerChunk();
int lastNodeElementCount = getLength() % getElementsPerChunk();
int lastNodeSizeBytes = bitsCeilToBytes(lastNodeElementCount * getSszElementBitSize());
Stream<TreeNode> fullZeroNodes = Stream.<TreeNode>generate(() -> LeafNode.ZERO_LEAVES[32]).limit(fullZeroNodesCount);
Stream<TreeNode> lastZeroNode = lastNodeSizeBytes > 0 ? Stream.of(LeafNode.ZERO_LEAVES[lastNodeSizeBytes]) : Stream.empty();
return TreeUtil.createTree(Stream.concat(fullZeroNodes, lastZeroNode).collect(Collectors.toList()));
}
}
Aggregations