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 ¶
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 ¶
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 ¶
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 ¶
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]
type Float64 ¶
type Float64 []float64
Float64 represents a hash type where the smallest hash element is a float64.
func (Float64) Equal ¶
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
type UInt8 ¶
type UInt8 []uint8
UInt8 represents a hash type where the smallest hash element is a uint8 value.
func (UInt8) Equal ¶
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