Class IntegerSet
java.lang.Object
com.comphenix.protocol.concurrency.IntegerSet
Represents a very quick integer set that uses a lookup table to store membership.
This class is intentionally missing a size method.
- Author:
- Kristian
-
Constructor Summary
ConstructorsConstructorDescriptionIntegerSet(int maximumCount)Initialize a lookup table with the given maximum number of elements.IntegerSet(int maximumCount, Collection<Integer> values)Initialize a lookup table with a given maximum and value list. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(int element)Add the given element to the set, or do nothing if it already exists.voidaddAll(Collection<Integer> packets)Add the given collection of elements to the set.voidclear()Remove every element from the set.booleancontains(int element)Determine whether or not the given element exists in the set.voidremove(int element)Remove the given element from the set, or do nothing if it's already removed.toSet()Convert the current IntegerSet to an equivalent HashSet.
-
Constructor Details
-
IntegerSet
public IntegerSet(int maximumCount)Initialize a lookup table with the given maximum number of elements.This creates a set for elements in the range [0, count).
Formally, the current set must be a subset of [0, 1, 2, ..., count - 1].
- Parameters:
maximumCount- - maximum element value and count.
-
IntegerSet
Initialize a lookup table with a given maximum and value list.The provided elements must be in the range [0, count).
- Parameters:
maximumCount- - the maximum element value and count.values- - the elements to add to the set.
-
-
Method Details
-
contains
public boolean contains(int element)Determine whether or not the given element exists in the set.- Parameters:
element- - the element to check. Must be in the range [0, count).- Returns:
- TRUE if the given element exists, FALSE otherwise.
-
add
public void add(int element)Add the given element to the set, or do nothing if it already exists.- Parameters:
element- - element to add.- Throws:
ArrayIndexOutOfBoundsException- If the given element is not in the range [0, count).
-
addAll
Add the given collection of elements to the set.- Parameters:
packets- - elements to add.
-
remove
public void remove(int element)Remove the given element from the set, or do nothing if it's already removed.- Parameters:
element- - element to remove.
-
clear
public void clear()Remove every element from the set. -
toSet
Convert the current IntegerSet to an equivalent HashSet.- Returns:
- The resulting HashSet.
-