From 6df910926ff46d33be87b3ab9715fadf7e44ac2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Coll?= Date: Thu, 4 Jul 2019 14:52:49 -0300 Subject: [PATCH] Rename Trie#treeSize to Trie#childrenSize --- .../main/java/co/rsk/trie/NodeReference.java | 2 +- rskj-core/src/main/java/co/rsk/trie/Trie.java | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/trie/NodeReference.java b/rskj-core/src/main/java/co/rsk/trie/NodeReference.java index 236accd1e43..19ad2e916b4 100644 --- a/rskj-core/src/main/java/co/rsk/trie/NodeReference.java +++ b/rskj-core/src/main/java/co/rsk/trie/NodeReference.java @@ -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() { diff --git a/rskj-core/src/main/java/co/rsk/trie/Trie.java b/rskj-core/src/main/java/co/rsk/trie/Trie.java index f28c42ddbe4..33ee6739142 100644 --- a/rskj-core/src/main/java/co/rsk/trie/Trie.java +++ b/rskj-core/src/main/java/co/rsk/trie/Trie.java @@ -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; @@ -135,7 +135,7 @@ 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; @@ -143,7 +143,7 @@ private Trie(TrieStore store, TrieKeySlice sharedPath, byte[] value, NodeReferen this.sharedPath = sharedPath; this.valueLength = valueLength; this.valueHash = valueHash; - this.treeSize = treeSize; + this.childrenSize = childrenSize; checkValueLength(); } @@ -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; @@ -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; @@ -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()) ); @@ -760,7 +760,7 @@ private void internalToMessage() { this.right.serializeInto(buffer); if (!this.isTerminal()) { - buffer.put(treeSize.encode()); + buffer.put(childrenSize.encode()); } if (hasLongVal) { @@ -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() {