markers

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: Apache-2.0, BSD-2-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithIncreaseIndexCallback

func WithIncreaseIndexCallback(callback IncreaseIndexCallback) options.Option[SequenceManager]

WithIncreaseIndexCallback is an Option for the SequenceManager that allows to specify whether a new marker index should be created. This is especially useful for testing.

func WithMaxPastMarkerDistance

func WithMaxPastMarkerDistance(distance uint64) options.Option[SequenceManager]

WithMaxPastMarkerDistance is an Option for the SequenceManager that allows to specify how many consecutive blocks are allowed to not receive a new PastMaster before we create a new Sequence.

func WithSequenceManager

func WithSequenceManager(sequenceManager *SequenceManager) options.Option[TestFramework]

Types

type IncreaseIndexCallback

type IncreaseIndexCallback func(sequenceID SequenceID, currentHighestIndex Index) bool

IncreaseIndexCallback is the type of the callback function that is used to determine if a new Index is supposed to be assigned in a given Sequence.

type Index

type Index uint64

Index represents the ever-increasing number of the Markers in a Sequence.

func (Index) Length

func (i Index) Length() int

Length returns the amount of bytes of a serialized Index.

func (Index) String

func (i Index) String() (humanReadable string)

String returns a human-readable version of the Index.

type Marker

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

Marker represents a coordinate in a Sequence that is identified by an ever-increasing Index.

func NewMarker

func NewMarker(sequenceID SequenceID, index Index) Marker

NewMarker returns a new marker.

func (Marker) Index

func (m Marker) Index() Index

func (Marker) SequenceID

func (m Marker) SequenceID() SequenceID

type Markers

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

Markers represents a collection of Markers that can contain exactly one Index per SequenceID.

func NewMarkers

func NewMarkers(markers ...Marker) (m *Markers)

NewMarkers creates a new collection of Markers.

func (*Markers) Clone

func (m *Markers) Clone() (cloned *Markers)

Clone creates a deep copy of the Markers.

func (*Markers) Delete

func (m *Markers) Delete(sequenceID SequenceID) (existed bool)

Delete removes the Marker with the given SequenceID from the collection and returns a boolean flag that indicates if the element existed.

func (*Markers) Equals

func (m *Markers) Equals(other *Markers) (equals bool)

Equals is a comparator for two Markers.

func (*Markers) ForEach

func (m *Markers) ForEach(iterator func(sequenceID SequenceID, index Index) bool) (success bool)

ForEach calls the iterator for each of the contained Markers. The iteration is aborted if the iterator returns false. The method returns false if the iteration was aborted.

func (*Markers) ForEachSorted

func (m *Markers) ForEachSorted(iterator func(sequenceID SequenceID, index Index) bool) (success bool)

ForEachSorted calls the iterator for each of the contained Markers in increasing order. The iteration is aborted if the iterator returns false. The method returns false if the iteration was aborted.

func (*Markers) Get

func (m *Markers) Get(sequenceID SequenceID) (index Index, exists bool)

Get returns the Index of the Marker with the given Sequence and a flag that indicates if the Marker exists.

func (*Markers) HighestIndex

func (m *Markers) HighestIndex() (highestIndex Index)

HighestIndex returns the highest Index of all Markers in the collection.

func (*Markers) LowestIndex

func (m *Markers) LowestIndex() (lowestIndex Index)

LowestIndex returns the lowest Index of all Markers in the collection.

func (*Markers) Marker

func (m *Markers) Marker() (marker Marker)

Marker type casts the Markers to a Marker if it contains only 1 element.

func (*Markers) Merge

func (m *Markers) Merge(markers *Markers)

Merge takes the given Markers and adds them to the collection (overwriting Markers with a lower Index if there are existing Markers with the same SequenceID).

func (*Markers) Set

func (m *Markers) Set(sequenceID SequenceID, index Index) (updated, added bool)

Set adds a new Marker to the collection and updates the Index of an existing entry if it is higher than a possible previously stored one. The method returns two boolean flags that indicate if an entry was updated and/or added.

func (*Markers) Size

func (m *Markers) Size() (size int)

Size returns the amount of Markers in the collection.

func (*Markers) String

func (m *Markers) String() string

type ReferencedMarkers

type ReferencedMarkers struct {
	syncutils.RWMutexFake
	// contains filtered or unexported fields
}

ReferencedMarkers is a data structure that allows to denote which Marker of a Sequence references which other Markers of its parent Sequences in the Sequence DAG.

func NewReferencedMarkers

func NewReferencedMarkers(markers *Markers) (r *ReferencedMarkers)

NewReferencedMarkers is the constructor for the ReferencedMarkers.

func (*ReferencedMarkers) Add

func (r *ReferencedMarkers) Add(index Index, referencedMarkers *Markers)

Add adds new referenced Markers to the ReferencedMarkers.

func (*ReferencedMarkers) Delete

func (r *ReferencedMarkers) Delete(id SequenceID)

func (*ReferencedMarkers) Get

func (r *ReferencedMarkers) Get(index Index) (referencedMarkers *Markers)

Get returns the Markers of parent Sequences that were referenced by the given Index.

func (*ReferencedMarkers) String

func (r *ReferencedMarkers) String() (humanReadableReferencedMarkers string)

String returns a human-readable version of the ReferencedMarkers.

type ReferencingMarkers

type ReferencingMarkers struct {
	syncutils.RWMutexFake
	// contains filtered or unexported fields
}

ReferencingMarkers is a data structure that allows to denote which Markers of child Sequences in the Sequence DAG reference a given Marker in a Sequence.

func NewReferencingMarkers

func NewReferencingMarkers() (referencingMarkers *ReferencingMarkers)

NewReferencingMarkers is the constructor for the ReferencingMarkers.

func (*ReferencingMarkers) Add

func (r *ReferencingMarkers) Add(index Index, referencingMarker Marker)

Add adds a new referencing Marker to the ReferencingMarkers.

func (*ReferencingMarkers) Get

func (r *ReferencingMarkers) Get(index Index) (referencingMarkers *Markers)

Get returns the Markers of child Sequences that reference the given Index.

func (*ReferencingMarkers) GetSequenceIDs

func (r *ReferencingMarkers) GetSequenceIDs() (referencingSequenceIDs SequenceIDs)

GetSequenceIDs returns the SequenceIDs of child Sequences.

func (*ReferencingMarkers) String

func (r *ReferencingMarkers) String() (humanReadableReferencingMarkers string)

String returns a human-readable version of the ReferencingMarkers.

type Sequence

type Sequence struct {
	syncutils.RWMutexFake
	// contains filtered or unexported fields
}

Sequence represents a set of ever-increasing Indexes that are encapsulating a certain part of the DAG.

func NewSequence

func NewSequence(id SequenceID, referencedMarkers *Markers) (s *Sequence)

NewSequence creates a new Sequence from the given details.

func (*Sequence) AddReferencingMarker

func (s *Sequence) AddReferencingMarker(index Index, referencingMarker Marker)

AddReferencingMarker register a Marker that referenced the given Index of this Sequence.

func (*Sequence) HighestIndex

func (s *Sequence) HighestIndex() Index

HighestIndex returns the Index of the latest Marker in the Sequence.

func (*Sequence) ID

func (s *Sequence) ID() SequenceID

func (*Sequence) IncreaseHighestIndex

func (s *Sequence) IncreaseHighestIndex(referencedMarkers *Markers) (index Index, increased bool)

IncreaseHighestIndex increases the highest Index of the Sequence if the referencedMarkers directly reference the Marker with the highest Index. It returns the new Index and a boolean flag that indicates if the value was increased.

func (*Sequence) LowestIndex

func (s *Sequence) LowestIndex() Index

LowestIndex returns the Index of the very first Marker in the Sequence.

func (*Sequence) ReferencedMarkers

func (s *Sequence) ReferencedMarkers(index Index) *Markers

ReferencedMarkers returns a collection of Markers that were referenced by the given Index.

func (*Sequence) ReferencingMarkers

func (s *Sequence) ReferencingMarkers(index Index) *Markers

ReferencingMarkers returns a collection of Markers that reference the given Index.

func (*Sequence) ReferencingSequences

func (s *Sequence) ReferencingSequences() SequenceIDs

ReferencingSequences returns a collection of SequenceIDs that reference the Sequence.

func (*Sequence) TryExtend

func (s *Sequence) TryExtend(referencedPastMarkers *Markers, increaseIndexCallback IncreaseIndexCallback) (index Index, remainingReferencedPastMarkers *Markers, extended bool)

TryExtend tries to extend the Sequence with a new Index by checking if the referenced PastMarkers contain the last assigned Index of the Sequence. It returns the new Index, the remaining Markers pointing to other Sequences and a boolean flag that indicating if a new Index was assigned.

type SequenceID

type SequenceID uint64

SequenceID is the type of the identifier of a Sequence.

func (SequenceID) Bytes

func (s SequenceID) Bytes() (marshaledSequenceID []byte)

Bytes returns a marshaled version of the SequenceID.

func (*SequenceID) FromBytes

