Documentation
¶
Overview ¶
Package muhash provides an implementation of a Multiplicative Hash, a cryptographic data structure that allows you to have a rolling hash function that you can add and remove elements from, without the need to re-serialize and re-hash the whole data set.
Index ¶
Constants ¶
const ( // HashSize of array used to store hashes. See Hash. HashSize = 32 // SerializedMuHashSize defines the length in bytes of SerializedMuHash SerializedMuHashSize = elementByteSize )
Variables ¶
var ( // EmptyMuHashHash is the hash of `NewMuHash().Finalize()` EmptyMuHashHash = Hash{0x32, 0x9d, 0x0a, 0x9d, 0x0c, 0xe1, 0x81, 0x7a, 0xa8, 0x82, 0xf8, 0x09, 0x35, 0xf2, 0x6e, 0x72, 0x4b, 0x0d, 0x6f, 0x7c, 0xe7, 0x9e, 0xeb, 0x3f, 0x5d, 0x20, 0x1a, 0x5a, 0xd9, 0x9e, 0x9b, 0x1c} )
Functions ¶
This section is empty.
Types ¶
type Hash ¶
Hash is a type encapsulating the result of hashing some unknown sized data. it typically represents Blake2b.
type MuHash ¶
type MuHash struct {
// contains filtered or unexported fields
}
MuHash is a type used to create a Multiplicative Hash which is a rolling(homomorphic) hash that you can add and remove elements from and receive the same resulting hash as-if you never hashed them. Because of that the order of adding and removing elements doesn't matter. Use NewMuHash to initialize a MuHash, or DeserializeMuHash to parse a MuHash.
func DeserializeMuHash ¶
func DeserializeMuHash(serialized *SerializedMuHash) (*MuHash, error)
DeserializeMuHash will deserialize the MuHash that `Serialize()` serialized.
func NewMuHash ¶
func NewMuHash() *MuHash
NewMuHash return an empty initialized set. when finalized it should be equal to a finalized set with all elements removed.
func (*MuHash) Add ¶
Add hashes the data and adds it to the muhash. Supports arbitrary length data (subject to the underlying hash function(Blake2b) limits)
func (*MuHash) Combine ¶
Combine will add the MuHash together. Equivalent to manually adding all the data elements from one set to the other.
func (*MuHash) Finalize ¶
Finalize will return a hash(blake2b) of the multiset. Because the returned value is a hash of a multiset you cannot "Un-Finalize" it. If this is meant for storage then Serialize should be used instead.
func (*MuHash) Remove ¶
Remove hashes the data and removes it from the multiset. Supports arbitrary length data (subject to the underlying hash function(Blake2b) limits)
func (*MuHash) Reset ¶
func (mu *MuHash) Reset()
Reset clears the muhash from all data. Equivalent to creating a new empty set
func (*MuHash) Serialize ¶
func (mu *MuHash) Serialize() *SerializedMuHash
Serialize returns a serialized version of the MuHash. This is the only right way to serialize a multiset for storage. This MuHash is not finalized, this is meant for storage.
type SerializedMuHash ¶
type SerializedMuHash [SerializedMuHashSize]byte
SerializedMuHash is a is a byte array representing the storage representation of a MuHash
func (SerializedMuHash) String ¶
func (serialized SerializedMuHash) String() string
String returns the SerializedMultiSet as the hexadecimal string