Documentation ¶
Overview ¶
Package time provides logical clock and ticket for document.
Index ¶
- Constants
- Variables
- type ActorID
- type Ticket
- func (t *Ticket) ActorID() *ActorID
- func (t *Ticket) ActorIDBytes() []byte
- func (t *Ticket) ActorIDHex() string
- func (t *Ticket) After(other *Ticket) bool
- func (t *Ticket) Compare(other *Ticket) int
- func (t *Ticket) Delimiter() uint32
- func (t *Ticket) Key() string
- func (t *Ticket) Lamport() int64
- func (t *Ticket) SetActorID(actorID *ActorID) *Ticket
- func (t *Ticket) ToTestString() string
Constants ¶
const ( // MaxLamport is the maximum value stored in lamport. MaxLamport = math.MaxInt64 // MaxDelimiter is the maximum value stored in delimiter. MaxDelimiter = math.MaxUint32 )
Variables ¶
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") )
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, ) )
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
ActorIDFromBytes returns the bytes represented by the bytes of decoded hexadecimal string itself.
func ActorIDFromHex ¶
ActorIDFromHex returns the bytes represented by the hexadecimal string str.
func (*ActorID) Bytes ¶ added in v0.1.2
Bytes returns the bytes of ActorID itself. If the receiver is nil, it would return empty array of byte.
func (*ActorID) Compare ¶
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
MarshalJSON ensures that when calling json.Marshal(), it is marshaled including private field.
func (*ActorID) 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
UnmarshalJSON ensures that when calling json.Unmarshal(), it is unmarshalled including private field.
type Ticket ¶
type Ticket struct {
// contains filtered or unexported fields
}
Ticket is a timestamp of the logical clock. Ticket is immutable. It is created by change.ID.
func (*Ticket) ActorIDBytes ¶ added in v0.1.2
ActorIDBytes returns the actorID's bytes value.
func (*Ticket) ActorIDHex ¶
ActorIDHex returns the actorID's hex value.
func (*Ticket) Compare ¶
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) SetActorID ¶
SetActorID creates a new instance of Ticket with the given actorID.
func (*Ticket) ToTestString ¶ added in v0.4.8
ToTestString returns a string containing the metadata of the ticket for debugging purpose.