trie: dirty tracking

This commit is contained in:
Jeffrey Wilcke
2015-07-01 15:38:32 +02:00
parent ab16ce70fc
commit 0a1ff68c11
7 changed files with 73 additions and 28 deletions

View File

@ -6,20 +6,22 @@ type ShortNode struct {
trie *Trie
key []byte
value Node
dirty bool
}
func NewShortNode(t *Trie, key []byte, value Node) *ShortNode {
return &ShortNode{t, []byte(CompactEncode(key)), value}
return &ShortNode{t, []byte(CompactEncode(key)), value, false}
}
func (self *ShortNode) Value() Node {
self.value = self.trie.trans(self.value)
return self.value
}
func (self *ShortNode) Dirty() bool { return true }
func (self *ShortNode) Dirty() bool { return self.dirty }
func (self *ShortNode) Copy(t *Trie) Node {
node := &ShortNode{t, nil, self.value.Copy(t)}
node := &ShortNode{t, nil, self.value.Copy(t), self.dirty}
node.key = common.CopyBytes(self.key)
node.dirty = true
return node
}
@ -33,3 +35,7 @@ func (self *ShortNode) Hash() interface{} {
func (self *ShortNode) Key() []byte {
return CompactDecode(string(self.key))
}
func (self *ShortNode) setDirty(dirty bool) {
self.dirty = dirty
}