Skip to content

Commit

Permalink
Rename Trie#treeSize to Trie#childrenSize
Browse files Browse the repository at this point in the history
  • Loading branch information
colltoaction authored and Diego López León committed Jul 4, 2019
1 parent 9119aed commit 6df9109
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion rskj-core/src/main/java/co/rsk/trie/NodeReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void serializeInto(ByteBuffer buffer) {
* Do not use.
*/
public long referenceSize() {
return getNode().map(trie -> trie.getTreeSize().value).orElse(0L) + serializedLength();
return getNode().map(trie -> trie.getChildrenSize().value).orElse(0L) + serializedLength();
}

public static NodeReference empty() {
Expand Down
28 changes: 14 additions & 14 deletions rskj-core/src/main/java/co/rsk/trie/Trie.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class Trie {

// the size of this node along with its children (in bytes)
// note that we use a long because an int would allow only up to 4GB of state to be stored.
private VarInt treeSize;
private VarInt childrenSize;

// associated store, to store or retrieve nodes in the trie
private TrieStore store;
Expand All @@ -135,15 +135,15 @@ public Trie(TrieStore store, TrieKeySlice sharedPath, byte[] value, NodeReferenc
}

// full constructor
private Trie(TrieStore store, TrieKeySlice sharedPath, byte[] value, NodeReference left, NodeReference right, Uint24 valueLength, Keccak256 valueHash, VarInt treeSize) {
private Trie(TrieStore store, TrieKeySlice sharedPath, byte[] value, NodeReference left, NodeReference right, Uint24 valueLength, Keccak256 valueHash, VarInt childrenSize) {
this.value = value;
this.left = left;
this.right = right;
this.store = store;
this.sharedPath = sharedPath;
this.valueLength = valueLength;
this.valueHash = valueHash;
this.treeSize = treeSize;
this.childrenSize = childrenSize;
checkValueLength();
}

Expand Down Expand Up @@ -305,9 +305,9 @@ private static Trie fromMessageRskip107(ByteBuffer message, TrieStore store) {
}
}

VarInt treeSize = new VarInt(0);
VarInt childrenSize = new VarInt(0);
if (leftNodePresent || rightNodePresent) {
treeSize = readVarInt(message);
childrenSize = readVarInt(message);
}

byte[] value;
Expand Down Expand Up @@ -340,7 +340,7 @@ private static Trie fromMessageRskip107(ByteBuffer message, TrieStore store) {
throw new IllegalArgumentException("The message had more data than expected");
}

Trie trie = new Trie(store, sharedPath, value, left, right, lvalue, valueHash, treeSize);
Trie trie = new Trie(store, sharedPath, value, left, right, lvalue, valueHash, childrenSize);

if (store != null) {
trie.saved = true;
Expand Down Expand Up @@ -714,14 +714,14 @@ private void internalToMessage() {
boolean hasLongVal = this.hasLongValue();

SharedPathSerializer sharedPathSerializer = new SharedPathSerializer(this.sharedPath);
VarInt treeSize = getTreeSize();
VarInt childrenSize = getChildrenSize();

ByteBuffer buffer = ByteBuffer.allocate(
1 + // flags
sharedPathSerializer.serializedLength() +
this.left.serializedLength() +
this.right.serializedLength() +
(this.isTerminal() ? 0 : treeSize.getSizeInBytes()) +
(this.isTerminal() ? 0 : childrenSize.getSizeInBytes()) +
(hasLongVal ? Keccak256Helper.DEFAULT_SIZE_BYTES + Uint24.BYTES : lvalue.intValue())
);

Expand Down Expand Up @@ -760,7 +760,7 @@ private void internalToMessage() {
this.right.serializeInto(buffer);

if (!this.isTerminal()) {
buffer.put(treeSize.encode());
buffer.put(childrenSize.encode());
}

if (hasLongVal) {
Expand Down Expand Up @@ -1040,16 +1040,16 @@ public byte[] getValue() {
* It shouldn't be called from outside. It's still public for NodeReference call
*
*/
public VarInt getTreeSize() {
if (treeSize == null) {
public VarInt getChildrenSize() {
if (childrenSize == null) {
if (isTerminal()) {
treeSize = new VarInt(0);
childrenSize = new VarInt(0);
} else {
treeSize = new VarInt(this.left.referenceSize() + this.right.referenceSize());
childrenSize = new VarInt(this.left.referenceSize() + this.right.referenceSize());
}
}

return treeSize;
return childrenSize;
}

private byte[] retrieveLongValue() {
Expand Down

0 comments on commit 6df9109

Please sign in to comment.