Class IntOpenHashSet
- All Implemented Interfaces:
Serializable
,Cloneable
,IntCollection
,IntSet
- Since:
- 1.0
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default capacity of this set.static final int
The default chunk size with which to increase the capacity of this set.static final double
The default factor with which to increase the capacity of this set.static final double
The default load factor of this set. -
Constructor Summary
ConstructorDescriptionCreates a new hash set with capacity 11, a relative growth factor of 1.0, and a load factor of 75%.IntOpenHashSet
(double loadFactor) Creates a new hash set with a capacity of 11, a relative growth factor of 1.0, and a specified load factor.IntOpenHashSet
(int capacity) Creates a new hash set with a specified capacity, a relative growth factor of 1.0, and a load factor of 75%.IntOpenHashSet
(int[] a) Creates a new hash set with the same elements as the specified array.IntOpenHashSet
(int capacity, double loadFactor) Creates a new hash set with a specified capacity and load factor, and a relative growth factor of 1.0.IntOpenHashSet
(int capacity, double loadFactor, double growthFactor) Creates a new hash set with a specified capacity, load factor, and relative growth factor.IntOpenHashSet
(int capacity, double loadFactor, int growthChunk) Creates a new hash set with a specified capacity, load factor, and absolute growth factor.IntOpenHashSet
(IntHashFunction keyhash) Creates a new hash set with capacity 11, a relative growth factor of 1.0, and a load factor of 75%.IntOpenHashSet
(IntHashFunction keyhash, double loadFactor) Creates a new hash set with a capacity of 11, a relative growth factor of 1.0, and a specified load factor.IntOpenHashSet
(IntHashFunction keyhash, int capacity) Creates a new hash set with a specified capacity, a relative growth factor of 1.0, and a load factor of 75%.IntOpenHashSet
(IntHashFunction keyhash, int capacity, double loadFactor) Creates a new hash set with a specified capacity and load factor, and a relative growth factor of 1.0.IntOpenHashSet
(IntHashFunction keyhash, int capacity, double loadFactor, double growthFactor) Creates a new hash set with a specified capacity, load factor, and relative growth factor.IntOpenHashSet
(IntHashFunction keyhash, int capacity, double loadFactor, int growthChunk) Creates a new hash set with a specified capacity, load factor, and absolute growth factor.Creates a new hash set with the same elements as a specified collection. -
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(int v) Throws UnsupportedOperationException.void
clear()
Clears this collection.clone()
Returns a clone of this hash set.boolean
contains
(int v) Indicates whether this collection contains a specified element.int
hashCode()
Returns a hash code value for this collection.iterator()
Returns an iterator over this collection.boolean
remove
(int v) Removes a specified element from this collection.int
size()
Returns the number of elements in this collection.int[]
toArray
(int[] a) Returns the elements of this collection as an array.void
Does nothing.Methods inherited from class zombie.util.set.AbstractIntSet
equals
Methods inherited from class zombie.util.AbstractIntCollection
addAll, containsAll, isEmpty, removeAll, retainAll, toArray, toString
Methods inherited from interface zombie.util.IntCollection
addAll, containsAll, equals, isEmpty, removeAll, retainAll, toArray
-
Field Details
-
DEFAULT_GROWTH_FACTOR
public static final double DEFAULT_GROWTH_FACTORThe default factor with which to increase the capacity of this set.- See Also:
-
DEFAULT_GROWTH_CHUNK
public static final int DEFAULT_GROWTH_CHUNKThe default chunk size with which to increase the capacity of this set.- See Also:
-
DEFAULT_CAPACITY
public static final int DEFAULT_CAPACITYThe default capacity of this set.- See Also:
-
DEFAULT_LOAD_FACTOR
public static final double DEFAULT_LOAD_FACTORThe default load factor of this set.- See Also:
-
-
Constructor Details
-
IntOpenHashSet
public IntOpenHashSet()Creates a new hash set with capacity 11, a relative growth factor of 1.0, and a load factor of 75%. -
IntOpenHashSet
Creates a new hash set with the same elements as a specified collection.- Parameters:
c
- the collection whose elements to add to the new set.- Throws:
NullPointerException
- if c is null.
-
IntOpenHashSet
public IntOpenHashSet(int[] a) Creates a new hash set with the same elements as the specified array.- Parameters:
a
- the array whose elements to add to the new set.- Throws:
NullPointerException
- if a is null.- Since:
- 1.1
-
IntOpenHashSet
public IntOpenHashSet(int capacity) Creates a new hash set with a specified capacity, a relative growth factor of 1.0, and a load factor of 75%.- Parameters:
capacity
- the initial capacity of the set.- Throws:
IllegalArgumentException
- if capacity is negative.
-
IntOpenHashSet
public IntOpenHashSet(double loadFactor) Creates a new hash set with a capacity of 11, a relative growth factor of 1.0, and a specified load factor.- Parameters:
loadFactor
- the load factor of the set.- Throws:
IllegalArgumentException
- if loadFactor is negative or zero.
-
IntOpenHashSet
public IntOpenHashSet(int capacity, double loadFactor) Creates a new hash set with a specified capacity and load factor, and a relative growth factor of 1.0.- Parameters:
capacity
- the initial capacity of the set.loadFactor
- the load factor of the set.- Throws:
IllegalArgumentException
- if capacity is negative; if loadFactor is not positive.
-
IntOpenHashSet
public IntOpenHashSet(int capacity, double loadFactor, double growthFactor) Creates a new hash set with a specified capacity, load factor, and relative growth factor.The set capacity increases to capacity()*(1+growthFactor). This strategy is good for avoiding many capacity increases, but the amount of wasted memory is approximately the size of the set.
- Parameters:
capacity
- the initial capacity of the set.loadFactor
- the load factor of the set.growthFactor
- the relative amount with which to increase the the capacity when a capacity increase is needed.- Throws:
IllegalArgumentException
- if capacity is negative; if loadFactor is not positive; if growthFactor is not positive.
-
IntOpenHashSet
public IntOpenHashSet(int capacity, double loadFactor, int growthChunk) Creates a new hash set with a specified capacity, load factor, and absolute growth factor.The set capacity increases to capacity()+growthChunk. This strategy is good for avoiding wasting memory. However, an overhead is potentially introduced by frequent capacity increases.
- Parameters:
capacity
- the initial capacity of the set.loadFactor
- the load factor of the set.growthChunk
- the absolute amount with which to increase the the capacity when a capacity increase is needed.- Throws:
IllegalArgumentException
- if capacity is negative; if loadFactor is not positive; if growthChunk is not positive.
-
IntOpenHashSet
Creates a new hash set with capacity 11, a relative growth factor of 1.0, and a load factor of 75%.- Parameters:
keyhash
- the hash function to use when hashing keys.- Throws:
NullPointerException
- if keyhash is null.
-
IntOpenHashSet
Creates a new hash set with a specified capacity, a relative growth factor of 1.0, and a load factor of 75%.- Parameters:
keyhash
- the hash function to use when hashing keys.capacity
- the initial capacity of the set.- Throws:
IllegalArgumentException
- if capacity is negative.NullPointerException
- if keyhash is null.
-
IntOpenHashSet
Creates a new hash set with a capacity of 11, a relative growth factor of 1.0, and a specified load factor.- Parameters:
keyhash
- the hash function to use when hashing keys.loadFactor
- the load factor of the set.- Throws:
IllegalArgumentException
- if loadFactor is negative or zero.NullPointerException
- if keyhash is null.
-
IntOpenHashSet
Creates a new hash set with a specified capacity and load factor, and a relative growth factor of 1.0.- Parameters:
keyhash
- the hash function to use when hashing keys.capacity
- the initial capacity of the set.loadFactor
- the load factor of the set.- Throws:
IllegalArgumentException
- if capacity is negative; if loadFactor is not positive.NullPointerException
- if keyhash is null.
-
IntOpenHashSet
public IntOpenHashSet(IntHashFunction keyhash, int capacity, double loadFactor, double growthFactor) Creates a new hash set with a specified capacity, load factor, and relative growth factor.The set capacity increases to capacity()*(1+growthFactor). This strategy is good for avoiding many capacity increases, but the amount of wasted memory is approximately the size of the set.
- Parameters:
keyhash
- the hash function to use when hashing keys.capacity
- the initial capacity of the set.loadFactor
- the load factor of the set.growthFactor
- the relative amount with which to increase the the capacity when a capacity increase is needed.- Throws:
IllegalArgumentException
- if capacity is negative; if loadFactor is not positive; if growthFactor is not positive.NullPointerException
- if keyhash is null.
-
IntOpenHashSet
Creates a new hash set with a specified capacity, load factor, and absolute growth factor.- Parameters:
keyhash
- the hash function to use when hashing keys.The set capacity increases to capacity()+growthChunk. This strategy is good for avoiding wasting memory. However, an overhead is potentially introduced by frequent capacity increases.
capacity
- the initial capacity of the set.loadFactor
- the load factor of the set.growthChunk
- the absolute amount with which to increase the the capacity when a capacity increase is needed.- Throws:
IllegalArgumentException
- if capacity is negative; if loadFactor is not positive; if growthChunk is not positive.NullPointerException
- if keyhash is null.
-
-
Method Details
-
add
public boolean add(int v) Description copied from class:AbstractIntCollection
Throws UnsupportedOperationException.- Specified by:
add
in interfaceIntCollection
- Overrides:
add
in classAbstractIntCollection
- Parameters:
v
- the element to add to this collection.- Returns:
- true if this collection was modified as a result of adding v; returns false otherwise.
- See Also:
-
iterator
Description copied from interface:IntCollection
Returns an iterator over this collection.- Specified by:
iterator
in interfaceIntCollection
- Returns:
- an iterator over this collection.
-
trimToSize
public void trimToSize()Description copied from class:AbstractIntCollection
Does nothing. Sub-classes may provide an implementation to minimize memory usage, but this is not required since many implementations will always have minimal memory usage.- Specified by:
trimToSize
in interfaceIntCollection
- Overrides:
trimToSize
in classAbstractIntCollection
-
clone
Returns a clone of this hash set.- Returns:
- a clone of this hash set.
- Since:
- 1.1
-
size
public int size()Description copied from interface:IntCollection
Returns the number of elements in this collection.- Specified by:
size
in interfaceIntCollection
- Overrides:
size
in classAbstractIntCollection
- Returns:
- the number of elements in this collection.
-
clear
public void clear()Description copied from interface:IntCollection
Clears this collection.- Specified by:
clear
in interfaceIntCollection
- Overrides:
clear
in classAbstractIntCollection
-
contains
public boolean contains(int v) Description copied from interface:IntCollection
Indicates whether this collection contains a specified element.- Specified by:
contains
in interfaceIntCollection
- Overrides:
contains
in classAbstractIntCollection
- Parameters:
v
- the element to test for containment.- Returns:
- true if v is contained in this collection; returns false otherwise.
- See Also:
-
hashCode
public int hashCode()Description copied from interface:IntCollection
Returns a hash code value for this collection.- Specified by:
hashCode
in interfaceIntCollection
- Overrides:
hashCode
in classAbstractIntSet
- Returns:
- a hash code value for this collection.
-
remove
public boolean remove(int v) Description copied from interface:IntCollection
Removes a specified element from this collection.- Specified by:
remove
in interfaceIntCollection
- Overrides:
remove
in classAbstractIntCollection
- Parameters:
v
- the int value to remove from this collection.- Returns:
- true if this collection was modified as a result of removing v; returns false otherwise.
-
toArray
public int[] toArray(int[] a) Description copied from interface:IntCollection
Returns the elements of this collection as an array.- Specified by:
toArray
in interfaceIntCollection
- Overrides:
toArray
in classAbstractIntCollection
- Parameters:
a
- an array to fill with the elements of this collection; if a is null or not big enough to contain all the elements of this collection, an new array is allocated, and a is not changed.- Returns:
- a, if a has room for all the elements of this collection; otherwise a new array is allocated, filled with the elements of this collection, and returned.
-