Use generics in TrackTrie
This commit is contained in:
parent
5d4ac105d3
commit
c1cc8e0a86
|
@ -1,7 +1,6 @@
|
|||
package org.ethereum.trie;
|
||||
|
||||
import org.ethereum.db.ByteArrayWrapper;
|
||||
import org.ethereum.db.Database;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -12,10 +11,8 @@ import java.util.Map;
|
|||
* @author: Roman Mandeleil
|
||||
* Created on: 11/06/2014 19:47
|
||||
*/
|
||||
|
||||
public class TrackTrie implements TrieFacade {
|
||||
|
||||
|
||||
private TrieFacade trie;
|
||||
|
||||
private boolean trackingChanges;
|
||||
|
@ -26,10 +23,9 @@ public class TrackTrie implements TrieFacade {
|
|||
this.trie = trie;
|
||||
}
|
||||
|
||||
|
||||
public void startTrack() {
|
||||
changes = new HashMap<>();
|
||||
deletes = new HashMap<>();
|
||||
changes = new HashMap<ByteArrayWrapper, byte[]>();
|
||||
deletes = new HashMap<ByteArrayWrapper, byte[]>();
|
||||
trackingChanges = true;
|
||||
}
|
||||
|
||||
|
@ -42,13 +38,12 @@ public class TrackTrie implements TrieFacade {
|
|||
}
|
||||
|
||||
public void rollbackTrack() {
|
||||
changes = new HashMap<>();
|
||||
deletes = new HashMap<>();
|
||||
changes = new HashMap<ByteArrayWrapper, byte[]>();
|
||||
deletes = new HashMap<ByteArrayWrapper, byte[]>();
|
||||
changes = null;
|
||||
trackingChanges = false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(byte[] key, byte[] value) {
|
||||
if (trackingChanges) {
|
||||
|
@ -62,8 +57,10 @@ public class TrackTrie implements TrieFacade {
|
|||
public byte[] get(byte[] key) {
|
||||
if (trackingChanges) {
|
||||
ByteArrayWrapper wKey = new ByteArrayWrapper(key);
|
||||
if (deletes.get(wKey) != null) return null;
|
||||
if (changes.get(wKey) != null) return changes.get(wKey);
|
||||
if (deletes.get(wKey) != null)
|
||||
return null;
|
||||
if (changes.get(wKey) != null)
|
||||
return changes.get(wKey);
|
||||
return trie.get(key);
|
||||
}
|
||||
return trie.get(key);
|
||||
|
@ -79,5 +76,3 @@ public class TrackTrie implements TrieFacade {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import static org.ethereum.util.CompactEncoder.*;
|
|||
import java.util.Arrays;
|
||||
|
||||
import org.ethereum.crypto.HashUtil;
|
||||
import org.ethereum.db.Database;
|
||||
import org.ethereum.util.Value;
|
||||
import org.iq80.leveldb.DB;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
@ -125,7 +124,6 @@ public class Trie implements TrieFacade{
|
|||
return c.asBytes();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a key/value pair from the trie
|
||||
*
|
||||
|
@ -135,7 +133,6 @@ public class Trie implements TrieFacade{
|
|||
delete(Hex.encode(key));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a key/value pair from the trie
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue