aboutsummaryrefslogtreecommitdiffstats
path: root/ptrie/node.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-11-18 19:02:13 +0800
committerobscuren <geffobscura@gmail.com>2014-11-18 19:02:13 +0800
commitf7417d3552de86f5acf969b6eb882502fd104a11 (patch)
tree939043bfbb72510326446b022e4615d58616e2e3 /ptrie/node.go
parenta19d2c22782fa85cd38de246d9801fa1ebd0660a (diff)
downloadgo-tangerine-f7417d3552de86f5acf969b6eb882502fd104a11.tar
go-tangerine-f7417d3552de86f5acf969b6eb882502fd104a11.tar.gz
go-tangerine-f7417d3552de86f5acf969b6eb882502fd104a11.tar.bz2
go-tangerine-f7417d3552de86f5acf969b6eb882502fd104a11.tar.lz
go-tangerine-f7417d3552de86f5acf969b6eb882502fd104a11.tar.xz
go-tangerine-f7417d3552de86f5acf969b6eb882502fd104a11.tar.zst
go-tangerine-f7417d3552de86f5acf969b6eb882502fd104a11.zip
New modified patricia trie
Diffstat (limited to 'ptrie/node.go')
-rw-r--r--ptrie/node.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/ptrie/node.go b/ptrie/node.go
new file mode 100644
index 000000000..2c85dbce7
--- /dev/null
+++ b/ptrie/node.go
@@ -0,0 +1,40 @@
+package ptrie
+
+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() 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("%s ", self.data) }
+func (self *HashNode) fstring(ind string) string { return fmt.Sprintf("%x ", self.key) }
+
+// 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("[ %s: %v ] ", self.key, self.value.fstring(ind+" "))
+}