-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #447 from cosmos/justin/fast-node-get
Refactor Get() to work with new faster cache
- Loading branch information
Showing
5 changed files
with
138 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,6 @@ cpu*.out | |
mem*.out | ||
cpu*.pdf | ||
mem*.pdf | ||
|
||
# IDE files | ||
.idea/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package iavl | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// NOTE: This file favors int64 as opposed to int for size/counts. | ||
// The Tree on the other hand favors int. This is intentional. | ||
|
||
type FastNode struct { | ||
key []byte | ||
versionLastUpdatedAt int64 | ||
value []byte | ||
leafHash []byte // TODO: Look into if this would help with proof stuff. | ||
} | ||
|
||
// NewFastNode returns a new fast node from a value and version. | ||
func NewFastNode(key []byte, value []byte, version int64) *FastNode { | ||
return &FastNode{ | ||
key: key, | ||
versionLastUpdatedAt: version, | ||
value: value, | ||
} | ||
} | ||
|
||
// DeserializeFastNode constructs an *FastNode from an encoded byte slice. | ||
func DeserializeFastNode(buf []byte) (*FastNode, error) { | ||
val, n, cause := decodeBytes(buf) | ||
if cause != nil { | ||
return nil, errors.Wrap(cause, "decoding fastnode.value") | ||
} | ||
buf = buf[n:] | ||
|
||
ver, _, cause := decodeVarint(buf) | ||
if cause != nil { | ||
return nil, errors.Wrap(cause, "decoding fastnode.version") | ||
} | ||
|
||
fastNode := &FastNode{ | ||
versionLastUpdatedAt: ver, | ||
value: val, | ||
} | ||
|
||
return fastNode, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters