Constructor
new module:caplin/core/SlidingWindow(nSize)
Creates a SlidingWindow, which allows a maximum number of items to be stored.
Parameters:
Name | Type | Description |
---|---|---|
nSize |
Number | The maximum size of this window. This must be an integer larger than 0. |
Methods
-
clear()
-
Clears all items resets it.
-
forEach(func)
-
Iterates over each of the items in this window from oldest to newest.
Parameters:
Name Type Description func
function a function that will be called with each item. -
get(n) → {*}
-
Parameters:
Name Type Description n
Number the index of the item to be returned. Returns:
the nth oldest item that is stored or undefined if the index is larger than the number of items stored.- Type
- *
-
getSize()
-
Returns:
the number of items in this window. -
newest() → {*}
-
Returns:
the item most recently added into this SlidingWindow, or null if no items have been added.- Type
- *
-
oldest() → {*}
-
Returns:
the oldest item that is still in this SlidingWindow or null if no items have been added.- Type
- *
-
push(oObject)
-
Adds an item into the end of this sliding window, possibly pushing an item out of the window in the process.
Parameters:
Name Type Description oObject
Object an item to add into this window. Returns:
the item that was pushed out of the window or null if the window is not full. -
setSize(nNewSize)
-
Changes the size of a SlidingWindow. This operation should not be expected to be performant; do not do it often. If the new size is smaller than the number of items in this window, this operation may cause some objects to be pushed out of the window.
Parameters:
Name Type Description nNewSize
Number the new size the window should take up. Must be a positive integer. -
toString() → {String}
-
Returns:
Returns a string representation of this SlidingWindow. This is intended to be human readable for debugging and may change.- Type
- String