Constructor
new HashSet(initialCapacityopt)
- Implements:
Example
const set = new Collections.HashSet();
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
initialCapacity |
number |
<optional> |
13
|
The initial size of the hashset |
Methods
add(element) → {Set}
- Implements:
Adds an element to the set if already in set
Example
set.add(1);
set.add(2);
set.add(1);
// set contains [1, 2] order might not be guareenteed
Parameters:
Name | Type | Description |
---|---|---|
element |
* | The element to add to the set |
Returns:
The instance that this method was called
- Type
- Set
cardinality()
- Implements:
Returns the number of elements in the set
Example
set.add(1);
set.add(2);
set.cardinality() ; // 2
diff(thatSet) → {Array}
- Implements:
Returns the set difference (not symmetric) of 'this' set and
another set x such that x is in A and x is not in B, where A and B
are two sets
Example
set.add(1);
set.add(2);
set2 = new <Another Set>
set2.add(2);
set.diff(set2); // [1]
Parameters:
Name | Type | Description |
---|---|---|
thatSet |
Set | another set instance |
Returns:
The difference of this and @param thatSet
- Type
- Array
entries() → {Array}
- Implements:
Returns all elements in the set
Returns:
Array with all elements in the set
- Type
- Array
has(element) → {boolean}
- Implements:
Reports whether the set contains a given value
Example
set.add(1);
set.add(2);
set.has(3); // false
Parameters:
Name | Type | Description |
---|---|---|
element |
* | The element to find |
Returns:
True if set contains @param element and false otherwise
- Type
- boolean
intersect(thatSet, thatSet) → {Array}
- Implements:
Returns the mathematical set intersection of 'this' set and
another set
Example
set.add(1);
set.add(2);
set2 = new Collections.HashSet();
set2.add(2);
set.intersect(set2); // [2]
Parameters:
Name | Type | Description |
---|---|---|
thatSet |
Set | another Set instance |
thatSet |
Returns:
The array containing the set intersection of this and
- Type
- Array
remove() → {Set}
- Implements:
Removes an element from the set
Returns:
the instance that this method was called
- Type
- Set
union(thatSet) → {Array}
- Implements:
Returns the mathematical set union of 'this' set and
another set
Example
set.add(1);
set.add(2);
set2 = new <Another Set>
set2.add(2);
set.union(set2); // [1, 2]
Parameters:
Name | Type | Description |
---|---|---|
thatSet |
Set | another set instance |
Returns:
An array containing the union of this and @param thatSet
- Type
- Array