You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are many tech debts in the Trie class, I've spotted some of them
publicclassTrie {
...
privateTrie(TrieStorestore, TrieKeySlicesharedPath, byte[] value, NodeReferenceleft, NodeReferenceright, Uint24valueLength, Keccak256valueHash, VarIntchildrenSize) {
this(store, sharedPath, value, left, right, valueLength, valueHash, childrenSize, exitStatus -> System.exit(exitStatus));
}
// full constructorprivateTrie(TrieStorestore, TrieKeySlicesharedPath, byte[] value, NodeReferenceleft, NodeReferenceright, Uint24valueLength, Keccak256valueHash, VarIntchildrenSize, @NonnullNodeStoppernodeStopper) {
this.value = value;
this.left = left;
this.right = right;
this.store = store;
this.sharedPath = sharedPath;
this.valueLength = valueLength;
this.valueHash = valueHash;
this.childrenSize = childrenSize;
this.nodeStopper = Objects.requireNonNull(nodeStopper);
checkValueLength();
}
...
/** * get by string, utility method used from test methods * * @param key a string, that is converted to a byte array * @return a byte array with the associated value */publicbyte[] get(Stringkey) {
// todo(fedejinich) this method is useless, the String to byte[] convention should be done at the testsreturnthis.get(key.getBytes(StandardCharsets.UTF_8));
}
...
/** * put string key to value, the key is converted to byte array * utility method to be used from testing * * @param key a string * @param value an associated value, a byte array * * @return a new NewTrie, the top node of a new trie having the key * value association */publicTrieput(Stringkey, byte[] value) {
returnput(key.getBytes(StandardCharsets.UTF_8), value);
}
...
@NullablepublicList<Trie> getNodes(Stringkey) {
returnthis.getNodes(key.getBytes(StandardCharsets.UTF_8));
}
...
}
Test code in production
There are two overloads for get() and put() methods that are only used in test cases, those methods should be removed in order to clean test code from production.
Unecesary overloads
getNodes()
There are many overloads for the getNodes() method, to me, this doesn't add any real value, in most cases, those conversions are just a simple Trie.fromKey(key). To simplify the Trie class, I propose only to leave the default findNodes() implementation, but if you push me, I think we should extract this method to the MutableTrie implementation (where we should do most of the trie manipulations).
Trie Constructor Overload
This overload it's unnecessary since the node stopper it's always initialized with System.exit(exitStatus). I propose to delegate that part into the full constructor
The text was updated successfully, but these errors were encountered:
There are many tech debts in the Trie class, I've spotted some of them
Test code in production
There are two overloads for
get()
andput()
methods that are only used in test cases, those methods should be removed in order to clean test code from production.Unecesary overloads
getNodes()
There are many overloads for the
getNodes()
method, to me, this doesn't add any real value, in most cases, those conversions are just a simpleTrie.fromKey(key)
. To simplify theTrie
class, I propose only to leave the defaultfindNodes()
implementation, but if you push me, I think we should extract this method to theMutableTrie
implementation (where we should do most of the trie manipulations).Trie Constructor Overload
This overload it's unnecessary since the node stopper it's always initialized with
System.exit(exitStatus)
. I propose to delegate that part into the full constructorThe text was updated successfully, but these errors were encountered: