-
- All Known Subinterfaces:
IntIterableSet
- All Known Implementing Classes:
AbstractSet
,IntIterableBitSet
,IntIterableRangeSet
,Set_BitSet
,Set_CstInterval
,Set_FixedArray
,Set_LinkedList
,Set_ReadOnly
,Set_Std_BitSet
,Set_Std_Swap
,Set_Std_Swap2
,Set_Swap
,Set_Swap2
,SetDifference
,SetDynamicFilter
,SetDynamicFilterOnSet
,SetIntersection
,SetUnion
,StdSet
public interface ISet extends Iterable<Integer>
Class representing a set of integers Created by IntelliJ IDEA.- Since:
- 9 feb. 2011, update 2016
- Author:
- chameau, Jean-Guillaume Fages
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ISet.WithOffset
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
add(int element)
Add element to the setvoid
clear()
Remove all elements from the setboolean
contains(int element)
Test the existence of element in the setSetType
getSetType()
default boolean
isEmpty()
ISetIterator
iterator()
Use the following loop to iterate over this set without autoboxing.int
max()
int
min()
ISetIterator
newIterator()
Creates a new iterator object, for nested loops only.default void
notifyCleared(int idx)
Operations to perform when an observed set is cleareddefault void
notifyElementAdded(int element, int idx)
Operations to perform when an observed set has an element added.default void
notifyElementRemoved(int element, int idx)
Operations to perform when an observed set has an element removed.void
registerObserver(ISet set, int idx)
Register an observer to this set.boolean
remove(int element)
Remove the first occurrence of element from the setint
size()
default int[]
toArray()
Copies the set in an array if integers-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
iterator
ISetIterator iterator()
Use the following loop to iterate over this set without autoboxing.// more readable but with autoboxing for(int value:set){ ... } // more verbose but without autoboxing ISetIterator iter = set.primitiveIterator(); while(iter.hasNext()){ int k = iter.next(); ... }
Do not use this iterator to make nested loops overISet
(prefernewIterator()
)
-
newIterator
ISetIterator newIterator()
Creates a new iterator object, for nested loops only.- Returns:
- a new iterator for this set
-
add
boolean add(int element)
Add element to the set- Parameters:
element
- element to add- Returns:
- true iff element was not in the set and has been added
-
remove
boolean remove(int element)
Remove the first occurrence of element from the set- Parameters:
element
- element to add- Returns:
- true iff element was in the set and has been removed
-
contains
boolean contains(int element)
Test the existence of element in the set- Parameters:
element
- element to add- Returns:
- true iff the set contains element
-
isEmpty
default boolean isEmpty()
- Returns:
- true iff the set is empty
-
size
int size()
- Returns:
- the number of elements in the set
-
clear
void clear()
Remove all elements from the set
-
min
int min()
- Returns:
- the smallest element in the set throws an exception if the set is empty Time complexity is linear for BIPARTITESET and LINKED_LIST (constant time otherwise)
-
max
int max()
- Returns:
- the largest element in the set throws an exception if the set is empty Time complexity is linear for BIPARTITESET and LINKED_LIST (constant time otherwise)
-
getSetType
SetType getSetType()
- Returns:
- the implementation type of this set
-
registerObserver
void registerObserver(ISet set, int idx)
Register an observer to this set. Observers are dynamic set data structures whose value depends on observed sets. This method must be called by observers' constructors.- Parameters:
set
- The observer to registeridx
- This index of this set in the observing set.
-
notifyElementAdded
default void notifyElementAdded(int element, int idx)
Operations to perform when an observed set has an element added.- Parameters:
element
- the element added to the observed set.idx
- the index of the observed set.
-
notifyElementRemoved
default void notifyElementRemoved(int element, int idx)
Operations to perform when an observed set has an element removed.- Parameters:
element
- the element removed to the observed set.idx
- the index of the observed set.
-
notifyCleared
default void notifyCleared(int idx)
Operations to perform when an observed set is cleared- Parameters:
idx
- the index of the observed set.
-
toArray
default int[] toArray()
Copies the set in an array if integers- Returns:
- an array containing every integer of the set
-
-