# References

## Clock

`RecordedArrays.AbstractClock`

— Type`AbstractClock{T<:Real}`

Supertype of clocks with time of type `T`

.

`RecordedArrays.DiscreteClock`

— Type```
DiscreteClock([start], timelist)
DiscreteClock(stop)
```

Clock for discrete-time process, time of which muse be increased with given step and can't be updated manually. The `timelist`

must be a non-empty and monotonically increasing `AbstractVector`

. If the `start`

is not specified, the first item of `timelist`

will be deleted and set as `start`

. During iteration, the current time will be updated automatically and returned as iteration item. When the iteration finished without `break`

, `init!`

will be applied. `DiscreteClock(stop)`

will create a clock with `start=0`

and `timelist=Base.OneTo(stop)`

**Examples**

```
julia> c = DiscreteClock(0:3);
julia> currenttime(c)
0
julia> [(t, currenttime(c)) for t in c]
3-element Vector{Tuple{Int64, Int64}}:
(1, 1)
(2, 2)
(3, 3)
julia> currenttime(c)
0
julia> c = DiscreteClock(3); # similar to DiscreteClock(0:3)
julia> (currenttime(c), collect(c))
(0, [1, 2, 3])
```

`RecordedArrays.ContinuousClock`

— Type```
ContinuousClock{T, I<:Union{Nothing, DiscreteClock}} <: AbstractClock{T}
ContinuousClock(stop, [start=zero(stop)]; [max_epoch=nothing])
```

A clock for continuous-time process. Unlike the `DiscreteClock`

, during iteration, the current time will not be update automatically, but update by `increase!`

manually. Besides the epoch of current iteration instead of current time will be returned. If the `max_epoch`

is specified, the iteration will break when epoch reach to the `max_epoch`

, even `currenttime(c) < limit(c)`

, and break in this way the `init!(c)`

will not be applied.

**Examples**

```
julia> c = ContinuousClock(3.0; max_epoch=2);
julia> for epoch in c
increase!(c, 1)
println(currenttime(c), ' ', epoch)
end
1.0 1
2.0 2
julia> for epoch in c
increase!(c, 1)
println(currenttime(c), ' ', epoch)
end
3.0 1
julia> for epoch in c
increase!(c, 1)
println(currenttime(c), ' ', epoch)
end
1.0 1
2.0 2
```

`RecordedArrays.currenttime`

— Function`currenttime(c::AbstractClock)`

Return current time of clock `c`

.

`RecordedArrays.limit`

— Function`limit(c::AbstractClock)`

Return the limit of clock `c`

. For a ContinuousClock `c`

, the max time might larger than `limit(c)`

.

`RecordedArrays.start`

— Function`start(c::AbstractClock)`

Return the start time of clock `c`

.

`RecordedArrays.init!`

— Function`init!(c::AbstractClock)`

Update current time to start time.

`RecordedArrays.increase!`

— Function`increase!(c::ContinuousClock, t::Real)`

Update current time of clock `c`

to `currenttime(c) + t`

.

## Entries

`RecordedArrays.AbstractEntry`

— Type`AbstractEntry{V,T<:Real}`

Supertype of all entry types, which store changes of a specified variable of type `V`

with timestamps of type `T`

.

`RecordedArrays.StaticEntry`

— Type`StaticEntry{V,T} <: AbstractEntry{V,T}`

Entry type to store changing history of a variable whose value not changing overtime.

`RecordedArrays.DynamicEntry`

— Type`DynamicEntry{V,T} <: AbstractEntry{V,T}`

Entry type to store changing history of a variable whose value changing overtime.

`RecordedArrays.getts`

— Function`getts(e::AbstractEntry{V,T}) -> Vector{T}`

Get timestamps of an entry `e`

.

`RecordedArrays.getvs`

— Function`getvs(e::AbstractEntry{V,T}) -> Vector{V}`

Get values at each timestamp of an entry `e`

.

`RecordedArrays.tspan`

— Function`tspan(e::AbstractEntry{V,T}) -> T`

Get last time of an entry `e`

.

`RecordedArrays.gettime`

