class HashSet<V is CanHash and CanEqual<V>>
Class HashSet<V>
stores a set, a collection of objects of type V
with no repetitions. Internally, this set is implemented with a hash table mapping objects of type V
to themselves. This implementation allows objects to be added, found, and deleted in constant or near-constant time. HashSet<V>
requires that type V
has the CanHash
interface but imposes no ordering requirement on objects. The TreeSet<V>
class should be considered if object ordering is a requirement.
Modifiers | Return Types | Method and Description |
---|---|---|
public |
() |
create() Creates an empty |
public |
() |
create(int initialCapacity) Creates an empty |
public |
() |
create(int initialCapacity, float loadFactor) Creates a |
Modifiers | Return Types | Method and Description |
---|---|---|
public |
() |
destroy() |
Modifiers | Return Types | Method and Description |
---|---|---|
public |
(boolean) |
add(V value) Adds an object to the set. |
public |
(HashSet<V>) |
clear() Removes all objects from the set and resets the capacity to default. |
public readonly |
(boolean) |
contains(V value) Checks to see if the set contains the specified object. |
public readonly |
(HashSet<V>) |
copy(AddressMap addresses) |
public readonly |
(boolean) |
index(V value) Checks to see if the object is present in the set. |
public |
() |
index(V value, boolean add) Adds or removes an object to or from the set. |
public readonly |
(boolean) |
isEmpty() Checks whether or not the set is empty. |
public readonly |
(Iterator<V>) |
iterator() Creates an iterator to iterate over all the objects in the set. |
public |
(boolean) |
remove(V value) Removes an object from the set. |
public readonly |
(String) |
toString() Produces a |
Modifiers | Return Types | Method and Description |
---|---|---|
public readonly get |
(int) |
size() Gets the number of objects in the set as an |
public readonly get |
(long) |
sizeLong() Gets the number of objects in the set as a |
public create() => ()
Creates an empty HashSet
with a default capacity of 16 and maximum load factor of 0.75.
public create(int initialCapacity) => ()
Creates an empty HashSet
with the specified capacity and maximum load factor.
initialCapacity
- initial capacity of the set
loadFactor
- maximum load factor before the set is resized
public create(int initialCapacity, float loadFactor) => ()
Creates a HashSet
with the specified initial capacity of buckets and the specified maximum load factor before all the values are re-hashed. Note that the capacity will always be increased to the next power of 2 if it is not a power of 2.
initialCapacity
- initial number of buckets in the hash table
loadFactor
- maximum load factor (buckets / objects) before all values are re-hashed
public destroy() => ()
public add(V value) => (boolean)
Adds an object to the set. This operation runs in constant or near-constant time.
value
- object to be added
true
if added to the set, false
if already present
public clear() => (HashSet<V>)
Removes all objects from the set and resets the capacity to default.
set after being cleared
public readonly contains(V value) => (boolean)
Checks to see if the set contains the specified object. This operation runs in constant or near-constant time.
value
- object to look for
true
if object is present
public readonly copy(AddressMap addresses) => (HashSet<V>)
public readonly index(V value) => (boolean)
Checks to see if the object is present in the set. This operation runs in constant or near-constant time.
value
- object to search for
true
if the object is present
public index(V value, boolean add) => ()
Adds or removes an object to or from the set. This operation runs in constant or near-constant time.
value
- object to be added or removed
add
- add object if true
, remove if false
public readonly isEmpty() => (boolean)
Checks whether or not the set is empty.
true
if the set is empty
public readonly iterator() => (Iterator<V>)
Creates an iterator to iterate over all the objects in the set.
iterator
public remove(V value) => (boolean)
Removes an object from the set. This operation runs in constant or near-constant time.
value
- object to be removed
true
if successfully removed, false
if not present
public readonly toString() => (String)
Produces a String
representation of the set, listing all the objects in an unspecified order.
String
representation