Class buckets.Set
A set is a data structure that contains no duplicate items.
If the inserted elements are custom objects a function which converts elements to strings must be provided. Example:
function petToString(pet) { return pet.name; }
Defined in: <../buckets.js>.
Constructor Attributes | Constructor Name and Description |
---|---|
buckets.Set(toStringFunction)
Creates an empty set.
|
Method Attributes | Method Name and Description |
---|---|
add(element)
Adds the specified element to this set if it is not already present.
|
|
clear()
Removes all of the elements from this set.
|
|
contains(element)
Returns true if this set contains the specified element.
|
|
difference(otherSet)
Performs a difference between this an another set.
|
|
forEach(callback)
Executes the provided function once for each element
present in this set.
|
|
intersection(otherSet)
Performs an intersecion between this an another set.
|
|
isEmpty()
Returns true if this set contains no elements.
|
|
isSubsetOf(otherSet)
Checks whether the given set contains all the elements in this set.
|
|
remove(element)
Removes the specified element from this set if it is present.
|
|
size()
Returns the number of elements in this set.
|
|
toArray()
Returns an array containing all of the elements in this set in arbitrary order.
|
|
union(otherSet)
Performs a union between this an another set.
|
Class Detail
buckets.Set(toStringFunction)
Creates an empty set.
- Parameters:
- {function(Object):string=} toStringFunction
- optional function used to convert elements to strings. If the elements aren't strings or if toString() is not appropriate, a custom function which receives a onject and returns a unique string must be provided.
Method Detail
{boolean}
add(element)
Adds the specified element to this set if it is not already present.
- Parameters:
- {Object} element
- the element to insert.
- Returns:
- {boolean} true if this set did not already contain the specified element.
clear()
Removes all of the elements from this set.
{boolean}
contains(element)
Returns true if this set contains the specified element.
- Parameters:
- {Object} element
- element to search for.
- Returns:
- {boolean} true if this set contains the specified element, false otherwise.
difference(otherSet)
Performs a difference between this an another set.
Removes from this set all the values that are present in the given set.
- Parameters:
- {buckets.Set} otherSet
- other set.
forEach(callback)
Executes the provided function once for each element
present in this set.
- Parameters:
- {function(Object):*} callback
- function to execute, it is invoked with one arguments: the element. To break the iteration you can optionally return false.
intersection(otherSet)
Performs an intersecion between this an another set.
Removes all values that are not present this set and the given set.
- Parameters:
- {buckets.Set} otherSet
- other set.
{boolean}
isEmpty()
Returns true if this set contains no elements.
- Returns:
- {boolean} true if this set contains no elements.
{boolean}
isSubsetOf(otherSet)
Checks whether the given set contains all the elements in this set.
- Parameters:
- {buckets.Set} otherSet
- other set.
- Returns:
- {boolean} true if this set is a subset of the given set.
{boolean}
remove(element)
Removes the specified element from this set if it is present.
- Parameters:
- element
- Returns:
- {boolean} true if this set contained the specified element.
{number}
size()
Returns the number of elements in this set.
- Returns:
- {number} the number of elements in this set.
{Array}
toArray()
Returns an array containing all of the elements in this set in arbitrary order.
- Returns:
- {Array} an array containing all of the elements in this set.
union(otherSet)
Performs a union between this an another set.
Adds all values from the given set to this set.
- Parameters:
- {buckets.Set} otherSet
- other set.