knownRounds

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: BSD-2-Clause Imports: 7 Imported by: 3

Documentation

Overview

Package knownRounds tracks which rounds have been checked and which are unchecked using a bit stream.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiskKnownRounds

type DiskKnownRounds struct {
	BitStream                   []byte
	FirstUnchecked, LastChecked uint64
}

DiskKnownRounds structure is used to as an intermediary to marshal and unmarshal KnownRounds.

type KnownRounds

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

KnownRounds structure tracks which rounds are known and which are unknown. Each bit in bitStream corresponds to a round ID and if it is set, it means the round has been checked. All rounds before firstUnchecked are known to be checked. All rounds after lastChecked are unknown.

func NewFromParts

func NewFromParts(
	buff []uint64, firstUnchecked, lastChecked id.Round, fuPos int) *KnownRounds

NewFromParts creates a new KnownRounds from the given firstUnchecked, lastChecked, fuPos, and uint64 buffer.

func NewKnownRound

func NewKnownRound(roundCapacity int) *KnownRounds

NewKnownRound creates a new empty KnownRounds in the default state with a bit stream that can hold the given number of rounds.

func (*KnownRounds) Check

func (kr *KnownRounds) Check(rid id.Round)

Check denotes a round has been checked. If the passed in round occurred after the last checked round, then every round between them is set as unchecked and the passed in round becomes the last checked round. Will panic if the buffer is not large enough to hold the current data and the new data

func (*KnownRounds) Checked

func (kr *KnownRounds) Checked(rid id.Round) bool

Checked determines if the round has been checked.

func (*KnownRounds) ForceCheck

func (kr *KnownRounds) ForceCheck(rid id.Round)

func (*KnownRounds) Forward

func (kr *KnownRounds) Forward(rid id.Round)

Forward sets all rounds before the given round ID as checked.

func (KnownRounds) GetBitStream

func (kr KnownRounds) GetBitStream() []uint64

func (KnownRounds) GetFirstUnchecked

func (kr KnownRounds) GetFirstUnchecked() id.Round

func (KnownRounds) GetFuPos

func (kr KnownRounds) GetFuPos() int

func (KnownRounds) GetLastChecked

func (kr KnownRounds) GetLastChecked() id.Round

func (*KnownRounds) Len

func (kr *KnownRounds) Len() int

Len returns the max number of round IDs the buffer can hold.

func (*KnownRounds) Marshal

func (kr *KnownRounds) Marshal() []byte

Marshal returns the JSON encoding of DiskKnownRounds, which contains the compressed information from KnownRounds. The bit stream is compressed such that the firstUnchecked occurs in the first block of the bit stream.

func (KnownRounds) MarshalBitStream1Byte

func (kr KnownRounds) MarshalBitStream1Byte() []byte

func (KnownRounds) MarshalBitStream2Byte

func (kr KnownRounds) MarshalBitStream2Byte() []byte

func (KnownRounds) MarshalBitStream4Byte

func (kr KnownRounds) MarshalBitStream4Byte() []byte

func (KnownRounds) MarshalBitStream8Byte

func (kr KnownRounds) MarshalBitStream8Byte() []byte

func (*KnownRounds) OutputBuffChanges

func (kr *KnownRounds) OutputBuffChanges(
	old []uint64) (KrChanges, id.Round, id.Round, int, error)

OutputBuffChanges returns the current KnownRounds' firstUnchecked, lastChecked, fuPos, and a list of changes between the given uint64 buffer and the current KnownRounds bit stream. An error is returned if the two buffers are not of the same length.

func (*KnownRounds) RangeUnchecked

func (kr *KnownRounds) RangeUnchecked(oldestUnknown id.Round, threshold uint,
	roundCheck func(id id.Round) bool, maxPickups int) (
	earliestRound id.Round, has, unknown []id.Round)

RangeUnchecked runs the passed function over all rounds starting with oldest unknown and ending with

func (*KnownRounds) RangeUncheckedMasked

func (kr *KnownRounds) RangeUncheckedMasked(mask *KnownRounds,
	roundCheck RoundCheckFunc, maxChecked int)

RangeUncheckedMasked masks the bit stream with the provided mask.

func (*KnownRounds) RangeUncheckedMaskedRange

func (kr *KnownRounds) RangeUncheckedMaskedRange(mask *KnownRounds,
	roundCheck RoundCheckFunc, start, end id.Round, maxChecked int)

RangeUncheckedMaskedRange masks the bit stream with the provided mask.

func (*KnownRounds) Truncate

func (kr *KnownRounds) Truncate(start id.Round) *KnownRounds

Truncate returns a subs ample of the KnownRounds buffer from last checked.

func (*KnownRounds) Unmarshal

func (kr *KnownRounds) Unmarshal(data []byte) error

Unmarshal parses the JSON-encoded data and stores it in the KnownRounds. An error is returned if the bit stream data is larger than the KnownRounds bit stream.

type KrChanges

type KrChanges map[int]uint64

KrChanges map contains a list of changes between two KnownRounds bit streams. The key is the index of the changed word and the value contains the change.

type RoundCheckFunc

type RoundCheckFunc func(id id.Round) bool

Jump to

Keyboard shortcuts

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