My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
OQueue  
Overview of OQueue
Updated May 14, 2010 by matr...@mac.com

OQueue

Maintains a collection of objects in a particular order, and provides methods to add to the end, and pull from the beginning. OQueues are FIFO (First in, first out) data structures.

// make a new queue
var queue = new OQueue();

// add some items
queue.push(1);
queue.push(2);
queue.push(3);

// queue.length == 3

alert(queue.pop());
// alerts "1"
// queue.length == 2

alert(queue.pop());
// alerts "2"
// queue.length == 1

alert(queue.pop());
// alerts "3"
// queue.length == 0

Methods

push

Adds an item to the end of the queue. Returns the OQueue instance to allow chaining.

(OQueue) queue.push( item );

queue The variable which is an instance of an OQueue
item The item to add to the queue

Example

queue.push( item1 ).push( item2 );

pop

Removes the next item from the front of the queue.

(object) queue.push( item );

queue The variable which is an instance of an OQueue
item The item to add to the queue

Properties

length

Read only. Holds the current number of items in the queue.

optimiseSize

The number of redundant items that have been popped before the queue is optimised. Items in the queue are not deleted when popped to improve performance, has optimiseSize redundant items, they will be removed and the memory freed.

Getting the right balance

Usually this is half of the average number of items you expect. If it is too low, your OQueue will be optimising itself too much which will result in a performance hit, if it is too high your OQueue will never optimise itself.

Known subclasses


Sign in to add a comment
Powered by Google Project Hosting