rhash

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package rhash provides implementations of rolling-hash functions.

A rolling-hash is a hash function that "remembers" only the last n bytes it received, where n is a parameter. Meaning, the hash of a byte sequence always equals the hash of its last n bytes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RabinFingerprintSum32

func RabinFingerprintSum32(data []byte) uint32

RabinFingerprintSum32 returns the Rabin fingerprint of data.

func RabinFingerprintSum64

func RabinFingerprintSum64(data []byte) uint64

RabinFingerprintSum64 returns the Rabin fingerprint of data.

Types

type Buz added in v1.0.0

type Buz struct {
	// contains filtered or unexported fields
}

Buz implements a buzhash rolling-hash. Implements hash.Hash64 and hash.Hash32.

func NewBuz added in v1.0.0

func NewBuz(n int) *Buz

NewBuz returns a new rolling hash with a window size of n.

func NewBuzWithSeed added in v1.0.0

func NewBuzWithSeed(n int, seed *BuzSeed) *Buz

NewBuzWithSeed returns a new rolling hash with a window size of n, with the given seed. Seeds can be generated with BuzRandomSeed.

func (*Buz) BlockSize added in v1.0.0

func (h *Buz) BlockSize() int

BlockSize returns the hash's block size, which is one.

func (*Buz) Reset added in v1.0.0

func (h *Buz) Reset()

Reset resets the hash to its initial state.

func (*Buz) Size added in v1.0.0

func (h *Buz) Size() int

Size returns the number of bytes Sum will return, which is eight.

func (*Buz) Sum added in v1.0.0

func (h *Buz) Sum(b []byte) []byte

Sum appends the current hash to b and returns the resulting slice.

func (*Buz) Sum32 added in v1.0.0

func (h *Buz) Sum32() uint32

Sum32 returns the current hash.

func (*Buz) Sum64 added in v1.0.0

func (h *Buz) Sum64() uint64

Sum64 returns the current hash.

func (*Buz) Write added in v1.0.0

func (h *Buz) Write(data []byte) (int, error)

Write updates the hash with the given bytes. Always returns len(data), nil.

func (*Buz) WriteByte added in v1.0.0

func (h *Buz) WriteByte(b byte) error

WriteByte updates the hash with the given byte. Always returns nil.

type BuzSeed added in v1.0.0

type BuzSeed [256]uint64

func BuzRandomSeed added in v1.0.0

func BuzRandomSeed() *BuzSeed

BuzRandomSeed returns a random seed for NewBuzWithSeed.

type RabinFingerprint32

type RabinFingerprint32 struct {
	// contains filtered or unexported fields
}

RabinFingerprint32 implements a Rabin fingerprint rolling-hash. Implements hash.Hash32.

func NewRabinFingerprint32

func NewRabinFingerprint32(n int) *RabinFingerprint32

NewRabinFingerprint32 returns a new rolling hash with a window size of n.

func (*RabinFingerprint32) BlockSize

func (h *RabinFingerprint32) BlockSize() int

BlockSize returns the hash's block size, which is one.

func (*RabinFingerprint32) Reset

func (h *RabinFingerprint32) Reset()

Reset resets the hash to its initial state.

func (*RabinFingerprint32) Size

func (h *RabinFingerprint32) Size() int

Size returns the number of bytes Sum will return, which is four.

func (*RabinFingerprint32) Sum

func (h *RabinFingerprint32) Sum(b []byte) []byte

Sum appends the current hash to b and returns the resulting slice.

func (*RabinFingerprint32) Sum32

func (h *RabinFingerprint32) Sum32() uint32

Sum32 returns the current hash.

func (*RabinFingerprint32) Write

func (h *RabinFingerprint32) Write(data []byte) (int, error)

Write updates the hash with the given bytes. Always returns len(data), nil.

func (*RabinFingerprint32) WriteByte

func (h *RabinFingerprint32) WriteByte(b byte) error

WriteByte updates the hash with the given byte. Always returns nil.

type RabinFingerprint64

type RabinFingerprint64 struct {
	// contains filtered or unexported fields
}

RabinFingerprint64 implements a Rabin fingerprint rolling-hash. Implements hash.Hash64.

func NewRabinFingerprint64

func NewRabinFingerprint64(n int) *RabinFingerprint64

NewRabinFingerprint64 returns a new rolling hash with a window size of n.

func (*RabinFingerprint64) BlockSize

func (h *RabinFingerprint64) BlockSize() int

BlockSize returns the hash's block size, which is one.

func (*RabinFingerprint64) Reset

func (h *RabinFingerprint64) Reset()

Reset resets the hash to its initial state.

func (*RabinFingerprint64) Size

func (h *RabinFingerprint64) Size() int

Size returns the number of bytes Sum will return, which is eight.

func (*RabinFingerprint64) Sum

func (h *RabinFingerprint64) Sum(b []byte) []byte

Sum appends the current hash to b and returns the resulting slice.

func (*RabinFingerprint64) Sum64

func (h *RabinFingerprint64) Sum64() uint64

Sum64 returns the current hash.

func (*RabinFingerprint64) Write

func (h *RabinFingerprint64) Write(data []byte) (int, error)

Write updates the hash with the given bytes. Always returns len(data), nil.

func (*RabinFingerprint64) WriteByte

func (h *RabinFingerprint64) WriteByte(b byte) error

WriteByte updates the hash with the given byte. Always returns nil.

Jump to

Keyboard shortcuts

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