Documentation ¶
Overview ¶
Package key contains a single Key interface. The key package was created to prevent cicular dependencies between "github.com/lleo/go-hamt" and either "github.com/lleo/go-hamt/hamt32", "github.com/lleo/go-hamt/hamt64", "github.com/lleo/go-hamt-functional/hamt32", or "github.com/lleo/go-hamt-functional/hamt64"
Additionally, the "github.com/lleo/go-hamt-key" provides a Base structure. The Base structure if added to a derivative key type will provide the k.Hash30() and k.Hash60() methods. Base needs to be populated by the derivative key constructor calling the k.Initialize([]byte) method.
Any key created using the Key interface must be read-only after construction.
The Hash30() returns a special type HashVal30. Which really just an alias for uint32 that stores a 30 bit hash value, but it provides methods for viewing the 30 bit hash30 value. For instance the hv.Index() method will pull out the 5 bit integer values, as a uint, for each depth of the Hamt datastructure that is really the index into a table. Also, there are methods to produce string representations of the underlying 30 bit hash value.
The Hash60() returns a special type HashVal60. Which really just an alias for uint64 that stores a 60 bit hash value, but it provides methods for viewing the 60 bit hash60 value. For instance the hv.Index() method will pull out the 5 bit integer values, as a uint, for each depth of the Hamt datastructure that is really the index into a table. Also, there are methods to produce string representations of the underlying 60 bit hash value.
The key package is also used by the functional HAMT variation in "github.com/lleo/go-hamt-functional".
Index ¶
Constants ¶
const BitsPerLevel30 uint = 5
BitsPerLevel30 is the number of bits per depth level of the HashVal30.
const BitsPerLevel60 uint = 6
BitsPerLevel60 is the number of bits per depth level of the HashVal60.
const MaxDepth30 uint = 5
MaxDepth30 represents the maximum depth of the HashVal30.
const MaxDepth60 uint = 9
MaxDepth60 represents the maximum depth of the HashVal60.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base struct is intended to be the base struct of all structs that satisfy Key interface. It caches the calculated hash30 and hash60 generated when the method Initialize([]byte) is called.
func (*Base) Initialize ¶
Initialize the calculates the Base part of any struct that has the Base struct embedded. It will be called by the New() function of any descendant class.
k.Initialize(bs)
where k is interpreted as a *Base and bs is a unique []byte to calculate the 30bit and 60bit hash values from.
type HashVal30 ¶
type HashVal30 uint32
HashVal30 stores 30 bits of a hash value.
func HashPathMask30 ¶
HashPathMask30() returns the mask for a 30 bit HashPath value.
func ParseHashPath30 ¶
ParseHashPath30() parses a string with a leading '/' and MaxDepth30+1 number of two digit numbers zero padded between "00" and "31" joined by '/' characters. Example: var h30 key.HashVal30 = key.ParseHashVal30("/00/01/02/03/04/05")
func (HashVal30) BitString ¶
Return the HashVal30 as a 30 bit bit string separated into groups of 5 bits (aka BitsPerLevel30).
func (HashVal30) BuildHashPath ¶
BuildHashPath() method adds a idx at depth level of the hashPath. Given a hashPath = "/11/07/13" and you call hashPath.BuildHashPath(23, 3) the method will return hashPath "/11/07/13/23". hashPath is shown here in the string representation, but the real value is HashVal30 (aka uint32).
func (HashVal30) HashPath ¶
HashPath() calculates the path required to read the given depth. In other words it returns a uint32 that preserves the first depth-1 5bit index values. For depth=0 it always returns no path (aka a 0 value). For depth=MaxDepth60 it returns all but the last set of 5bit index values.
func (HashVal30) HashPathString ¶
HashPathString() returns a string representation of the index path of a HashVal30 30 bit value; that is depth number of zero padded numbers between "00" and "31" separated by '/' characters and a leading '/'. If the limit parameter is 0 then the method will simply return a solitary "/". Warning: It will panic() if limit > MaxDepth30+1. Example: "/00/24/46/17" for limit=4 of a hash30 value represented
by "/00/24/46/17/34/08".
type HashVal60 ¶
type HashVal60 uint64
HashVal60 stores 60 bits of a hash value.
func HashPathMask60 ¶
HashPathMask60() returns the mask for a 60 bit HashPath value.
func ParseHashPath60 ¶
ParseHashPath60() parses a string with a leading '/' and MaxDepth60+1 number of two digit numbers zero padded between "00" and "63" joined by '/' characters. Example: var h60 key.HashVal60 = key.ParseHashVal60("/00/01/02/03/04/05")
func (HashVal60) BitString ¶
Return the HashVal60 as a 60 bit bit string separated into groups of 6 bits (aka BitsPerLevel60).
func (HashVal60) BuildHashPath ¶
BuildHashPath() method adds a idx at depth level of the hashPath. Given a hashPath = "/11/07/13" and you call hashPath.BuildHashPath(23, 3) the method will return hashPath "/11/07/13/23". hashPath is shown here in the string representation, but the real value is HashVal60 (aka uint64).
func (HashVal60) HashPath ¶
HashPath() calculates the path required to read the given depth. In other words it returns a uint64 that preserves the first depth-1 6bit index values. For depth=0 it always returns no path (aka a 0 value). For depth=MaxDepth60 it returns all but the last set of 6bit index values.
func (HashVal60) HashPathString ¶
HashPathString() returns a string representation of the index path of a HashVal60 60 bit value; that is depth number of zero padded numbers between "00" and "63" separated by '/' characters and a leading '/'. If the limit parameter is 0 then the method will simply return a solitary "/". Warning: It will panic() if limit > MaxDepth60+1. Example: "/00/24/46/17" for limit=4 of a hash60 value represented
by "/00/24/46/17/34/08".