diff options
author | obscuren <obscuren@obscura.com> | 2013-12-30 08:09:57 +0800 |
---|---|---|
committer | obscuren <obscuren@obscura.com> | 2013-12-30 08:09:57 +0800 |
commit | f17930eb4661721cd0e1b92765448c589441907b (patch) | |
tree | 35def5092a0d704feb0c20f1d29b94452ebfd09c /trie.go | |
parent | a926686445929d091c2d9e019b017600168e9e47 (diff) | |
download | go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.gz go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.bz2 go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.lz go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.xz go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.tar.zst go-tangerine-f17930eb4661721cd0e1b92765448c589441907b.zip |
Split up db and trie and added interface
Diffstat (limited to 'trie.go')
-rw-r--r-- | trie.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/trie.go b/trie.go new file mode 100644 index 000000000..d9d5dba5a --- /dev/null +++ b/trie.go @@ -0,0 +1,50 @@ +package main + +// Database interface +type Database interface { + Put(key []byte, value []byte) + Get(key []byte) ([]byte, error) +} + +type Trie struct { + root string + db Database +} + +func NewTrie(db Database) *Trie { + return &Trie{db: db, root: ""} +} + +func (t *Trie) Update(key string, value string) { + k := CompactHexDecode(key) + + t.root = t.UpdateState(t.root, k, value) +} + +func (t *Trie) Get(key []byte) ([]byte, error) { + return nil, nil +} + +// Inserts a new sate or delete a state based on the value +func (t *Trie) UpdateState(node string, key []int, value string) string { + if value != "" { + return t.InsertState(node, ""/*key*/, value) + } else { + // delete it + } + + return "" +} + +func (t *Trie) InsertState(node, key, value string) string { + return "" +} + +func (t *Trie) Put(node []byte) []byte { + enc := Encode(node) + sha := Sha256Bin(enc) + + t.db.Put([]byte(sha), enc) + + return sha +} |