Documentation
¶
Index ¶
- Variables
- func BitIndex(v uint64) (out uint8)
- func BitLength(v uint64) (out uint8)
- func CoverDepth(v uint64) (out uint8)
- func InitZeroHashes(h HashFn, zeroHashesLevels uint)
- type Gindex
- type Gindex64
- func (v Gindex64) Anchor() Gindex
- func (v Gindex64) BitIter() (iter GindexBitIter, depth uint32)
- func (v Gindex64) Depth() uint32
- func (v Gindex64) IsClose() bool
- func (v Gindex64) IsLeft() bool
- func (v Gindex64) IsRoot() bool
- func (v Gindex64) Left() Gindex
- func (v Gindex64) Parent() Gindex
- func (v Gindex64) Right() Gindex
- func (v Gindex64) Subtree() Gindex
- type Gindex64BitIter
- type GindexBitIter
- type HashFn
- type Link
- type NewHashFn
- type Node
- type PairNode
- func (c *PairNode) Getter(target Gindex) (Node, error)
- func (c *PairNode) IsLeaf() bool
- func (c *PairNode) Left() (Node, error)
- func (c *PairNode) MerkleRoot(h HashFn) Root
- func (c *PairNode) RebindLeft(v Node) (Node, error)
- func (c *PairNode) RebindRight(v Node) (Node, error)
- func (c *PairNode) Right() (Node, error)
- func (c *PairNode) Setter(target Gindex, expand bool) (Link, error)
- func (c *PairNode) SummarizeInto(target Gindex, h HashFn) (SummaryLink, error)
- type Root
- func (r *Root) Getter(target Gindex) (Node, error)
- func (r *Root) IsLeaf() bool
- func (r *Root) Left() (Node, error)
- func (r Root) MarshalText() ([]byte, error)
- func (r *Root) MerkleRoot(h HashFn) Root
- func (r *Root) RebindLeft(v Node) (Node, error)
- func (r *Root) RebindRight(v Node) (Node, error)
- func (r *Root) Right() (Node, error)
- func (r *Root) Setter(target Gindex, expand bool) (Link, error)
- func (r Root) String() string
- func (r *Root) SummarizeInto(target Gindex, h HashFn) (SummaryLink, error)
- func (r *Root) UnmarshalText(text []byte) error
- type SummaryLink
Constants ¶
This section is empty.
Variables ¶
var ZeroHashes []Root
Functions ¶
func BitIndex ¶
bitmagic: binary search through a uint64 to find the index (least bit being 0) of the first set bit. Zero is a special case, it has a 0 bit index. Example:
(in out): (0 0), (1 0), (2 1), (3 1), (4 2), (5 2), (6 2), (7 2), (8 3), (9 3)
func BitLength ¶
bitmagic: binary search through a uint64 to find the bit-length Zero is a special case, it has a 0 bit length. Example:
(in out): (0 0), (1 1), (2 2), (3 2), (4 3), (5 3), (6 3), (7 3), (8 4), (9 4)
func CoverDepth ¶
bitmagic: binary search through a uint64, to find the BitIndex of next power of 2 (if not already a power of 2) Zero is a special case, it has a 0 depth. Example:
(in out): (0 0), (1 0), (2 1), (3 2), (4 2), (5 3), (6 3), (7 3), (8 3), (9 4)
func InitZeroHashes ¶
initialize the zero-hashes pre-computed data with the given hash-function.
Types ¶
type Gindex ¶
type Gindex interface {
// Subtree returns the same gindex, but with the anchor moved one bit to the right, to represent the subtree position.
Subtree() Gindex
// Anchor of the gindex: same depth, but with position zeroed out.
Anchor() Gindex
// Left child gindex
Left() Gindex
// Right child gindex
Right() Gindex
// Parent gindex
Parent() Gindex
// If the gindex points into the left subtree (2nd bit is 0)
IsLeft() bool
// If the gindex is the root (= 1)
IsRoot() bool
// If gindex is 2 or 3
IsClose() bool
// Get the depth of the gindex
Depth() uint32
// Iterate over the bits of the gindex
// The depth is excl. the "root" bit
BitIter() (iter GindexBitIter, depth uint32)
}
type Gindex64 ¶
type Gindex64 uint64
const LeftGindex Gindex64 = 2
const RightGindex Gindex64 = 3
const RootGindex Gindex64 = 1
func (Gindex64) BitIter ¶
func (v Gindex64) BitIter() (iter GindexBitIter, depth uint32)
type Gindex64BitIter ¶
func (*Gindex64BitIter) Next ¶
func (iter *Gindex64BitIter) Next() (right bool, ok bool)
type GindexBitIter ¶
type GindexBitIter interface {
// Next: move forward through gindex.
// It returns bools for each bit after the "root" bit.
// If "ok" is false, the bit cannot be read, none are remaining.
// Subsequent calls are invalid.
// For these extra calls, "ok" will be false, and "right" is undefined.
Next() (right bool, ok bool)
}
type NewHashFn ¶
type NewHashFn func() HashFn
var GetHashFn NewHashFn = sha256CombiRepeat
Get a hash-function that re-uses the hashing working-variables. Defaults to SHA-256.
type Node ¶
type Node interface {
Left() (Node, error)
Right() (Node, error)
IsLeaf() bool
RebindLeft(v Node) (Node, error)
RebindRight(v Node) (Node, error)
Getter(target Gindex) (Node, error)
Setter(target Gindex, expand bool) (Link, error)
SummarizeInto(target Gindex, h HashFn) (SummaryLink, error)
MerkleRoot(h HashFn) Root
}
Node of a binary merkle tree
func SubtreeFillToDepth ¶
func SubtreeFillToLength ¶
type PairNode ¶
An immutable (L, R) pair with a link to the holding node. If L or R changes, the link is used to bind a new (L, *R) or (*L, R) pair in the holding value.
func NewPairNode ¶
func (*PairNode) MerkleRoot ¶
func (*PairNode) SummarizeInto ¶
func (c *PairNode) SummarizeInto(target Gindex, h HashFn) (SummaryLink, error)
type Root ¶
type Root [32]byte
func (Root) MarshalText ¶ added in v0.0.2
func (*Root) MerkleRoot ¶
func (*Root) SummarizeInto ¶
func (r *Root) SummarizeInto(target Gindex, h HashFn) (SummaryLink, error)