hash

package
v0.0.1-rc Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: MIT Imports: 13 Imported by: 21

Documentation

Index

Constants

View Source
const (
	// HashLength is the expected length of the hash
	HashLength = 32
)

Variables

View Source
var (
	// Zero is an empty hash.
	Zero = Hash{}
)
View Source
var (
	// ZeroEvent is a hash of virtual initial event.
	ZeroEvent = Event{}
)

Functions

func FakeEpoch

func FakeEpoch() idx.Epoch

FakeEpoch gives fixed value of fake epoch for testing purpose.

func FakeHash

func FakeHash(seed ...int64) (h common.Hash)

FakeHash generates random fake hash for testing purpose.

func FakePeer

func FakePeer(seed ...int64) idx.ValidatorID

FakePeer generates random fake peer id for testing purpose.

func GetEventName

func GetEventName(e Event) string

GetEventName gets an optional human readable alias of event hash.

func GetNodeName

func GetNodeName(n idx.ValidatorID) string

GetNodeName gets an optional human readable alias of node address.

func SetEventName

func SetEventName(e Event, name string)

SetEventName sets an optional human readable alias of event hash in log.

func SetNodeName

func SetNodeName(n idx.ValidatorID, name string)

SetNodeName sets an optional human readable alias of node address in log.

Types

type Event

type Event Hash

Event is a unique identifier of event. It is a hash of Event.

func BytesToEvent

func BytesToEvent(b []byte) Event

BytesToEvent converts bytes to event hash. If b is larger than len(h), b will be cropped from the left.

func FakeEvent

func FakeEvent() (h Event)

FakeEvent generates random fake event hash with the same epoch for testing purpose.

func HexToEventHash

func HexToEventHash(s string) Event

HexToEventHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func (*Event) Big

func (h *Event) Big() *big.Int

Big converts a hash to a big integer.

func (Event) Bytes

func (h Event) Bytes() []byte

Bytes returns value as byte slice.

func (Event) Epoch

func (h Event) Epoch() idx.Epoch

Epoch returns [0:4] bytes, which store event's Epoch.

func (Event) FullID

func (h Event) FullID() string

FullID returns human readable string representation with no information loss.

func (Event) Hex

func (h Event) Hex() string

Hex converts an event hash to a hex string.

func (*Event) IsZero

func (h *Event) IsZero() bool

IsZero returns true if hash is empty.

func (Event) Lamport

func (h Event) Lamport() idx.Lamport

Lamport returns [4:8] bytes, which store event's Lamport.

func (*Event) SetBytes

func (h *Event) SetBytes(raw []byte)

setBytes converts bytes to event hash. If b is larger than len(h), b will be cropped from the left.

func (Event) ShortID

func (h Event) ShortID(precision int) string

ShortID returns human readable ID representation, suitable for API calls.

func (Event) String

func (h Event) String() string

String returns human readable string representation.

type Events

type Events []Event

Events is a slice of event hashes.

func FakeEvents

func FakeEvents(n int) Events

FakeEvents generates random hashes of fake event with the same epoch for testing purpose.

func NewEvents

func NewEvents(h ...Event) Events

NewEvents makes event hash slice.

func (*Events) Add

func (hh *Events) Add(hash ...Event)

Add appends hash to the slice.

func (Events) Copy

func (hh Events) Copy() Events

Copy copies events to a new structure.

func (Events) Set

func (hh Events) Set() EventsSet

Set returns whole index as a EventsSet.

func (Events) String

func (hh Events) String() string

String returns human readable string representation.

type EventsSet

type EventsSet map[Event]struct{}

EventsSet provides additional methods of event hash index.

func NewEventsSet

func NewEventsSet(h ...Event) EventsSet

NewEventsSet makes event hash index.

func (EventsSet) Add

func (hh EventsSet) Add(hash ...Event)

Add appends hash to the index.

func (EventsSet) Contains

func (hh EventsSet) Contains(hash Event) bool

Contains returns true if hash is in.

func (EventsSet) Copy

func (hh EventsSet) Copy() EventsSet

Copy copies events to a new structure.

func (EventsSet) Erase

func (hh EventsSet) Erase(hash ...Event)

Erase erase hash from the index.

func (EventsSet) Slice

func (hh EventsSet) Slice() Events

Slice returns whole index as slice.