func (s *SequenceID) FromBytes(data []byte) (err error)

FromBytes unmarshals a SequenceID from a sequence of bytes.

func (SequenceID) Length

func (s SequenceID) Length() int

Length returns the length of a serialized SequenceID.

func (SequenceID) String

func (s SequenceID) String() (humanReadableSequenceID string)

String returns a human-readable version of the SequenceID.

type SequenceIDs

type SequenceIDs = *advancedset.AdvancedSet[SequenceID]

SequenceIDs represents a collection of SequenceIDs.

func NewSequenceIDs

func NewSequenceIDs(sequenceIDs ...SequenceID) (result SequenceIDs)

NewSequenceIDs creates a new collection of SequenceIDs.

type SequenceManager

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

SequenceManager is the managing entity for the Marker related business logic. It is stateful and automatically stores its state in a memstorage.

func NewSequenceManager

func NewSequenceManager(opts ...options.Option[SequenceManager]) (m *SequenceManager)

NewSequenceManager is the constructor of the SequenceManager that takes a KVStore to persist its state.

func (*SequenceManager) Delete

func (s *SequenceManager) Delete(id SequenceID)

func (*SequenceManager) InheritStructureDetails

func (s *SequenceManager) InheritStructureDetails(referencedStructureDetails []*StructureDetails, allParentsInPastSlot bool) (inheritedStructureDetails *StructureDetails, newSequenceCreated bool)

InheritStructureDetails takes the StructureDetails of the referenced parents and returns new StructureDetails for the block that was just added to the DAG. It automatically creates a new Sequence and Index if necessary and returns an additional flag that indicates if a new Sequence was created. When attaching to one of the root blocks, a new sequence is always created and the block is assigned Index(1), while Index(0) is a root index. InheritStructureDetails inherits the structure details of the given parent StructureDetails.

func (*SequenceManager) Sequence

func (s *SequenceManager) Sequence(sequenceID SequenceID) (sequence *Sequence, exists bool)

Sequence retrieves a Sequence by its ID.

func (*SequenceManager) SetIncreaseIndexCallback

func (s *SequenceManager) SetIncreaseIndexCallback(callback IncreaseIndexCallback)

type StructureDetails

type StructureDetails struct {
	syncutils.RWMutexFake
	// contains filtered or unexported fields
}

StructureDetails represents a container for the complete Marker related information of a node in a DAG that are used to interact with the public API of this package.

func NewStructureDetails

func NewStructureDetails() (s *StructureDetails)

NewStructureDetails creates an empty StructureDetails object.

func (*StructureDetails) Clone

func (s *StructureDetails) Clone() (clone *StructureDetails)

Clone creates a deep copy of the StructureDetails.

func (*StructureDetails) IsPastMarker

func (s *StructureDetails) IsPastMarker() (isPastMarker bool)

func (*StructureDetails) PastMarkerGap

func (s *StructureDetails) PastMarkerGap() (pastMarkerGap uint64)

func (*StructureDetails) PastMarkers

func (s *StructureDetails) PastMarkers() (pastMarkers *Markers)

func (*StructureDetails) Rank

func (s *StructureDetails) Rank() (rank uint64)

func (*StructureDetails) SetIsPastMarker

func (s *StructureDetails) SetIsPastMarker(isPastMarker bool)

func (*StructureDetails) SetPastMarkerGap

func (s *StructureDetails) SetPastMarkerGap(pastMarkerGap uint64)

func (*StructureDetails) SetPastMarkers

func (s *StructureDetails) SetPastMarkers(pastMarkers *Markers)

func (*StructureDetails) SetRank

func (s *StructureDetails) SetRank(rank uint64)

func (*StructureDetails) String

func (s *StructureDetails) String() string

type TestFramework

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

func NewTestFramework

func NewTestFramework(t *testing.T, opts ...options.Option[TestFramework]) (newFramework *TestFramework)

NewTestFramework is the constructor of the TestFramework.

func (*TestFramework) InheritStructureDetails

func (t *TestFramework) InheritStructureDetails(alias string, inheritedStructureDetails []*StructureDetails) (structureDetails *StructureDetails, created bool)

func (*TestFramework) SequenceManager

func (t *TestFramework) SequenceManager() (sequenceTracker *SequenceManager)

func (*TestFramework) StructureDetails

func (t *TestFramework) StructureDetails(alias string) (structureDetails *StructureDetails)

func (*TestFramework) StructureDetailsSet

func (t *TestFramework) StructureDetailsSet(aliases ...string) (structureDetailsSlice []*StructureDetails)

Jump to

Keyboard shortcuts

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