metrohash

package module
v0.0.0-...-8d1c8b6 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: 0

README

Build Status Coverage Status GoDoc

metrohash

A pure Go port of metrohash algorithm

For more information about metrohash, see:

Installation

go get github.com/shivakar/metrohash

Usage

package main

import (
	"fmt"
	"github.com/shivakar/metrohash"
)

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

    // Create a new instance of the hash engine with custom seed
    _ = metrohash.NewSeedMetroHash64(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:
    // [205 190 61 93 89 212 164 71]
    // 14825354494498612295
    // cdbe3d5d59d4a447
}

License

metrohash is licensed under a MIT license.

Documentation

Overview

Package metrohash implements the metrohash hash algorithm.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MetroHash64

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

MetroHash64 implements the 64-bit variant of the metrohash algorithm. MetroHash64 implements hash.Hash and hash.Hash64 interfaces.

Example (Usage)

Examples

package main

import (
	"fmt"

	"github.com/shivakar/metrohash"
)

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

	// Create a new instance of the hash engine with custom seed
	_ = metrohash.NewSeedMetroHash64(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:

[205 190 61 93 89 212 164 71]
14825354494498612295
cdbe3d5d59d4a447

func NewMetroHash64

func NewMetroHash64() *MetroHash64

NewMetroHash64 returns an instance of MetroHash64 with seed set to 0.

func NewSeedMetroHash64

func NewSeedMetroHash64(seed uint64) *MetroHash64

NewSeedMetroHash64 returns an instance of MetroHash64 with the specified seed.

func (*MetroHash64) BlockSize

func (m *MetroHash64) BlockSize() int

BlockSize returns the hash's underlying block size.

func (*MetroHash64) Reset

func (m *MetroHash64) Reset()

Reset resets the Hash to its initial state.

func (*MetroHash64) Size

func (m *MetroHash64) Size() int

Size returns the number of bytes Sum will return.

func (*MetroHash64) String

func (m *MetroHash64) String() string

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

func (*MetroHash64) Sum

func (m *MetroHash64) Sum(b []byte) []byte

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

func (*MetroHash64) Sum64

func (m *MetroHash64) Sum64() uint64

Sum64 returns the current hash value

func (*MetroHash64) Uint64

func (m *MetroHash64) Uint64() uint64

Uint64 returns the current value of the hash as an uint64

func (*MetroHash64) Write

func (m *MetroHash64) Write(input []byte) (int, error)

Write adds more data to the running hash. It never returns an error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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