Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make InternalNode.children a const-sized array #456

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ func CreateInternalNode(bitlist []byte, raw []byte, depth byte) (*InternalNode,

// Create a HashNode placeholder for all values
// corresponding to a set bit.
node.children = make([]VerkleNode, NodeWidth)
for i, b := range bitlist {
for j := 0; j < 8; j++ {
if b&mask[j] != 0 {
Expand Down
7 changes: 2 additions & 5 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ type (
// Represents an internal node at any level
InternalNode struct {
// List of child nodes of this internal node.
children []VerkleNode
children [NodeWidth]VerkleNode

// node depth in the tree, in bits
depth byte
Expand Down Expand Up @@ -239,7 +239,6 @@ func (n *InternalNode) ToJSON() ([]byte, error) {

func newInternalNode(depth byte) VerkleNode {
node := new(InternalNode)
node.children = make([]VerkleNode, NodeWidth)
for idx := range node.children {
node.children[idx] = Empty(struct{}{})
}
Expand All @@ -255,7 +254,6 @@ func New() VerkleNode {

func NewStatelessInternal(depth byte, comm *Point) VerkleNode {
node := &InternalNode{
children: make([]VerkleNode, NodeWidth),
depth: depth,
commitment: comm,
}
Expand Down Expand Up @@ -334,7 +332,7 @@ func NewLeafNodeWithNoComms(stem Stem, values [][]byte) *LeafNode {

// Children return the children of the node. The returned slice is
// internal to the tree, so callers *must* consider it readonly.
func (n *InternalNode) Children() []VerkleNode {
func (n *InternalNode) Children() [NodeWidth]VerkleNode {
return n.children
}

Expand Down Expand Up @@ -1073,7 +1071,6 @@ func (n *InternalNode) Serialize() ([]byte, error) {

func (n *InternalNode) Copy() VerkleNode {
ret := &InternalNode{
children: make([]VerkleNode, len(n.children)),
commitment: new(Point),
depth: n.depth,
}
Expand Down