java.lang.Object
org.jhotdraw8.collection.primitive.DenseIntSet8Bit
- All Implemented Interfaces:
IntSet
- Direct Known Subclasses:
GrowableIntSet8Bit
A dense set of int-values which can be cleared in O(1);
needs 8-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 255 times it takes O(n) time to clear the set.
Storage space is one byte per boolean.
This set has a fixed capacity. Attempting to access an element outside of the
capacity range results in an ArrayIndexOutOfBoundsException.
-
Constructor Summary
Constructors -
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[]Returns a new long array containing all the bits in this int set.toString()
-
Constructor Details
-
DenseIntSet8Bit
public DenseIntSet8Bit(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- an 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
public long[] toLongArray()Returns a new long array containing all the bits in this int set.- Returns:
- a new long array.
-
toString
-