hashlittle2

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2024 License: MIT Imports: 2 Imported by: 0

README

Hashlittle2

This is a pure Go implementation of the hashlittle2 hash function, from the lookup3 family of hash functions by Bob Jenkins. It is a non-cryptographic, 64 bit hash function.

I did not implement this from scratch; I merely adapted existing code for my own purposes. See Credits, below.

Usage

	hl2 := hashlittle2.HashLittle2()
	hl2.Write([]byte("Hello, world!"))
	fmt.Printf("%#x\n", hl2.Sum64()) // prints 0xe44bd6e48deb0e18

Applications

This function is compatible with the hashes used by older (pre-v246, ~2020) versions of systemd journal files. More details can be found in their journal file format document.

Credits

This implementation was based on Apsalar/lookup3, which implements the closely related hashlittle function. The internal workings of these two functions are identical, just with differing input and output widths (32-bit vs 64-bit).

The original C version by Bob Jenkins can be found in lookup3.c.

Massive thanks to all involved.

Documentation

Overview

Package lookup3 implements Bob Jenkins' lookup3 hashlittle non-cryptographic hash function.

See:

https://en.wikipedia.org/wiki/Jenkins_hash_function

http://burtleburtle.net/bob/c/lookup3.c

While this package uses the Go standard library hash package interface hashlittle calls cannot be chained, i.e. all the bytes of the key need to be written to the hash object in a single call to Write(), as the hash is dependent on the key length. Making multiple calls to Write() would not yield the same result, and for this reason throws an error

This code is hereby placed in the public domain

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashLittle2

func HashLittle2() hash.Hash64

Hashlittle2 returns a new hash.Hash64 to calculate the 64-bit lookup3 hashlittle

Its Sum() method will lay the value out in big-endian byte order. and Sum64() will return the 64-bit unsigned value

Types

This section is empty.

Jump to

Keyboard shortcuts

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