Package it.unimi.di.prog2.h18.refactored
Class PreallocatedIntSet
java.lang.Object
it.unimi.di.prog2.h18.refactored.AbstractIntSet
it.unimi.di.prog2.h18.refactored.PreallocatedIntSet
A set of integer that can be preallocated to a given capacity.
An instance of this class is stored in a preallocated container of given initial capacity. Once the size reaches the capacity, the contained is doubled in size.
-
Field Summary
FieldsFields inherited from class it.unimi.di.prog2.h18.refactored.AbstractIntSet
size
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty set.PreallocatedIntSet
(int capacity) Creates an empty set with a given initial capacity. -
Method Summary
Methods inherited from class it.unimi.di.prog2.h18.refactored.AbstractIntSet
choose, equals, hashCode, size, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
elements
protected int[] elementsThe array of elements.
-
-
Constructor Details
-
PreallocatedIntSet
public PreallocatedIntSet()Creates an empty set. -
PreallocatedIntSet
public PreallocatedIntSet(int capacity) Creates an empty set with a given initial capacity.- Parameters:
capacity
- the initial capacity of the set.- Throws:
IllegalArgumentException
- if capacity is negative.
-
-
Method Details
-
isIn
public boolean isIn(int x) Description copied from class:AbstractIntSet
Tells if the given element is in this set.Answers the question \( x\in S \).
- Overrides:
isIn
in classAbstractIntSet
- Parameters:
x
- the element to look for.- Returns:
- whether the given element belongs to this set, or not.
-
insert
public void insert(int x) Description copied from class:AbstractIntSet
Adds the given element to this set.This method modifies the object, that is: \( S' = S \cup \{ x \} \).
- Specified by:
insert
in classAbstractIntSet
- Parameters:
x
- the element to be added.
-
remove
public void remove(int x) Description copied from class:AbstractIntSet
Removes the given element from this set.This method modifies the object, that is: \( S' = S \setminus \{ x \} \).
- Specified by:
remove
in classAbstractIntSet
- Parameters:
x
- the element to be removed.
-
iterator
-