shadow:utility

Class HashSet<V>

Parent class

shadow:standard@Object

Interfaces

shadow:utility@Set<V>

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.

See Also

Create Summary

Modifiers Return Types Method and Description
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.

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.

Destroy Summary

Modifiers Return Types Method and Description
public () destroy()

Method Summary

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 String representation of the set, listing all the objects in an unspecified order.

Property Summary

Modifiers Return Types Method and Description
public readonly get (int) size()

Gets the number of objects in the set as an int.

public readonly get (long) sizeLong()

Gets the number of objects in the set as a long.

Create Detail

create

public create() => ()

Creates an empty HashSet with a default capacity of 16 and maximum load factor of 0.75.

create

public create(int initialCapacity) => ()

Creates an empty HashSet with the specified capacity and maximum load factor.

Parameters

initialCapacity - initial capacity of the set

loadFactor - maximum load factor before the set is resized

create

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.

Parameters

initialCapacity - initial number of buckets in the hash table

loadFactor - maximum load factor (buckets / objects) before all values are re-hashed

Destroy Detail

destroy

public destroy() => ()

Method Detail

add

public add(V value) => (boolean)

Adds an object to the set. This operation runs in constant or near-constant time.

Parameters

value - object to be added

Returns

true if added to the set, false if already present

clear

public clear() => (HashSet<V>)

Removes all objects from the set and resets the capacity to default.

Returns

set after being cleared

contains

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.

Parameters

value - object to look for

Returns

true if object is present

copy

public readonly copy(AddressMap addresses) => (HashSet<V>)

index

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.

Parameters

value - object to search for

Returns

true if the object is present

index

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.

Parameters

value - object to be added or removed

add - add object if true, remove if false

isEmpty

public readonly isEmpty() => (boolean)

Checks whether or not the set is empty.

Returns

true if the set is empty

iterator

public readonly iterator() => (Iterator<V>)

Creates an iterator to iterate over all the objects in the set.

Returns

iterator

remove

public remove(V value) => (boolean)

Removes an object from the set. This operation runs in constant or near-constant time.

Parameters

value - object to be removed

Returns

true if successfully removed, false if not present

toString

public readonly toString() => (String)

Produces a String representation of the set, listing all the objects in an unspecified order.

Returns

String representation

Property Detail

size

public readonly get size() => (int)

Gets the number of objects in the set as an int.

Returns

size of set

sizeLong

public readonly get sizeLong() => (long)

Gets the number of objects in the set as a long.

Returns

size of set