rhash

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: MIT Imports: 2 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 Buz32

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

Buz32 implements a buzhash rolling-hash. Implements hash.Hash32.

func NewBuz32

func NewBuz32(n int) *Buz32

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

func (*Buz32) BlockSize

func (h *Buz32) BlockSize() int

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

func (*Buz32) Reset

func (h *Buz32) Reset()

Reset resets the hash to its initial state.

func (*Buz32) Size

func (h *Buz32) Size() int

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

func (*Buz32) Sum

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

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

func (*Buz32) Sum32

func (h *Buz32) Sum32() uint32

Sum32 returns the current hash.

func (*Buz32) Write

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

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

func (*Buz32) WriteByte

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

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

type Buz64

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

Buz64 implements a buzhash rolling-hash. Implements hash.Hash64.

func NewBuz64

func NewBuz64(n int) *Buz64

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

func (*Buz64) BlockSize

func (h *Buz64) BlockSize() int

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

func (*Buz64) Reset

func (h *Buz64) Reset()

Reset resets the hash to its initial state.

func (*Buz64) Size

func (h *Buz64) Size() int

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

func (*Buz64) Sum

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

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

func (*Buz64) Sum64

func (h *Buz64) Sum64() uint64

Sum64 returns the current hash.

func (*Buz64) Write

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

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

func (*Buz64) WriteByte

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

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

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