Documentation
¶
Overview ¶
Package bin256 provides a binary 256-bit value.
Index ¶
- Constants
- Variables
- func Compare128(a, b Bin128) int
- func Compare256(a, b Bin256) int
- func Compare64(a, b Bin64) int
- func Sort128(vv []Bin128)
- func Sort256(vv []Bin256)
- func Sort64(vv []Bin64)
- type Bin128
- func (b Bin128) AppendHexTo(buf []byte) []byte
- func (b Bin128) Compare(b1 Bin128) int
- func (b Bin128) Equal(b1 Bin128) bool
- func (b Bin128) Hash32() uint32
- func (b Bin128) Hash64() uint64
- func (b Bin128) Int64() (int64, int64)
- func (b Bin128) IsZero() bool
- func (b Bin128) Less(b1 Bin128) bool
- func (b Bin128) Marshal() []byte
- func (b Bin128) MarshalJSON() ([]byte, error)
- func (b Bin128) MarshalTo(buf []byte)
- func (b Bin128) MarshalToBuffer(buf buffer.Buffer) []byte
- func (b Bin128) Size() int
- func (b Bin128) String() string
- func (b Bin128) Uint64() (uint64, uint64)
- func (b *Bin128) Unmarshal(buf []byte) error
- func (b *Bin128) UnmarshalJSON(buf []byte) error
- type Bin256
- func (b Bin256) AppendHexTo(buf []byte) []byte
- func (b Bin256) Bin128() [2]Bin128
- func (b Bin256) Compare(b1 Bin256) int
- func (b Bin256) Equal(b1 Bin256) bool
- func (b Bin256) Hash32() uint32
- func (b Bin256) Hash64() uint64
- func (b Bin256) Int64() [4]int64
- func (b Bin256) IsZero() bool
- func (b Bin256) Less(b1 Bin256) bool
- func (b Bin256) Marshal() []byte
- func (b Bin256) MarshalJSON() ([]byte, error)
- func (b Bin256) MarshalTo(buf []byte)
- func (b Bin256) MarshalToBuffer(buf buffer.Buffer) []byte
- func (b Bin256) Size() int
- func (b Bin256) String() string
- func (b Bin256) Uint64() [4]uint64
- func (b *Bin256) Unmarshal(buf []byte) error
- func (b *Bin256) UnmarshalJSON(buf []byte) error
- type Bin64
- func (b Bin64) AppendHexTo(buf []byte) []byte
- func (b Bin64) Compare(b1 Bin64) int
- func (b Bin64) Equal(b1 Bin64) bool
- func (b Bin64) Hash32() uint32
- func (b Bin64) Hash64() uint64
- func (b Bin64) Int64() int64
- func (b Bin64) IsZero() bool
- func (b Bin64) Less(b1 Bin64) bool
- func (b Bin64) Marshal() []byte
- func (b Bin64) MarshalJSON() ([]byte, error)
- func (b Bin64) MarshalTo(buf []byte)
- func (b Bin64) MarshalToBuffer(buf buffer.Buffer) []byte
- func (b Bin64) Size() int
- func (b Bin64) String() string
- func (b Bin64) Uint64() uint64
- func (b *Bin64) Unmarshal(buf []byte) error
- func (b *Bin64) UnmarshalJSON(buf []byte) error
- type Hash128
- type Hash256
Constants ¶
const Len128 = 16
const Len128Char = (Len128 * 2) + 1 // 341a7d60bc5893a6-4bda3de06721534c
const Len256 = 32
const Len256Char = (Len256 * 2) + 3
const Len64 = 8
const Len64Char = (Len64 * 2) // 341a7d60bc5893a6
Variables ¶
var Max128 = Bin128{Max64, Max64}
var Max64 = Bin64{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
var Regexp128 = regexp.MustCompile(`^[0-9A-Za-z]{16}-[0-9A-Za-z]{16}$`)
var Regexp256 = regexp.MustCompile(`^[0-9A-Za-z]{16}-[0-9A-Za-z]{16}-[0-9A-Za-z]{16}-[0-9A-Za-z]{16}$`)
var Regexp64 = regexp.MustCompile(`^[0-9A-Za-z]{16}$`)
Functions ¶
func Compare128 ¶
Compare128 compares two bin128 values.
Returns:
-1 if a < b 0 if a == b 1 if a > b
func Compare256 ¶
Compare256 compares two bin256 values.
Returns:
-1 if a < b 0 if a == b 1 if a > b
Types ¶
type Bin128 ¶
type Bin128 [2]Bin64
Bin128 is a 128-bit value.
func MustParseString128 ¶
MustParseString128 parses a bin128 from 33-char string or panics.
func ParseString128 ¶
ParseString128 parses a bin128 from 33-char string.
func TimeRandom128 ¶
func TimeRandom128() Bin128
TimeRandom128 returns a time-random bin128 with a millisecond resolution.
func (Bin128) AppendHexTo ¶
AppendHexTo appends a 33-char lower-case hex-encoded string to a buffer.
func (Bin128) Hash32 ¶
Hash32 returns a 32-bit hash. The method decodes the value as two big-endian uint64s and then xors their halves.
func (Bin128) Hash64 ¶
Hash64 returns a 64-bit hash. The method decodes the value as two big-endian uint64s and then xors them.
func (Bin128) MarshalJSON ¶
MarshalJSON marshals the value to a JSON string.
func (Bin128) MarshalToBuffer ¶
MarshalToBuffer marshals the value to a buffer.
func (*Bin128) UnmarshalJSON ¶
MarshalJSON parses the value from a JSON string.
type Bin256 ¶
type Bin256 [4]Bin64
Bin256 is a 32 byte value.
func MustParseString256 ¶
MustParseString256 parses a bin256 from 67-char string or panics.
func ParseString256 ¶
ParseString256 parses a bin256 from 67-char string.
func TimeRandom256 ¶
func TimeRandom256() Bin256
TimeRandom256 returns a time-random bin256 with a millisecond resolution.
func (Bin256) AppendHexTo ¶
AppendHexTo appends a 67-char lower-case hex-encoded string to a buffer.
func (Bin256) Hash32 ¶
Hash32 returns a 32-bit hash. The method decodes the value as four big-endian uint64s and then xors their halves.
func (Bin256) Hash64 ¶
Hash64 returns a 64-bit hash. The method decodes the value as four big-endian uint64s and then xors them.
func (Bin256) MarshalJSON ¶
MarshalJSON marshals the value to a JSON string.
func (Bin256) MarshalToBuffer ¶
MarshalToBuffer marshals the value to a buffer.
func (*Bin256) UnmarshalJSON ¶
MarshalJSON parses the value from a JSON string.
type Bin64 ¶
type Bin64 [8]byte
Bin64 is a binary 64-bit value.
func MustParseString64 ¶
MustParseString64 parses a bin64 from 16-char string or panics.
func ParseString64 ¶
ParseString64 parses a bin64 from 32-char string.
func TimeRandom64 ¶
func TimeRandom64() Bin64
TimeRandom64 returns a time-random bin64 with a second resolution.
func (Bin64) AppendHexTo ¶
AppendHexTo appends a 16-char lower-case hex-encoded string to a buffer.
func (Bin64) Hash32 ¶
Hash32 returns a 32-bit hash of the value. The method decodes the value as a big-endian uint64 and then xors the two halves.
func (Bin64) Hash64 ¶
Hash64 returns a 64-bit hash of the value. The method decodes the value as a big-endian uint64.
func (Bin64) MarshalJSON ¶
MarshalJSON marshals the value to a JSON string.
func (Bin64) MarshalToBuffer ¶
MarshalToBuffer marshals the value to a buffer.
func (*Bin64) UnmarshalJSON ¶
MarshalJSON parses the value from a JSON string.