— Function```
gettime([alg::AbstractSearch], e::AbstractEntry, t::Real)
gettime([alg::AbstractSearch], e::AbstractEntry, ts)
gettime([alg::AbstractSearch], es::AbstractArray{<:AbstractEntry}, t::Real)
gettime([alg::AbstractSearch], es::AbstractArray{<:AbstractEntry}, ts)
```

Get the value of `e`

at `t::Real`

or values at each time `t`

in an iterate `ts`

. If `t`

is not a timestamp in `getts(e)`

, return value at time `getts(e)[i]`

where `getts(e)[i] < t < getts(e)[i+1]`

. The `alg`

is a search algorithm that finds the index `i`

of a target time `t`

, which can be `LinearSearch`

or `BinarySearch`

(by default). For `es`

, an array of entries, return values at `t`

as a similar array.

`ts`

must be monotonically increasing.

`RecordedArrays.store!`

— Function`store!(e::AbstractEntry, v, t::Union{Real,AbstractClock})`

Store a entry with value `v`

at time `t`

.

`RecordedArrays.del!`

— Function`del!(e::AbstractEntry, t::Union{Real,AbstractClock})`

Marks a entry `e`

deleted at time `t`

. If an AbstractClock `c`

is given, `t = currenttime(c)`

.

## Recorded Types

`RecordedArrays.AbstractRecArray`

— Type`AbstractRecArray{T,N}`

Supertype of recorded `N`

-dimensional arrays with elements of type `T`

, whose changes will be recorded automatically.

Avoid to mutate recorded arrays out of loop, because clocks will initial automatically during loop.

`RecordedArrays.RecordedNumber`

— Type`RecordedNumber{T}`

A `Union`

of recorded numbers with type `T`

.

`RecordedNumber{S} <: T`

will always return `false`

where `T`

is a subtype of `Number`

, even if `S <: T`

. There is a function `issubtype(RecordedNumber{S}, T)`

which would return `true`

if `S <: T`

. Besides, `isnum(T, n::RecordedNumber{S})`

would return `true`

if `S <: T`

.

Store a value `v`

to an `RecordedNumber`

`x`

by `x[] = v`

or `x[1] = v`

instead of `x = v`

.

`RecordedArrays.recorded`

— Function`recorded(E, c::AbstractClock, A)`

Create a recorded array (or number) with entry of type `E`

and clock `c`

.

`RecordedArrays.state`

— Function```
state(A::AbstractRecArray{T,N}) -> Array{T,N}
state(x::RecordedNumber{T}) -> T
```

Get current state of a recorded array `A`

or a recorded number `x`

.

`state`

for `AbstractRecArray{V,T,N}`

where `N >= 2`

may be unsafe because of `unsafe_wrap`

and `unsafe_convert`

.

`RecordedArrays.getentries`

— Function`getentries(x::RecordedNumber)`

Get entries of a recorded number `x`

.

`getentries(A::AbstractRecArray)`

Get entries of a recorded array `A`

.

`RecordedArrays.issubtype`

— Function`issubtype(S, T) -> Bool`

Similar to `S <: T`

, but for a `S`

where `S <: RecordedNumber{P}`

, return `true`

if `P <: T`

.

`RecordedArrays.isnum`

— Function`isnum(T, x) -> Bool`

Similar to `x is T`

, but for `x`

where `x::RecordedNumber{S}`

, return `true`

if `S <:T`

.

## Utilities

`RecordedArrays.MCIndices`

— Type```
MCIndices(sz::NTuple{N,AbstractVector{Int}}) -> R
MCIndices(A::AbstractArray) -> R
```

A `CartesianIndices`

like type defines mutable and disconnected region `R`

.

**Examples**

```
julia> im = MCIndices(([1, 3], [2, 4]))
2×2 MCIndices{2}:
(1, 2) (1, 4)
(3, 2) (3, 4)
julia> im[1]
(1, 2)
julia> im[1, 2]
(1, 4)
```

`RecordedArrays.DOKSparseArray`

— Type`DOKSparseArray{T,N}`

A simple sparse array type storing as `DOK`

format.