aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-06-30 19:34:47 +0800
committerobscuren <geffobscura@gmail.com>2014-06-30 19:34:47 +0800
commit9ed0d389b2402baf2dbc90fe12e9b4695ee22858 (patch)
tree281ef96ea0e1be6ac8ca838e4d549e3f51d2b5d9 /ethutil
parent00bb68d7d21ce3b4c79e0c269c62607b6d4f1acc (diff)
downloadgo-tangerine-9ed0d389b2402baf2dbc90fe12e9b4695ee22858.tar.gz
go-tangerine-9ed0d389b2402baf2dbc90fe12e9b4695ee22858.tar.zst
go-tangerine-9ed0d389b2402baf2dbc90fe12e9b4695ee22858.zip
Generic trie
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/trie.go22
1 files changed, 12 insertions, 10 deletions
diff --git a/ethutil/trie.go b/ethutil/trie.go
index ce9c2da27..26a27a901 100644
--- a/ethutil/trie.go
+++ b/ethutil/trie.go
@@ -191,7 +191,17 @@ func (t *Trie) Get(key string) string {
}
func (t *Trie) Delete(key string) {
- t.Update(key, "")
+ t.mut.Lock()
+ defer t.mut.Unlock()
+
+ k := CompactHexDecode(key)
+
+ root := t.DeleteState(t.Root, k)
+ if _, ok := root.([]byte); !ok {
+ t.Root = t.cache.PutValue(root, true)
+ } else {
+ t.Root = root
+ }
}
func (t *Trie) GetState(node interface{}, key []int) interface{} {
@@ -243,15 +253,7 @@ func (t *Trie) GetNode(node interface{}) *Value {
}
func (t *Trie) UpdateState(node interface{}, key []int, value string) interface{} {
-
- if value != "" {
- return t.InsertState(node, key, value)
- } else {
- // delete it
- return t.DeleteState(node, key)
- }
-
- return t.Root
+ return t.InsertState(node, key, value)
}
func (t *Trie) Put(node interface{}) interface{} {