func (EventsSet) String

func (hh EventsSet) String() string

String returns human readable string representation.

type EventsStack

type EventsStack []Event

func (*EventsStack) Pop

func (s *EventsStack) Pop() *Event

Pop event ID from top. Erases element.

func (*EventsStack) Push

func (s *EventsStack) Push(v Event)

Push event ID on top

func (*EventsStack) PushAll

func (s *EventsStack) PushAll(vv Events)

PushAll event IDs on top

type Hash

type Hash [HashLength]byte

Hash represents the 32 byte hash of arbitrary data.

func BigToHash

func BigToHash(b *big.Int) Hash

BigToHash sets byte representation of b to hash. If b is larger than len(h), b will be cropped from the left.

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func FromBytes

func FromBytes(b []byte) Hash

FromBytes converts bytes to hash. If b is larger than len(h), b will be cropped from the left.

func HexToHash

func HexToHash(s string) Hash

HexToHash sets byte representation of s to hash. If b is larger than len(h), b will be cropped from the left.

func Of

func Of(data ...[]byte) (hash Hash)

Of returns hash of data

func (Hash) Big

func (h Hash) Big() *big.Int

Big converts a hash to a big integer.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes gets the byte representation of the underlying hash.

func (Hash) Format

func (h Hash) Format(s fmt.State, c rune)

Format implements fmt.Formatter, forcing the byte slice to be formatted as is, without going through the stringer interface used for logging.

func (Hash) Hex

func (h Hash) Hex() string

Hex converts a hash to a hex string.

func (Hash) MarshalText

func (h Hash) MarshalText() ([]byte, error)

MarshalText returns the hex representation of h.

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

setBytes sets the hash to the value of b. If b is larger than len(h), b will be cropped from the left.

func (Hash) String

func (h Hash) String() string

String implements the stringer interface and is used also by the logger when doing full logging into a file.

func (Hash) TerminalString

func (h Hash) TerminalString() string

TerminalString implements log.TerminalStringer, formatting a string for console output during logging.

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(input []byte) error

UnmarshalJSON parses a hash in hex syntax.

func (*Hash) UnmarshalText

func (h *Hash) UnmarshalText(input []byte) error

UnmarshalText parses a hash in hex syntax.

type Hashes

type Hashes []Hash

func NewHashes

func NewHashes(h ...Hash) Hashes

NewHashes makes hash slice.

func (*Hashes) Add

func (hh *Hashes) Add(hash ...Hash)

Add appends hash to the slice.

func (Hashes) Copy

func (hh Hashes) Copy() Hashes

Copy copies hashes to a new structure.

func (Hashes) Set

func (hh Hashes) Set() HashesSet

Set returns whole index as a HashesSet.

func (Hashes) String

func (hh Hashes) String() string

String returns human readable string representation.

type HashesSet

type HashesSet map[Hash]struct{}

func NewHashesSet

func NewHashesSet(h ...Hash) HashesSet

NewHashesSet makes hash index.

func (HashesSet) Add

func (hh HashesSet) Add(hash ...Hash)

Add appends hash to the index.

func (HashesSet) Contains

func (hh HashesSet) Contains(hash Hash) bool

Contains returns true if hash is in.

func (HashesSet) Copy

func (hh HashesSet) Copy() HashesSet

Copy copies hashes to a new structure.

func (HashesSet) Erase

func (hh HashesSet) Erase(hash ...Hash)

Erase erase hash from the index.

func (HashesSet) Slice

func (hh HashesSet) Slice() Hashes

Slice returns whole index as slice.

func (HashesSet) String

func (hh HashesSet) String() string

String returns human readable string representation.

type OrderedEvents

type OrderedEvents []Event

OrderedEvents is a sortable slice of event hashes.

func (OrderedEvents) ByEpochAndLamport

func (hh OrderedEvents) ByEpochAndLamport()

ByEpochAndLamport sorts events by epoch first, by lamport second, by ID third

func (OrderedEvents) Len

func (hh OrderedEvents) Len() int

func (OrderedEvents) Less

func (hh OrderedEvents) Less(i, j int) bool

func (OrderedEvents) String

func (hh OrderedEvents) String() string

String returns string representation.

func (OrderedEvents) Swap

func (hh OrderedEvents) Swap(i, j int)

Jump to

Keyboard shortcuts

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