Packagecom.threerings.util
Classpublic class TimeBuffer

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.



Public Properties
 PropertyDefined by
  empty : Boolean
[read-only] Returns true if the TimeBuffer contains 0 elements.
TimeBuffer
  length : uint
[read-only] Returns the number of elements currently stored in the TimeBuffer.
TimeBuffer
  maxAge : int
[write-only] Sets the maximum age of items in the buffer, in milliseconds.
TimeBuffer
Protected Properties
 PropertyDefined by
  _array : Array
TimeBuffer
  _firstIndex : uint
TimeBuffer
  _length : uint
TimeBuffer
  _maxAge : int
TimeBuffer
  _timerFn : Function
TimeBuffer
Public Methods
 MethodDefined by
  
TimeBuffer(maxAge:int = 0, initialCapacity:int = 10, timerFn:Function = null)
Constructs a new TimeBuffer.
TimeBuffer
  
at(index:uint):*
Returns the element at the specified index, or undefined if index is out of bounds.
TimeBuffer
  
clear():void
Removes all elements from the TimeBuffer.
TimeBuffer
  
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.
TimeBuffer
  
forEach(callback:Function):void
Executes a function on each item in the buffer.
TimeBuffer
  
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.
TimeBuffer
  
pop():*
Removes the last element from the TimeBuffer and returns it.
TimeBuffer
  
pruneOldEntries(minTimestamp:int):void
Removes all entries whose age is < minTimestamp from the TimeBuffer.
TimeBuffer
  
push(... args):uint
Adds the specified elements to the back of the TimeBuffer.
TimeBuffer
  
shift():*
Removes the first element from the TimeBuffer and returns it.
TimeBuffer
  
timestampAt(index:uint):int
Returns the timestamp of the element at the specified index, or -1 if index is out of bounds.
TimeBuffer
Protected Methods
 MethodDefined by
  
entryAt(index:uint):Entry
TimeBuffer
  
setCapacity(newCapacity:uint):void
TimeBuffer
Property detail
_arrayproperty
protected var _array:Array
emptyproperty 
empty:Boolean  [read-only]

Returns true if the TimeBuffer contains 0 elements.

Implementation
    public function get empty():Boolean
_firstIndexproperty 
protected var _firstIndex:uint
_lengthproperty 
protected var _length:uint
lengthproperty 
length:uint  [read-only]

Returns the number of elements currently stored in the TimeBuffer.

Implementation
    public function get length():uint
_maxAgeproperty 
protected var _maxAge:int
maxAgeproperty 
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
_timerFnproperty 
protected var _timerFn:Function
Constructor detail
TimeBuffer()constructor
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)
Method detail
at()method
public function at(index:uint):*

Returns the element at the specified index, or undefined if index is out of bounds.

Parameters
index:uint

Returns
*
clear()method 
public function clear():void

Removes all elements from the TimeBuffer.

entryAt()method 
protected function entryAt(index:uint):EntryParameters
index:uint

Returns
Entry
every()method 
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
callback:Function

Returns
Boolean
forEach()method 
public function forEach(callback:Function):void

Executes a function on each item in the buffer. function callback (data : timestamp :int) :void

Parameters
callback:Function
indexOf()method 
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
int
pop()method 
public function pop():*

Removes the last element from the TimeBuffer and returns it. If the TimeBuffer is empty, pop() will return undefined.

Returns
*
pruneOldEntries()method 
public function pruneOldEntries(minTimestamp:int):void

Removes all entries whose age is < minTimestamp from the TimeBuffer.

Parameters
minTimestamp:int
push()method 
public function push(... args):uint

Adds the specified elements to the back of the TimeBuffer. Returns the new length of the TimeBuffer.

Parameters
... args

Returns
uint
setCapacity()method 
protected function setCapacity(newCapacity:uint):voidParameters
newCapacity:uint
shift()method 
public function shift():*

Removes the first element from the TimeBuffer and returns it. If the TimeBuffer is empty, shift() will return undefined.

Returns
*
timestampAt()method 
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
index:uint

Returns
int