aboutsummaryrefslogtreecommitdiffstats
path: root/trie/node.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-02-14 00:23:48 +0800
committerobscuren <geffobscura@gmail.com>2015-02-14 00:23:48 +0800
commit7336dfad02833989037440fb22e01566444d0100 (patch)
tree8f7dc62676e519236b69a977c7af00d81b1e0406 /trie/node.go
parentc9985bf563888d5f346408d2ff174167e8b65880 (diff)
parent00fca409398172811e71158e0ca9f6229e0f815b (diff)
downloaddexon-7336dfad02833989037440fb22e01566444d0100.tar
dexon-7336dfad02833989037440fb22e01566444d0100.tar.gz
dexon-7336dfad02833989037440fb22e01566444d0100.tar.bz2
dexon-7336dfad02833989037440fb22e01566444d0100.tar.lz
dexon-7336dfad02833989037440fb22e01566444d0100.tar.xz
dexon-7336dfad02833989037440fb22e01566444d0100.tar.zst
dexon-7336dfad02833989037440fb22e01566444d0100.zip
Merge branch 'develop' into poc8
Diffstat (limited to 'trie/node.go')
-rw-r--r--trie/node.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/trie/node.go b/trie/node.go
new file mode 100644
index 000000000..0d8a7cff9
--- /dev/null
+++ b/trie/node.go
@@ -0,0 +1,44 @@
+package trie
+
+import "fmt"
+
+var indices = []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "[17]"}
+
+type Node interface {
+ Value() Node
+ Copy(*Trie) Node // All nodes, for now, return them self
+ Dirty() bool
+ fstring(string) string
+ Hash() interface{}
+ RlpData() interface{}
+}
+
+// Value node
+func (self *ValueNode) String() string { return self.fstring("") }
+func (self *FullNode) String() string { return self.fstring("") }
+func (self *ShortNode) String() string { return self.fstring("") }
+func (self *ValueNode) fstring(ind string) string { return fmt.Sprintf("%x ", self.data) }
+
+//func (self *HashNode) fstring(ind string) string { return fmt.Sprintf("< %x > ", self.key) }
+func (self *HashNode) fstring(ind string) string {
+ return fmt.Sprintf("%v", self.trie.trans(self))
+}
+
+// Full node
+func (self *FullNode) fstring(ind string) string {
+ resp := fmt.Sprintf("[\n%s ", ind)
+ for i, node := range self.nodes {
+ if node == nil {
+ resp += fmt.Sprintf("%s: <nil> ", indices[i])
+ } else {
+ resp += fmt.Sprintf("%s: %v", indices[i], node.fstring(ind+" "))
+ }
+ }
+
+ return resp + fmt.Sprintf("\n%s] ", ind)
+}
+
+// Short node
+func (self *ShortNode) fstring(ind string) string {
+ return fmt.Sprintf("[ %x: %v ] ", self.key, self.value.fstring(ind+" "))
+}