A data structure that keeps a list of objects, timestamped at the time they were added
to the buffer. Objects that have lived in the buffer for a specified amount of time
will be efficiently removed.
TimeBuffer does not remove old elements automatically; they are removed when new entries
are push()'d to the buffer, or when pruneOldEntries() is called.
protected var _array:Array
empty:Boolean [read-only]
Returns true if the TimeBuffer contains 0 elements.
Implementation
public function get empty():Boolean
protected var _firstIndex:uint
protected var _length:uint
length:uint [read-only]
Returns the number of elements currently stored in the TimeBuffer.
Implementation
public function get length():uint
protected var _maxAge:int
maxAge:int [write-only]
Sets the maximum age of items in the buffer, in milliseconds.
Whenever new items are added, items older than the maxAge will be removed.
Implementation
public function set maxAge(value:int):void
protected var _timerFn:Function
public function TimeBuffer(maxAge:int = 0, initialCapacity:int = 10, timerFn:Function = null)
Constructs a new TimeBuffer.
Parameters
| maxAge:int (default = 0) — the time, in milliseconds, that an entry can live in the TimeBuffer before
being removed. If maxAge <= 0, elements will never be removed. Defaults to 0.
|
| |
| initialCapacity:int (default = 10) |
| |
| timerFn:Function (default = null) |
public function at(index:uint):*
Returns the element at the specified index,
or undefined if index is out of bounds.
Parameters
Returns
public function clear():void Removes all elements from the TimeBuffer.
protected function entryAt(index:uint):EntryParameters
Returns
public function every(callback:Function):Boolean
Executes a test function on each item in the ring buffer
until an item is reached that returns false for the specified
function.
function test (data : timestamp :int) :Boolean
Returns a Boolean value of true if all items in the buffer return
true for the specified function; otherwise, false.
Parameters
Returns
public function forEach(callback:Function):void
Executes a function on each item in the buffer.
function callback (data : timestamp :int) :void
Parameters
public function indexOf(searchElement:*, fromIndex:int = 0):int
Searches for an item in the ring buffer by using strict equality
(===) and returns the index position of the item, or -1
if the item is not found.
Parameters
| searchElement:* |
| |
| fromIndex:int (default = 0) |
Returns
public function pop():*
Removes the last element from the TimeBuffer and returns it.
If the TimeBuffer is empty, pop() will return undefined.
Returns
public function pruneOldEntries(minTimestamp:int):void
Removes all entries whose age is < minTimestamp from the TimeBuffer.
Parameters
public function push(... args):uint
Adds the specified elements to the back of the TimeBuffer.
Returns the new length of the TimeBuffer.
Parameters
Returns
protected function setCapacity(newCapacity:uint):voidParameters
public function shift():*
Removes the first element from the TimeBuffer and returns it.
If the TimeBuffer is empty, shift() will return undefined.
Returns
public function timestampAt(index:uint):int
Returns the timestamp of the element at the specified index,
or -1 if index is out of bounds.
Parameters
Returns
Copyright © 2007-2009 Three Rings Design, Inc.