xxhash

package module
v0.0.0-...-5ea66fb Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2016 License: MIT Imports: 3 Imported by: 1

README

Build Status Coverage Status GoDoc

xxhash

A pure Go port of xxHash algorithm

For more information about xxHash, see:

Installation

go get github.com/shivakar/xxhash

Usage

package main

import (
    "fmt"

    "github.com/shivakar/xxhash"
)

func main() {
    // Create a new instance of the hash engine with default seed
    h := xxhash.NewXXHash64()

    // Create a new instance of the hash engine with custom seed
    _ = xxhash.NewSeedXXHash64(uint64(10))

    // Write some data to the hash
    h.Write([]byte("Hello, World!!"))

    // Write some more data to the hash
    h.Write([]byte("How are you doing?"))

    // Get the current hash as a byte array
    b := h.Sum(nil)
    fmt.Println(b)

    // Get the current hash as an integer (uint64) (little-endian)
    fmt.Println(h.Uint64())

    // Get the current hash as a hexadecimal string (big-endian)
    fmt.Println(h.String())

    // Reset the hash
    h.Reset()

    // Output:
    // [70 182 137 152 187 180 209 136]
    // 5095411317493518728
    // 46b68998bbb4d188

}

License

xxhash is licensed under a MIT license.

Documentation

Overview

Package xxhash implements the xxHash hash algorithm.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type XXHash64

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

XXHash64 implements the 64-bit variant of the xxHash algorithm.

Example (Usage)

Examples

package main

import (
	"fmt"

	"github.com/shivakar/xxhash"
)

func main() {
	// Create a new instance of the hash engine with default seed
	h := xxhash.NewXXHash64()

	// Create a new instance of the hash engine with custom seed
	_ = xxhash.NewSeedXXHash64(uint64(10))

	// Write some data to the hash
	h.Write([]byte("Hello, World!!"))

	// Write some more data to the hash
	h.Write([]byte("How are you doing?"))

	// Get the current hash as a byte array
	b := h.Sum(nil)
	fmt.Println(b)

	// Get the current hash as an integer (uint64) (little-endian)
	fmt.Println(h.Uint64())

	// Get the current hash as a hexadecimal string (big-endian)
	fmt.Println(h.String())

	// Reset the hash
	h.Reset()

}
Output:

[70 182 137 152 187 180 209 136]
5095411317493518728
46b68998bbb4d188

func NewSeedXXHash64

func NewSeedXXHash64(seed uint64) *XXHash64

NewSeedXXHash64 returns an instance of XXHash64 with the specified seed.

func NewXXHash64

func NewXXHash64() *XXHash64

NewXXHash64 returns an instance of XXHash64 with seed set to 0.

func (*XXHash64) BlockSize

func (x *XXHash64) BlockSize() int

BlockSize returns the hash's underlying block size.

func (*XXHash64) Reset

func (x *XXHash64) Reset()

Reset resets the Hash to its initial state.

func (*XXHash64) Size

func (x *XXHash64) Size() int

Size returns the number of bytes Sum will return.

func (*XXHash64) String

func (x *XXHash64) String() string

String returns the current value of the hash as a hexadecimal string

func (*XXHash64) Sum

func (x *XXHash64) Sum(b []byte) []byte

Sum appends the current hash to b and returns the resulting slice. It does not change the underlying has state

func (*XXHash64) Sum64

func (x *XXHash64) Sum64() uint64

Sum64 returns the current hash state

func (*XXHash64) Uint64

func (x *XXHash64) Uint64() uint64

Uint64 returns the current value of the hash as an uint64

func (*XXHash64) Write

func (x *XXHash64) Write(input []byte) (int, error)

Write adds more data to the running hash and updates the hash state It never returns an error

Jump to

Keyboard shortcuts

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