vrtime

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: MIT Imports: 2 Imported by: 5

Documentation

Overview

Package vrtime defines and manages virtual time inside a simulator. Time is tracked as an integral number of ticks since the epoch, along with a secondary sort value to provide for deterministic order among simultaneous events.

Index

Constants

This section is empty.

Variables

View Source
var FloatTicksPerSecond float64 = float64(TicksPerSecond)

FloatTicksPerSecond gives a float64 representation of the size of number of ticks a second has

View Source
var NanoSecPerTick int64 = int64((float64(1e9)) * SecondPerTick)

NanoSecPerTick gives a float64 representation of the tick size in nanoseconds

View Source
var SecondPerTick float64 = 1e-10

SecondPerTick gives a float64 representation of the tick size in seconds. Default 0.1 ns

TickValue gives the size of a tick, in seconds

View Source
var TicksPerSecond int64 = int64(1.0 / SecondPerTick)

TicksPerSecond specifies the frequency of the ticker. Default is 1e9.

Functions

func MuSecondsToTicks

func MuSecondsToTicks(v float64) int64

MuSecondsToTicks converts a fractional number of micro-seconds into a whole number of ticks.

func SecondsToTicks

func SecondsToTicks(v float64) int64

SecondsToTicks converts a fractional number of seconds into a whole number of ticks.

func SetTicksPerSecond

func SetTicksPerSecond(tps int64) bool

SetTicksPerSecond changes the value of TicksPerSecond (the frequency of the ticker) and the associated values [FloatTicksPersecond] and TickValue. the frequency of the ticker. The default value is 1e7.

func TicksToSeconds

func TicksToSeconds(ticks int64) float64

TicksToSeconds converts a whole number of ticks into a fractional number of seconds.

func TimeToSeconds

func TimeToSeconds(t Time) float64

TimeToSeconds converts a Time value into a fractional number of seconds. The Priority field is ignored.

Types

type Time

type Time struct {
	TickCnt  int64
	Priority int64
}

Time measures the number of ticks since the epoch (in TickCnt). The tick count provides a natural ordering of time values -- smaller numbers happen earlier than larger numbers. In order to provide determinism, the order in which simultaneous events occur is specified by Priority -- among simultaneous events, smaller numbers for Priority occur before larger numbers.

func CreateTime

func CreateTime(ticks, priority int64) Time

CreateTime creates a Time object.

func InfinityTime

func InfinityTime() Time

InfinityTime marks the end of time. Every other time in a running simulation is less than InfinityTime

func SecondsToTime

func SecondsToTime(v float64) Time

SecondsToTime converts a fractional number of seconds into an equivalent Time value. The returned Priority is 0.

func SecondsToTimePri added in v0.1.5

func SecondsToTimePri(v float64, pri int64) Time

SecondsToTime converts a fractional number of seconds into an equivalent Time value. The returned Priority is 0.

func ZeroTime

func ZeroTime() Time

ZeroTime returns a Time structure with value zero in both keys

func (Time) EQ

func (t Time) EQ(t1 Time) bool

EQ returns true iff the receiver Time is equal to the argument Time. Both ticks and priority have to be the same for true to be returned

func (Time) GE

func (t Time) GE(t1 Time) bool

GE returns true iff the receiver Time is greater than or equal to the argument Time.

func (Time) GT

func (t Time) GT(t1 Time) bool

GT returns true iff the receiver Time is greater than the argument Time

func (Time) LE

func (t Time) LE(t1 Time) bool

LE returns true iff the receiver Time is less than or equal to the argument Time.

func (Time) LT

func (t Time) LT(t1 Time) bool

LT returns true iff the receiver Time is less than the argument Time

func (Time) NEQ

func (t Time) NEQ(t1 Time) bool

NEQ returns true iff the receiver time is not equal to the argument Time. Like all of the Time comparison functions, both the Ticks and the Priority are used.

func (Time) Plus

func (t Time) Plus(a Time) Time

func (*Time) Pri

func (t *Time) Pri() int64

Pri returns the priority of an event, which plays a role in ordering when two events have the same primary key value. Events with lower priority number are ordered to appear before events with higher priority numbers

func (Time) Seconds

func (t Time) Seconds() float64

Ticks returns the float64 respresentation of the primary key of a Time data structure, usually used to describe a length of time (e.g. between events)

func (*Time) SecondsStr

func (t *Time) SecondsStr() string

SecondsStr returns a human-readble representation of a Time. The time is represented as fractional seconds rather than ticks.

func (*Time) SetPri

func (t *Time) SetPri(p int64)

SetPri sets the priority of an event. N.b. this does not modify the Ticks

func (*Time) SetTicks

func (t *Time) SetTicks(v int64)

SetTicks sets the time associated with an event. N.b.: this does not modify the Priority.

func (Time) Ticks

func (t Time) Ticks() int64

Ticks returns the primary key of a Time data structure, usually used to describe a length of time (e.g. between events)

func (*Time) TimeStr

func (t *Time) TimeStr() string

TimeStr provides a human-readable version of Time, including both Ticks and Priority.

Jump to

Keyboard shortcuts

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