class SAPO.Utility.Set
Implements a set. Any item in the set must an Object! The low level implementation uses an hash table. Hash codes are extracted from objects using obj.toString(), so override toString to enhance your hash table results :)
Authors:
jose.p.dias AT co.sapo.pt
Since:
December 2011
Defined in Utility/Set/0.1/lib.js

Constructor Summary
Set ([Object[] items], [boolean cacheHash])

Function Summary
boolean add (Object item)
adds given element to the set if not already there, otherwise does nothing
addSeveral (Object[] items)
adds items to the set
clear()
removes all items from the set
returns a clone of the set
contains (Object item)
returns true iif item in set
boolean containsAny (Object items)
returns true iif any of the given items is in the set
boolean containsSeveral (Object items)
returns true iif all given items are in the set
boolean equals()
returns equals iif items of both are the same
forEach (Function supports)
applies a function to all
Object[] getItems()
returns an array with all items which are in the set
Number getLength()
returns the number of items in the set
SAPO.Utility.Set|Object[] intersect (SAPO.Utility.Set setB, [boolean asArray])
returns a set/array with the intersection of both sets
Boolean isEmpty()
returns true iif set is empty
boolean remove (Object item)
removes given element from the set if already there, otherwise does nothing
removeSeveral (Object[] items)
removes items from the set
SAPO.Utility.Set|Object[] subtract (SAPO.Utility.Set setB, [boolean asArray])
returns a set/array with the subtraction of setA - setB
SAPO.Utility.Set|Object[] union (SAPO.Utility.Set setB, [boolean asArray])
returns a set/array with the union of setA with setB

Constructor Details

constructor Set

Set([Object[] items], [boolean cacheHash])
Parameters:
[items] - initial items to add to the set
[cacheHash] - if true, objects' hash codes are stored in obj._hashCode

Function Details

function add

boolean add(Object item)
adds given element to the set if not already there, otherwise does nothing
Parameters:
item - item to add
Returns:
true iif item has been added

function addSeveral

addSeveral(Object[] items)
adds items to the set
Parameters:
items - items to add to the set (calls add recursively)

function clear

clear()
removes all items from the set

function clone

SAPO.Utility.Set clone()
returns a clone of the set
Returns:
clone of the set

function contains

contains(Object item)
returns true iif item in set
Parameters:
item - item to look for

function containsAny

boolean containsAny(Object items)
returns true iif any of the given items is in the set
Parameters:
items - items to look for

function containsSeveral

boolean containsSeveral(Object items)
returns true iif all given items are in the set
Parameters:
items - items to look for

function equals

boolean equals()
returns equals iif items of both are the same

function forEach

forEach(Function supports)
applies a function to all
Parameters:
supports function with signature: fn(element, index)

function getItems

Object[] getItems()
returns an array with all items which are in the set
Returns:
array with all the items in the set

function getLength

Number getLength()
returns the number of items in the set
Returns:
number of items in the set

function intersect

SAPO.Utility.Set|Object[] intersect(SAPO.Utility.Set setB, [boolean asArray])
returns a set/array with the intersection of both sets
Parameters:
setB - one of the sets of the intersection
[asArray] - if trueish, returns array, otherwise returns set
Returns:
setA intersection setB

function isEmpty

Boolean isEmpty()
returns true iif set is empty

function remove

boolean remove(Object item)
removes given element from the set if already there, otherwise does nothing
Parameters:
item - item to remove
Returns:
true iif item has been removed

function removeSeveral

removeSeveral(Object[] items)
removes items from the set
Parameters:
items - items to remove from the set (calls remove recursively)

function subtract

SAPO.Utility.Set|Object[] subtract(SAPO.Utility.Set setB, [boolean asArray])
returns a set/array with the subtraction of setA - setB
Parameters:
setB - the reference set 2
[asArray] - if trueish, returns array, otherwise returns set
Returns:
setA - setB

function union

SAPO.Utility.Set|Object[] union(SAPO.Utility.Set setB, [boolean asArray])
returns a set/array with the union of setA with setB
Parameters:
setB - the reference set 2
[asArray] - if trueish, returns array, otherwise returns set
Returns:
setA union setB