Search Results for

    Show / Hide Table of Contents

    Class ValueHistory<T>

    Represents a variable of type T and its entire value history starting at some round.

    The history can be extended by adding records for later rounds or updating the value for the currently last round, but it cannot be changed for any round before the last round with a record unless it is cut off.

    The value in a round before the first recorded round is not defined.

    The history also provides a marker mechanism that allows the value history to be traversed in sequence. The marker starts at the initial round and tracks the latest round until it is set to some round using SetMarkerToRound(int) or moved by one step using StepBack() or StepForward(). It can be reset to track the last round using ContinueTracking().

    Inheritance
    object
    ValueHistory<T>
    ValueHistoryBondInfo
    ValueHistoryJointMovement
    ValueHistoryMessage
    ValueHistoryPinConfiguration
    Implements
    IReplayHistory
    Namespace: AS2.Sim
    Assembly: .dll
    Syntax
    public class ValueHistory<T> : IReplayHistory
    Type Parameters
    Name Description
    T

    The type of the represented variable. Must implement an equality check.

    Constructors

    | Edit this page View Source

    ValueHistory()

    Declaration
    protected ValueHistory()
    | Edit this page View Source

    ValueHistory(ValueHistorySaveData<T>)

    Instantiates a ValueHistory<T> from the given save data.

    The instance will start in the tracking state, following the latest recorded round.

    Declaration
    public ValueHistory(ValueHistorySaveData<T> data)
    Parameters
    Type Name Description
    ValueHistorySaveData<T> data

    A serializable object storing history data.

    | Edit this page View Source

    ValueHistory(T, int)

    Creates a new history for a variable of type T.

    Declaration
    public ValueHistory(T initialValue, int initialRound = 0)
    Parameters
    Type Name Description
    T initialValue

    The first recorded value of the variable.

    int initialRound

    The round in which this value is recorded.

    Fields

    | Edit this page View Source

    isTracking

    Indicates whether the marked round is currently tracking the last round.

    Declaration
    protected bool isTracking
    Field Value
    Type Description
    bool
    | Edit this page View Source

    lastRound

    The last round for which we have a recorded value.

    Declaration
    protected int lastRound
    Field Value
    Type Description
    int
    | Edit this page View Source

    markedIndex

    The record index corresponding to the currently marked round. Useful for fast lookup.

    Declaration
    protected int markedIndex
    Field Value
    Type Description
    int
    | Edit this page View Source

    markedRound

    The currently marked round.

    Declaration
    protected int markedRound
    Field Value
    Type Description
    int
    | Edit this page View Source

    rounds

    The history of rounds in which the recorded value has changed.

    Declaration
    protected List<int> rounds
    Field Value
    Type Description
    List<int>
    | Edit this page View Source

    values

    The history of values. If two consecutively recorded values are equal, the second value is not stored.

    Declaration
    protected List<T> values
    Field Value
    Type Description
    List<T>

    Methods

    | Edit this page View Source

    ContinueTracking()

    Resets the marker to continue tracking the last recorded round.

    Declaration
    public virtual void ContinueTracking()
    | Edit this page View Source

    CutOffAfterRound(int)

    Deletes all records after the specified round, turning this round into the last round if it is earlier than the current last round.

    Declaration
    public virtual void CutOffAfterRound(int round)
    Parameters
    Type Name Description
    int round

    The round after which all records should be removed.

    | Edit this page View Source

    CutOffAtMarker()

    Deletes all records after the currently marked round. If the marked round is earlier than the current last round, the marked round becomes the new last round.

    Declaration
    public virtual void CutOffAtMarker()
    | Edit this page View Source

    GenerateSaveData()

    Creates a serializable object storing the history data so that it can be saved to and loaded from a file.

    Declaration
    public virtual ValueHistorySaveData<T> GenerateSaveData()
    Returns
    Type Description
    ValueHistorySaveData<T>

    A serializable representation of the history data.

    | Edit this page View Source

    GenerateSaveDataString()

    Same as GenerateSaveData(), but all values are stored as strings.

    Declaration
    public ValueHistorySaveData<string> GenerateSaveDataString()
    Returns
    Type Description
    ValueHistorySaveData<string>

    A serializable representation of the history data, where the stored values are represented as strings.

    | Edit this page View Source

    GetFirstRecordedRound()

    Returns the first round in which a value was recorded. This is the round in which the history of this variable begins; its value is undefined in all previous rounds.

    See also GetLastRecordedRound().

    Declaration
    public virtual int GetFirstRecordedRound()
    Returns
    Type Description
    int

    The first round with a recorded value.

    | Edit this page View Source

    GetIndexOfRound(int)

    Finds the list index of the record that specifies the value in the given round. The round of that record is at most round and the next recorded round is greater than round, if it exists.

    Declaration
    private int GetIndexOfRound(int round)
    Parameters
    Type Name Description
    int round

    The round for which to find the corresponding index. Must be at least the first recorded round.

    Returns
    Type Description
    int

    The list index of the last record before round.

    | Edit this page View Source

    GetLastRecordedRound()

    Returns the last round in which a value was recorded. The history may only be updated for rounds greater than or equal to this round. Queries for rounds after this one will return the value that was recorded for this round.

    See also GetFirstRecordedRound().

    Declaration
    public virtual int GetLastRecordedRound()
    Returns
    Type Description
    int

    The last round with a recorded value.

    | Edit this page View Source

    GetMarkedRound()

    Returns the round that is currently marked.

    See SetMarkerToRound(int), StepBack(), StepForward().

    Declaration
    public virtual int GetMarkedRound()
    Returns
    Type Description
    int

    The currently marked round.

    | Edit this page View Source

    GetMarkedValue()

    Returns the value recorded for the currently marked round.

    Note that the returned value may still change if the marked round is greater than or equal to the last recorded round and the history is updated with new values.

    Declaration
    public virtual T GetMarkedValue()
    Returns
    Type Description
    T

    The recorded or predicted value for the currently marked round.

    | Edit this page View Source

    GetValueInRound(int)

    Returns the value the variable had in the specified round round.

    Declaration
    public virtual T GetValueInRound(int round)
    Parameters
    Type Name Description
    int round

    The round for which to query. Must be at least GetFirstRecordedRound().

    Returns
    Type Description
    T

    The value of the represented variable in round round.

    | Edit this page View Source

    IsTracking()

    Checks whether the round marker is currently tracking the latest round.

    Declaration
    public virtual bool IsTracking()
    Returns
    Type Description
    bool

    true if and only if the marker is tracking the latest round.

    | Edit this page View Source

    RecordValueAtMarker(T)

    Like RecordValueInRound(T, int) but the recorded round is the round that is currently marked.

    Declaration
    public virtual void RecordValueAtMarker(T value)
    Parameters
    Type Name Description
    T value

    The value to record in the currently marked round.

    | Edit this page View Source

    RecordValueInRound(T, int)

    Adds a value for the specified round to the variable record.

    The value is assumed to remain unchanged between the previously last round and round.

    Declaration
    public virtual void RecordValueInRound(T value, int round)
    Parameters
    Type Name Description
    T value

    The value to be recorded.

    int round

    The round for which the value should be recorded. Must be greater than or equal to the last recorded round.

    | Edit this page View Source

    SetMarkerToRound(int)

    Sets the marker to the specified round and stops it from tracking the latest round.

    Declaration
    public virtual void SetMarkerToRound(int round)
    Parameters
    Type Name Description
    int round

    The round to which the marker should be set. Must not be smaller than the first recorded round.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    Thrown if round is less than the first recorded round.

    | Edit this page View Source

    ShiftTimescale(int)

    Shifts all records as well as the marker by the specified amount of rounds.

    Declaration
    public virtual void ShiftTimescale(int amount)
    Parameters
    Type Name Description
    int amount

    The number of rounds to add to each entry. May be negative.

    | Edit this page View Source

    StepBack()

    Moves the marker one round back and stops it from tracking the last round.

    Must not be called when the marker is already at the first recorded round.

    Declaration
    public virtual void StepBack()
    Exceptions
    Type Condition
    InvalidOperationException

    Thrown when the marker is already at the first recorded round.

    | Edit this page View Source

    StepForward()

    Moves the marker one round forward and stops it from tracking the last round.

    Declaration
    public virtual void StepForward()
    | Edit this page View Source

    ValuesEqual(T, T)

    Equality comparison method for values of the parameter type T. Can be overridden by inheriting classes to define specialized behavior for specific types.

    Default implementation uses System.Collections.Generic.EqualityComparer<T>.Default for comparison.

    Declaration
    protected virtual bool ValuesEqual(T val1, T val2)
    Parameters
    Type Name Description
    T val1

    The first value to compare.

    T val2

    The second value to compare.

    Returns
    Type Description
    bool

    true if and only if val1 and val2 are equal in the sense that it is not necessary to create a new history entry.

    Operators

    | Edit this page View Source

    implicit operator T(ValueHistory<T>)

    Implicit conversion that returns the currently marked value

    Declaration
    public static implicit operator T(ValueHistory<T> history)
    Parameters
    Type Name Description
    ValueHistory<T> history

    The history whose marked value to return.

    Returns
    Type Description
    T

    Implements

    IReplayHistory
    • Edit this page
    • View Source
    In this article
    Back to top AmoebotSim 2.0 Documentation v1.11
    Copyright © 2025 AmoebotSim 2.0 Authors
    Generated by DocFX