MutableIntSet
public final class MutableIntSet extends IntSet
MutableIntSet is a container with a MutableSet-like interface based on a flat hash table implementation. The underlying implementation is designed to avoid all allocations on insertion, removal, retrieval, and iteration. Allocations may still happen on insertion when the underlying storage needs to grow to accommodate newly added elements to the set.
This implementation makes no guarantee as to the order of the elements stored, nor does it make guarantees that the order remains constant over time.
This implementation is not thread-safe: if multiple threads access this container concurrently, and one or more threads modify the structure of the set (insertion or removal for instance), the calling code must provide the appropriate synchronization. Concurrent reads are however safe.
Summary
Public constructors |
|---|
MutableIntSet(int initialCapacity)Creates a new |
Public methods |
|
|---|---|
final boolean |
add(int element)Adds the specified element to the set. |
final boolean |
Adds all the |
final boolean |
Adds all the elements in the |
final void |
clear()Removes all elements from this set. |
final void |
minusAssign(int element)Removes the specified |
final void |
minusAssign(@NonNull int[] elements)Removes the specified |
final void |
minusAssign(@NonNull IntSet elements)Removes the specified |
final void |
plusAssign(int element)Adds the specified element to the set. |
final void |
plusAssign(@NonNull int[] elements)Adds all the |
final void |
plusAssign(@NonNull IntSet elements)Adds all the elements in the |
final boolean |
remove(int element)Removes the specified |
final boolean |
Removes the specified |
final boolean |
Removes the specified |
final @IntRange(from = 0) int |
trim()Trims this |
Inherited methods |
||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
MutableIntSet
public MutableIntSet(int initialCapacity)
Creates a new MutableIntSet
| Parameters | |
|---|---|
int initialCapacity |
The initial desired capacity for this container. The container will honor this value by guaranteeing its internal structures can hold that many elements without requiring any allocations. The initial capacity can be set to 0. |
Public methods
add
public final boolean add(int element)
Adds the specified element to the set.
| Parameters | |
|---|---|
int element |
The element to add to the set. |
| Returns | |
|---|---|
boolean |
|
addAll
public final boolean addAll(@NonNull int[] elements)
Adds all the elements into this set.
| Parameters | |
|---|---|
@NonNull int[] elements |
An array of elements to add to the set. |
| Returns | |
|---|---|
boolean |
|
addAll
public final boolean addAll(@NonNull IntSet elements)
Adds all the elements in the elements set into this set.
| Returns | |
|---|---|
boolean |
|
minusAssign
public final void minusAssign(int element)
Removes the specified element from the set if it is present.
| Parameters | |
|---|---|
int element |
The element to remove from the set. |
minusAssign
public final void minusAssign(@NonNull int[] elements)
Removes the specified elements from the set, if present.
| Parameters | |
|---|---|
@NonNull int[] elements |
An array of elements to be removed from the set. |
minusAssign
public final void minusAssign(@NonNull IntSet elements)
Removes the specified elements from the set, if present.
plusAssign
public final void plusAssign(int element)
Adds the specified element to the set.
| Parameters | |
|---|---|
int element |
The element to add to the set. |
plusAssign
public final void plusAssign(@NonNull int[] elements)
Adds all the elements into this set.
| Parameters | |
|---|---|
@NonNull int[] elements |
An array of elements to add to the set. |
plusAssign
public final void plusAssign(@NonNull IntSet elements)
Adds all the elements in the elements set into this set.
remove
public final boolean remove(int element)
Removes the specified element from the set.
| Parameters | |
|---|---|
int element |
The element to remove from the set. |
| Returns | |
|---|---|
boolean |
|
removeAll
public final boolean removeAll(@NonNull int[] elements)
Removes the specified elements from the set, if present.
| Parameters | |
|---|---|
@NonNull int[] elements |
An array of elements to be removed from the set. |
| Returns | |
|---|---|
boolean |
|
removeAll
public final boolean removeAll(@NonNull IntSet elements)
Removes the specified elements from the set, if present.
| Returns | |
|---|---|
boolean |
|
trim
public final @IntRange(from = 0) int trim()
Trims this MutableIntSet's storage so it is sized appropriately to hold the current elements.
Returns the number of empty elements removed from this set's storage. Returns 0 if no trimming is necessary or possible.