hasher

package
v3.0.0-...-3d818cf Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package hasher generates a unique binary identifier for a longer piece of binary data using an efficient, non-cryptographic hash function.

A new Hasher instance can be created with the NewHasher() function. Advanced users can use the NewHasherWithOptions() function to tweak the underlying parameters, but the defaults were chosen based on testing and should provide a good balance of performance and storage efficiency.

Shortened identifiers are generated using the idempotent Hasher.CreateID method.

Using the default algorithm which uses the first 4 bytes of a 64-bit BLAKE2b hash and then increases the length in the case of collisions. Identifiers will be 4 bytes long in the vast majority of cases and will sometimes be 5 and rarely 6 bytes long. In some extremely rare cases (which have not appeared in tests), identifiers may be longer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashOptions

type HashOptions struct {
	// NewHash is a function which returns a new hash.Hash instance.
	NewHash func() hash.Hash

	// MinLength is the minimum number of hash bytes that will be used to create a lookup identifier.
	MinLength int
}

HashOptions is used to specify custom hash options and should only be used by advanced users.

type Hasher

type Hasher interface {
	// CreateID is an idempotent method for creating a unique shortened identifier
	// for the provided binary value.
	CreateID(value []byte, collisions int) []byte
}

Hasher generates a unique binary identifier for a longer piece of binary data using an efficient, non-cryptographic hash function.

func NewHasher

func NewHasher() (Hasher, error)

NewHasher creates a new hasher instance. Default parameters are currently set to use the first 4-bytes of the 64-bit BLAKE2b, non-cryptographic hash. In the case of a collision, more bytes of the hash will be used for disambiguation but this happens in a minority of cases except for massively large data sets.

func NewHasherWithOptions

func NewHasherWithOptions(options HashOptions) (Hasher, error)

NewHasherWithOptions creates a Hash with custom options. Most users should just use NewHasher with the default values.

Jump to

Keyboard shortcuts

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