Object buckets.Set
A set is a data structure that contains no duplicate items.
If the inserted elements are custom objects, a function that converts elements to unique strings must be provided at construction time.
Example:
function petToString(pet) { return pet.type + ' ' + pet.name; }
Constructor Name and Description |
---|
buckets.Set(toStringFunction)
Creates an empty set.
|
Method Name and Description |
---|
buckets.Set.add(element)
Adds the specified element to the set if it's not already present.
|
buckets.Set.clear()
Removes all the elements from the set.
|
buckets.Set.contains(element)
Returns true if the set contains the specified element.
|
buckets.Set.difference(otherSet)
Performs a difference between this and another set.
|
buckets.Set.equals(other)
Returns true if the set is equal to another set.
|
buckets.Set.forEach(callback)
Executes the provided function once per element
present in the set.
|
buckets.Set.intersection(otherSet)
Performs an intersection between this and another set.
|
buckets.Set.isEmpty()
Returns true if the set contains no elements.
|
buckets.Set.isSubsetOf(otherSet)
Checks whether the given set contains all the elements of this set.
|
buckets.Set.remove(element)
Removes the specified element from the set.
|
buckets.Set.size()
Returns the number of elements in the set.
|
buckets.Set.toArray()
Returns an array containing all the elements in the set in no particular order.
|
buckets.Set.union(otherSet)
Performs a union between this and another set.
|
Object Detail
buckets.Set(toStringFunction)
Creates an empty set.
- Parameters:
- {function(Object):string=} toStringFunction
- Optional function used to convert elements to unique strings. If the elements aren't strings or if toString() is not appropriate, a custom function which receives an object and returns a unique string must be provided.
Method Detail
<static>
{boolean}
buckets.Set.add(element)
Adds the specified element to the set if it's not already present.
- Parameters:
- {Object} element
- The element to insert.
- Returns:
- {boolean} True if the set did not already contain the specified element.
<static>
buckets.Set.clear()
Removes all the elements from the set.
<static>
{boolean}
buckets.Set.contains(element)
Returns true if the set contains the specified element.
- Parameters:
- {Object} element
- Element to search for.
- Returns:
- {boolean} True if the set contains the specified element, false otherwise.
<static>
buckets.Set.difference(otherSet)
Performs a difference between this and another set.
Removes all the values that are present in the given set from this set.
- Parameters:
- {buckets.Set} otherSet
- other set.
<static>
{boolean}
buckets.Set.equals(other)
Returns true if the set is equal to another set.
Two sets are equal if they have the same elements.
- Parameters:
- {buckets.Set} other
- The other set.
- Returns:
- {boolean} True if the set is equal to the given set.
<static>
buckets.Set.forEach(callback)
Executes the provided function once per element
present in the set.
- Parameters:
- {function(Object):*} callback
- Function to execute, it's invoked an element as argument. To break the iteration you can optionally return false inside the callback.
<static>
buckets.Set.intersection(otherSet)
Performs an intersection between this and another set.
Removes all values that are not present in this set and the given set.
- Parameters:
- {buckets.Set} otherSet
- Other set.
<static>
{boolean}
buckets.Set.isEmpty()
Returns true if the set contains no elements.
- Returns:
- {boolean} True if the set contains no elements.
<static>
{boolean}
buckets.Set.isSubsetOf(otherSet)
Checks whether the given set contains all the elements of this set.
- Parameters:
- {buckets.Set} otherSet
- Other set.
- Returns:
- {boolean} True if this set is a subset of the given set.
<static>
{boolean}
buckets.Set.remove(element)
Removes the specified element from the set.
- Parameters:
- element
- Returns:
- {boolean} True if the set contained the specified element, false otherwise.
<static>
{number}
buckets.Set.size()
Returns the number of elements in the set.
- Returns:
- {number} The number of elements in the set.
<static>
{Array}
buckets.Set.toArray()
Returns an array containing all the elements in the set in no particular order.
- Returns:
- {Array} An array containing all the elements in the set.
<static>
buckets.Set.union(otherSet)
Performs a union between this and another set.
Adds all values from the given set to this set.
- Parameters:
- {buckets.Set} otherSet
- Other set.