diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2014-11-27 20:23:31 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2014-11-27 20:23:31 +0800 |
commit | ef7961b7d27be930a4d9dc81527a55497d3dea2e (patch) | |
tree | 5746b715b1b66c5767779e2e4ca66be345333e13 /ptrie/node.go | |
parent | c17a3cb0ceec44c10bc84d05f0d81f08894c792c (diff) | |
parent | 8cf9ed0ea588e97f2baf0f834248727e8fbca18f (diff) | |
download | dexon-ef7961b7d27be930a4d9dc81527a55497d3dea2e.tar dexon-ef7961b7d27be930a4d9dc81527a55497d3dea2e.tar.gz dexon-ef7961b7d27be930a4d9dc81527a55497d3dea2e.tar.bz2 dexon-ef7961b7d27be930a4d9dc81527a55497d3dea2e.tar.lz dexon-ef7961b7d27be930a4d9dc81527a55497d3dea2e.tar.xz dexon-ef7961b7d27be930a4d9dc81527a55497d3dea2e.tar.zst dexon-ef7961b7d27be930a4d9dc81527a55497d3dea2e.zip |
Merge pull request #194 from ethereum/poc8
Update tests branch to PoC8
Diffstat (limited to 'ptrie/node.go')
-rw-r--r-- | ptrie/node.go | 40 |
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+" ")) +} |