time

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package time provides logical clock and ticket for document.

Index

Constants

View Source
const (
	// MaxLamport is the maximum value stored in lamport.
	MaxLamport = math.MaxInt64

	// MaxDelimiter is the maximum value stored in delimiter.
	MaxDelimiter = math.MaxUint32
)

Variables

View Source
var (
	// InitialActorID represents the initial value of ActorID.
	InitialActorID = &ActorID{}

	// MaxActorID represents the maximum value of ActorID.
	MaxActorID = &ActorID{
		bytes: [actorIDSize]byte{
			math.MaxUint8,
			math.MaxUint8,
			math.MaxUint8,
			math.MaxUint8,
			math.MaxUint8,
			math.MaxUint8,
			math.MaxUint8,
			math.MaxUint8,
			math.MaxUint8,
			math.MaxUint8,
			math.MaxUint8,
			math.MaxUint8,
		},
	}

	// ErrInvalidHexString is returned when the given string is not valid hex.
	ErrInvalidHexString = errors.New("invalid hex string")

	// ErrInvalidActorID is returned when the given ID is not valid.
	ErrInvalidActorID = errors.New("invalid actor id")
)
View Source
var (
	// InitialTicket is the initial value of Ticket.
	InitialTicket = NewTicket(
		0,
		0,
		InitialActorID,
	)

	// MaxTicket is the maximum value of Ticket.
	MaxTicket = NewTicket(
		MaxLamport,
		MaxDelimiter,
		MaxActorID,
	)
)
View Source
var InitialVersionVector = VersionVector{}

InitialVersionVector is the initial version vector.

Functions

This section is empty.

Types

type ActorID

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

ActorID represents the unique ID of the client. It is composed of 12 bytes. It caches the string representation of ActorID to reduce the number of calls to hex.EncodeToString. This causes a multi-routine problem, so it is recommended to use it in a single routine or to use it after locking.

func ActorIDFromBytes added in v0.1.2

func ActorIDFromBytes(bytes []byte) (*ActorID, error)

ActorIDFromBytes returns the bytes represented by the bytes of decoded hexadecimal string itself.

func ActorIDFromHex

func ActorIDFromHex(str string) (*ActorID, error)

ActorIDFromHex returns the bytes represented by the hexadecimal string str.

func (*ActorID) Bytes added in v0.1.2

func (id *ActorID) Bytes() []byte

Bytes returns the bytes of ActorID itself. If the receiver is nil, it would return empty array of byte.

func (*ActorID) Compare

func (id *ActorID) Compare(other *ActorID) int

Compare returns an integer comparing two ActorID lexicographically. The result will be 0 if id==other, -1 if id < other, and +1 if id > other. If the receiver or argument is nil, it would panic at runtime.

func (*ActorID) MarshalJSON added in v0.2.4

func (id *ActorID) MarshalJSON() ([]byte, error)

MarshalJSON ensures that when calling json.Marshal(), it is marshaled including private field.

func (*ActorID) String

func (id *ActorID) String() string

String returns the hexadecimal encoding of ActorID. If the receiver is nil, it would return empty string.

func (*ActorID) UnmarshalJSON added in v0.2.4

func (id *ActorID) UnmarshalJSON(bytes []byte) error

UnmarshalJSON ensures that when calling json.Unmarshal(), it is unmarshalled including private field.

type Ticket

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

Ticket represents the logical clock. It is used to determine the order of changes and identify elements and nodes in the document. It can't be used to detect the relationship between changes whether they are causally related or concurrent.

func NewTicket

func NewTicket(
	lamport int64,
	delimiter uint32,
	actorID *ActorID,
) *Ticket

NewTicket creates an instance of Ticket.

func (*Ticket) ActorID

func (t *Ticket) ActorID() *ActorID

ActorID returns the actorID value.

func (*Ticket) ActorIDBytes added in v0.1.2

func (t *Ticket) ActorIDBytes() []byte

ActorIDBytes returns the actorID's bytes value.

func (*Ticket) ActorIDHex

func (t *Ticket) ActorIDHex() string

ActorIDHex returns the actorID's hex value.

func (*Ticket) After

func (t *Ticket) After(other *Ticket) bool

After returns whether the given ticket was created later.

func (*Ticket) Compare

func (t *Ticket) Compare(other *Ticket) int

Compare returns an integer comparing two Ticket. The result will be 0 if id==other, -1 if id < other, and +1 if id > other. If the receiver or argument is nil, it would panic at runtime.

func (*Ticket) Delimiter

func (t *Ticket) Delimiter() uint32

Delimiter returns the delimiter value.

func (*Ticket) Key

func (t *Ticket) Key() string

Key returns the key string for this Ticket.

func (*Ticket) Lamport

func (t *Ticket) Lamport() int64

Lamport returns the lamport value.

func (*Ticket) SetActorID

func (t *Ticket) SetActorID(actorID *ActorID) *Ticket

SetActorID creates a new instance of Ticket with the given actorID.

func (*Ticket) ToTestString added in v0.4.8

func (t *Ticket) ToTestString() string

ToTestString returns a string containing the metadata of the ticket for debugging purpose.

type VersionVector added in v0.5.3

type VersionVector map[actorID]int64

VersionVector is similar to vector clock, but it is synced with Lamport timestamp of the current change.

func NewVersionVector added in v0.5.3

func NewVersionVector() VersionVector

NewVersionVector creates a new instance of VersionVector.

func (VersionVector) AfterOrEqual added in v0.5.3

func (v VersionVector) AfterOrEqual(other VersionVector) bool

AfterOrEqual returns whether this VersionVector is causally after or equal the given VersionVector.

func (VersionVector) DeepCopy added in v0.5.3

func (v VersionVector) DeepCopy() VersionVector

DeepCopy creates a deep copy of this VersionVector.

func (VersionVector) EqualToOrAfter added in v0.5.3

func (v VersionVector) EqualToOrAfter(other *Ticket) bool

EqualToOrAfter returns whether this VersionVector's every field is equal or after than given ticket.

func (VersionVector) Filter added in v0.5.3

func (v VersionVector) Filter(filter []*ActorID) VersionVector

Filter returns filtered version vector which keys are only from filter

func (VersionVector) Keys added in v0.5.3

func (v VersionVector) Keys() ([]*ActorID, error)

Keys returns a slice of ActorIDs present in the VersionVector.

func (VersionVector) Marshal added in v0.5.3

func (v VersionVector) Marshal() string

Marshal returns the JSON encoding of this VersionVector.

func (VersionVector) Max added in v0.5.3

Max returns new vv consists of every max value in each column.

func (VersionVector) MaxLamport added in v0.5.3

func (v VersionVector) MaxLamport() int64

MaxLamport returns new vv consists of every max value in each column.

func (VersionVector) Min added in v0.5.3

Min returns new vv consists of every min value in each column.

func (VersionVector) Set added in v0.5.3

func (v VersionVector) Set(id *ActorID, i int64)

Set sets the given actor's version to the given value.

func (VersionVector) Unset added in v0.5.3

func (v VersionVector) Unset(id *ActorID)

Unset removes the version for the given actor from the VersionVector.

func (VersionVector) VersionOf added in v0.5.3

func (v VersionVector) VersionOf(id *ActorID) int64

VersionOf returns the version of the given actor.

Jump to

Keyboard shortcuts

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