java.lang.Object
org.jhotdraw8.collection.primitive.DenseIntSet16Bit
- All Implemented Interfaces:
IntSet
A dense set of int-values which can be cleared in O(1);
needs 16-bits storage space for each int-value.
This set is optimised for frequent setting and clearing.
Setting a boolean at an index is O(1).
Clearing the set is O(1) amortized. Every 2^16 - 1 times it takes
O(n) time to clear the set.
Storage space is one char per boolean.
This set has a fixed capacity. Attempting to access an element outside of the
capacity range results in an ArrayIndexOutOfBoundsException.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty set.DenseIntSet16Bit(int capacity) Creates a set with the specified capacity. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddAsInt(int element) Adds an element to the set.intcapacity()Gets the capacity of the set.voidclear()Clears the set.booleancontainsAsInt(int e) Checks if the set contains the specified element.booleaninthashCode()The hash code is the same asBitSet.hashCode().booleanremoveAsInt(int element) Removes the specified element from the set.voidsetCapacity(int capacity) Sets the capacity of the set.long @NonNull []Returns a new long array containing all the bits in this int set.toString()
-
Constructor Details
-
DenseIntSet16Bit
public DenseIntSet16Bit()Creates an empty set. -
DenseIntSet16Bit
public DenseIntSet16Bit(int capacity) Creates a set with the specified capacity.
-
-
Method Details
-
addAsInt
public boolean addAsInt(int element) Adds an element to the set.- Specified by:
addAsIntin interfaceIntSet- Parameters:
element- the element- Returns:
- true if the element was added, false if it was already in the set.
- Throws:
ArrayIndexOutOfBoundsException- if element is outside of the capacity range.
-
removeAsInt
public boolean removeAsInt(int element) Removes the specified element from the set.- Specified by:
removeAsIntin interfaceIntSet- Parameters:
element- an element- Returns:
- true if the element was in the set, false otherwise
- Throws:
ArrayIndexOutOfBoundsException- if element is outside of the capacity range.
-
containsAsInt
public boolean containsAsInt(int e) Checks if the set contains the specified element.- Specified by:
containsAsIntin interfaceIntSet- Parameters:
e- the element- Returns:
- true if the element is in the set.
- Throws:
ArrayIndexOutOfBoundsException- if element is outside of the capacity range.
-
clear
public void clear()Description copied from interface:IntSetClears the set. -
setCapacity
public void setCapacity(int capacity) Sets the capacity of the set.- Parameters:
capacity- the new capacity
-
capacity
public int capacity()Gets the capacity of the set.- Returns:
- the capacity
-
equals
-
hashCode
public int hashCode()The hash code is the same asBitSet.hashCode(). -
toLongArray
Returns a new long array containing all the bits in this int set.- Returns:
- a new long array.
-
toString
-