Optional
capacity: numberthe capacity of the list; default is 3000
Private
capacity_capacity of the list, maximum size
Private
cycles_number of times the list has been overwritten
Private
lastpointer to newest entry: index of last entry written to list or -1 if never written.
Private
lastlast value written to memory list
Private
nextpointer to next entry in list; oldest entry if list has wrapped around.
Private
size_number of items now in memory list <= capacity
Private
values_values stored
Returns the index of the ending value in this HistoryList. The ending value is the newest value in this HistoryList.
the index of the ending value in this HistoryList, or –1 if nothing has been stored
when the index number exceeds the maximum representable integer
Returns a HistoryIterator which begins at the given index in this HistoryList.
Optional
index: numberthe index to start the iterator at; if undefined or –1, then starts at beginning of this HistoryList
a HistoryIterator which begins at the given index in this HistoryList.
Converts an index (which includes cycles) into a pointer. Pointer and index are the same until the list fills and 'wraps around'.
the index number, which can be larger than the size of the list
the pointer to the corresponding point in the list
Converts a pointer into the list to an index number that includes cycles. Pointer and index are the same until the list fills and 'wraps around'.
an index from 0 to size
the index number of this point including cycles
when the index number exceeds the maximum representable integer
Stores the given value into this HistoryList.
the value to store
index within HistoryList where the value was stored
when the index number exceeds the maximum representable integer
Generated using TypeDoc
A circular list of values, where the next value added overwrites the oldest value. The list is filled in until full, then it overwrites earlier entries in the list.
How CircularList Works
This section describes how the class works internally. This information is not needed for using this class.
Index Numbers, Pointers, and Overflow
Each value added has an index number which starts at zero and increases by one with each new value. The index number keeps increasing even when the list has 'wrapped around' and starts overwriting earlier entries.
Internally we use the term 'pointer' to mean a number in the range from 0 to the list capacity which 'points at' a particular list entry. The pointer and index are related and we can convert between them with the functions pointerToIndex and indexToPointer. The relation between pointer and index is:
The index number can have a maximum value of 2^53. When the index number exceeds this maximum, an exception is thrown by methods that calculate the current index number. Because index numbers are visible outside of this class we cannot just reset the index number.
This 2^53 maximum value should be enough capacity for most uses of CircularList. If you add 1000 points per second, it would take 37 million years to run out of capacity.
It might be possible to add a method that the caller can use to reset the index numbers to start at or near zero again, preserving the data in the CircularList and changing the index number associated with each value. Or the caller can simply make a new CircularList when catching the exception.
Example Scenario
We write new entries into the arrays
memX
andmemY
until they fill. Then we wrap around and start writing to the beginning again.