hashtype

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package hashtype implements data types used to represent hashes. It can be used by hashing algorithm implementations to represent the algorithm's results.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrOutOfBounds = errors.New("position out of bounds")

ErrOutOfBounds is reported when the bit position is larger than the number of bits in the hash.

Functions

This section is empty.

Types

type Binary

type Binary []byte

Binary represents a hash type where the smallest hash element is a bit.

func (Binary) Equal

func (h Binary) Equal(bh Binary) bool

Equal checks if two binary hashes are the same. Returns true if the hashes match.

Example
h1 := Binary{1, 2, 128}
h2 := Binary{2, 128}
h3 := Binary{1, 2, 128}
fmt.Println(h1.Equal(h2))
fmt.Println(h1.Equal(h3))
Output:

false
true

func (Binary) Set

func (h Binary) Set(position uint) error

Set turns a bit on in the binary hash. The position argument determines which bit should be turned on. Returns error if position is out of bounds.

Example
hash := Binary{0, 0}
hash.Set(0)
hash.Set(15)
fmt.Println(hash.String())
Output:

[1 128]

func (Binary) SetReverse

func (h Binary) SetReverse(position uint) error

SetReverse turns a bit on in the binary hash. The position argument determines which bit should be turned on, where position is counted in reverse order. Returns error if position is out of bounds.

Example
hash := Binary{0, 0}
hash.SetReverse(0)
hash.SetReverse(15)
fmt.Println(hash.String())
Output:

[128 1]

func (Binary) String

func (h Binary) String() string

String returns a string representation of the binary hash. Is is formated as an array of bytes.

Example
hash := Binary{115, 247, 1}
fmt.Println(hash.String())
Output:

[115 247 1]

type Float64

type Float64 []float64

Float64 represents a hash type where the smallest hash element is a float64.

func (Float64) Equal

func (h Float64) Equal(fh Float64) bool

Equal checks if two float64 hashes are the same. It uses an epsilon based value comparrison. Returns true if each same index value pair is within an epsilon distance of each other. If the hashes aren't equal size the function returns false.

Example
h1 := Float64{0, 1.1, 2.22, 3.333}
h2 := Float64{0, 1.1, 2.22}
h3 := Float64{0, 1.1, 2.22, 3.333}
fmt.Println(h1.Equal(h2))
fmt.Println(h1.Equal(h3))
Output:

false
true

func (Float64) String

func (h Float64) String() string

String returns a string representation of the float64 hash. Is is formated as a slice of float64 values.

Example
hash := Float64{0.000000000000000012345678, 3892.1234567890123456789}
fmt.Println(hash.String())
Output:

[1.2345678e-17 3892.1234567890124]

type UInt8

type UInt8 []uint8

UInt8 represents a hash type where the smallest hash element is a uint8 value.

func (UInt8) Equal

func (h UInt8) Equal(uh UInt8) bool

Equal checks if two uint8 hashes are the same. It checks each same index value pair. Returns true if all elements match. If the length of hashes isn't the same the function returns false.

Example
h1 := UInt8{0, 1, 2, 3}
h2 := UInt8{0, 1, 2}
h3 := UInt8{0, 1, 2, 3}
fmt.Println(h1.Equal(h2))
fmt.Println(h1.Equal(h3))
Output:

false
true

func (UInt8) String

func (h UInt8) String() string

String returns a string representation of uint8 hash. Is is formated as a uint8 slice.

Example
hash := UInt8{0, 1, 2, 3, 4, 5}
fmt.Println(hash.String())
Output:

[0 1 2 3 4 5]

Jump to

Keyboard shortcuts

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