key

package module
v0.0.0-...-096b6cb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2017 License: Apache-2.0 Imports: 6 Imported by: 2

README

go-hamt-key

A key data structure to be used in go-hamt and go-hamt-functional

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

View Source
const BitsPerLevel30 uint = 5

BitsPerLevel30 is the number of bits per depth level of the HashVal30.

View Source
const BitsPerLevel60 uint = 6

BitsPerLevel60 is the number of bits per depth level of the HashVal60.

View Source
const MaxDepth30 uint = 5

MaxDepth30 represents the maximum depth of the HashVal30.

View Source
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) Hash30

func (kb Base) Hash30() HashVal30

Hash30 returns the HashVal30 that contains the 30bit hash value.

func (Base) Hash60

func (kb Base) Hash60() HashVal60

Hash60 returns the HashVal60 that contains the 60bit hash value.

func (*Base) Initialize

func (kb *Base) Initialize(bs []byte)

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.

func (Base) String

func (kb Base) String() string

String() provides a human readable form of the Base's hash30 and hash60 values. Both in raw integer and slash '/' separated integers of the 5 and 6 bit path values; for hash30 and hash60 respectively.

type HashVal30

type HashVal30 uint32

HashVal30 stores 30 bits of a hash value.

func HashPathMask30

func HashPathMask30(depth uint) HashVal30

HashPathMask30() returns the mask for a 30 bit HashPath value.

func ParseHashPath30

func ParseHashPath30(s string) HashVal30

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

func (h30 HashVal30) BitString() string

Return the HashVal30 as a 30 bit bit string separated into groups of 5 bits (aka BitsPerLevel30).

func (HashVal30) BuildHashPath

func (hashPath HashVal30) BuildHashPath(idx, depth uint) HashVal30

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

func (h30 HashVal30) HashPath(depth uint) HashVal30

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

func (h30 HashVal30) HashPathString(limit uint) string

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".

func (HashVal30) Index

func (h30 HashVal30) Index(depth uint) uint

Index() will return a 5bit (aka BitsPerLevel30) value 'depth' number of 5bits from the beginning of the HashVal30 (aka uint32) h30 value.

func (HashVal30) String

func (h30 HashVal30) String() string

String() returns a string representation of the h30 HashVal30 value. This is MaxDepth30+1(6) two digit numbers (zero padded) between "00" and "31" seperated by '/' characters and given a leading '/'. Example: "/08/14/28/20/00/31"

type HashVal60

type HashVal60 uint64

HashVal60 stores 60 bits of a hash value.

func HashPathMask60

func HashPathMask60(depth uint) HashVal60

HashPathMask60() returns the mask for a 60 bit HashPath value.

func ParseHashPath60

func ParseHashPath60(s string) HashVal60

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

func (h60 HashVal60) BitString() string

Return the HashVal60 as a 60 bit bit string separated into groups of 6 bits (aka BitsPerLevel60).

func (HashVal60) BuildHashPath

func (hashPath HashVal60) BuildHashPath(idx, depth uint) HashVal60

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

func (h60 HashVal60) HashPath(depth uint) HashVal60

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

func (h60 HashVal60) HashPathString(limit uint) string

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".

func (HashVal60) Index

func (h60 HashVal60) Index(depth uint) uint

Index() will return a 6bit (aka BitsPerLevel60) value 'depth' number of 6bits from the beginning of the HashVal60 (aka uint64) h60 value.

func (HashVal60) String

func (h60 HashVal60) String() string

String() returns a string representation of the h60 HashVal60 value. This is MaxDepth60+1(10) two digit numbers (zero padded) between "00" and "63" seperated by '/' characters and given a leading '/'. Example: "/08/14/28/20/00/63"

type Key

type Key interface {
	Hash30() HashVal30
	Hash60() HashVal60
	Equals(Key) bool
	String() string
}

Key interface descibes the methods any struct needs to implement to be used in either the github.com/lleo/go-hamt or github.com/lleo/go-hamt-functional packages.

type KeyVal

type KeyVal struct {
	Key Key
	Val interface{}
}

KeyVal is a simple struct used to transfer lists ([]KeyVal) from one function to another.

func (KeyVal) String

func (kv KeyVal) String() string

Directories

Path Synopsis
Package stringkey is an implementation of the "github.com/lleo/go-hamt/key" interface.
Package stringkey is an implementation of the "github.com/lleo/go-hamt/key" interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL