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