diff options
Diffstat (limited to 'merkle.go')
| -rw-r--r-- | merkle.go | 34 |
1 files changed, 17 insertions, 17 deletions
@@ -55,8 +55,8 @@ func Init(m Merkle) { // nodes are stored in BFS order, root node first type BFSMerkle struct { height int64 - file *os.File - size int64 + *os.File + size int64 } func NewBFSMerkle(height int64, fname string) *BFSMerkle { @@ -65,7 +65,7 @@ func NewBFSMerkle(height int64, fname string) *BFSMerkle { panic(err) } size := int64(1)<<uint64(height) - 2 - return &BFSMerkle{height: height, file: file, size: size} + return &BFSMerkle{height: height, File: file, size: size} } func (m *BFSMerkle) Size() int64 { @@ -73,11 +73,11 @@ func (m *BFSMerkle) Size() int64 { } func (m *BFSMerkle) Put(id int64, data []byte) { - m.file.WriteAt(data, id*hashSize) + m.WriteAt(data, id*hashSize) } func (m *BFSMerkle) Read(buf []byte, id int64) { - m.file.ReadAt(buf, id*hashSize) + m.ReadAt(buf, id*hashSize) } // disk access is sequential and mostly backward @@ -119,8 +119,8 @@ func (m *BFSMerkle) Proof(id int64) [][]byte { // nodes are stored in depth-first post order type PostMerkle struct { height int64 - file *os.File - size int64 + *os.File + size int64 } func NewPostMerkle(height int64, fname string) *PostMerkle { @@ -129,7 +129,7 @@ func NewPostMerkle(height int64, fname string) *PostMerkle { panic(err) } size := int64(1)<<uint64(height) - 2 - return &PostMerkle{height: height, file: file, size: size} + return &PostMerkle{height: height, File: file, size: size} } func (m *PostMerkle) Size() int64 { @@ -138,12 +138,12 @@ func (m *PostMerkle) Size() int64 { func (m *PostMerkle) Put(id int64, data []byte) { pos := Post(m.size, m.height, id) - m.file.WriteAt(data, pos*hashSize) + m.WriteAt(data, pos*hashSize) } func (m *PostMerkle) Read(buf []byte, id int64) { pos := Post(m.size, m.height, id) - m.file.ReadAt(buf, pos*hashSize) + m.ReadAt(buf, pos*hashSize) } // Iterative post-order depth-first construction of the Merkle tree @@ -169,7 +169,7 @@ func (m *PostMerkle) Build() []byte { h.Reset() binary.Write(h, binary.LittleEndian, cur) h.Sum(stack[l-1][:0]) - m.file.WriteAt(stack[l-1], count*hsize) + m.WriteAt(stack[l-1], count*hsize) for cur&1 == 0 && count < size { // we just completed a right node, moving up to the parent @@ -180,7 +180,7 @@ func (m *PostMerkle) Build() []byte { h.Write(stack[l-1]) l-- // pop two items, add one item h.Sum(stack[l-1][:0]) - m.file.WriteAt(stack[l-1], count*hsize) + m.WriteAt(stack[l-1], count*hsize) } // we just completed a left node, moving to its sibling cur++ @@ -203,16 +203,16 @@ func (m *PostMerkle) Proof(id int64) [][]byte { for i := len(proof) - 1; mask > 0; i-- { proof[i] = make([]byte, hashSize) if mask&id > 0 { // leaf is in the right subtree of current node - m.file.ReadAt(proof[i], (cur-size)*hashSize) // reading the left child - cur -= 1 // moving to the right subtree + m.ReadAt(proof[i], (cur-size)*hashSize) // reading the left child + cur -= 1 // moving to the right subtree } else { // left is in the left subtree of current node - m.file.ReadAt(proof[i], (cur-1)*hashSize) // reading the right child - cur -= size // moving the left subtree + m.ReadAt(proof[i], (cur-1)*hashSize) // reading the right child + cur -= size // moving the left subtree } size = mask mask >>= 1 } proof[0] = make([]byte, hashSize) - m.file.ReadAt(proof[0], cur*hashSize) + m.ReadAt(proof[0], cur*hashSize) return proof } |
