Package pascal.taie.util.collection
Class AbstractHybridSet<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
pascal.taie.util.collection.AbstractSetEx<E>
pascal.taie.util.collection.AbstractHybridSet<E>
- Type Parameters:
E
- type of elements
- All Implemented Interfaces:
Serializable
,Iterable<E>
,Collection<E>
,Set<E>
,SetEx<E>
,Copyable<SetEx<E>>
- Direct Known Subclasses:
HybridBitSet
,HybridHashSet
,HybridIndexableSet
,HybridLinkedHashSet
This set supports hybrid of two set implementations, where one is
efficient for small set and another one is efficient for large set.
When the number of elements contained in this set succeeds a threshold, it will automatically upgrade the set implementation to the one that is efficient for large set. Moreover, empty sets and singleton sets are represented with just a reference.
Elements added to this set cannot be null.
By default, this set uses ArraySet
for small set.
- See Also:
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Constructs a new hybrid set.protected
Constructs a new hybrid set from the given collection. -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends E> c) void
clear()
boolean
boolean
containsAll
(Collection<?> c) boolean
protected int
int
hashCode()
boolean
isEmpty()
iterator()
newLargeSet
(int initialCapacity) Creates a large set.Creates a small set.boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) int
size()
Object[]
toArray()
<T> T[]
toArray
(T[] a) Methods inherited from class pascal.taie.util.collection.AbstractSetEx
addAllDiff, copy, hasOverlapWith, newSet
Methods inherited from class java.util.AbstractCollection
toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.Set
spliterator
-
Field Details
-
singleton
The singleton value. Null if not a singleton. -
set
The set containing the elements. Null if the set is not used. -
isLargeSet
protected boolean isLargeSetWhether the set implementation is the one for large set.
-
-
Constructor Details
-
AbstractHybridSet
protected AbstractHybridSet()Constructs a new hybrid set. -
AbstractHybridSet
Constructs a new hybrid set from the given collection.
-
-
Method Details
-
getThreshold
protected int getThreshold()- Returns:
- the threshold between sizes of small set and large set. When number of elements exceeds the threshold, set should be upgraded to large set.
-
newSmallSet
Creates a small set. -
newLargeSet
Creates a large set.- Parameters:
initialCapacity
- initial capacity of the resulting set.
-
add
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceSet<E>
- Overrides:
add
in classAbstractCollection<E>
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceSet<E>
- Overrides:
addAll
in classAbstractCollection<E>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceSet<E>
- Overrides:
clear
in classAbstractCollection<E>
-
contains
- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceSet<E>
- Overrides:
contains
in classAbstractCollection<E>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceSet<E>
- Overrides:
containsAll
in classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceSet<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
-
size
public int size()- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceSet<E>
- Specified by:
size
in classAbstractCollection<E>
-
iterator
-
remove
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceSet<E>
- Overrides:
remove
in classAbstractCollection<E>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceSet<E>
- Overrides:
removeAll
in classAbstractSet<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceSet<E>
- Overrides:
retainAll
in classAbstractCollection<E>
-
toArray
- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceSet<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
toArray
@Nonnull public <T> T[] toArray(@Nonnull T[] a) - Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceSet<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<E>
- Specified by:
hashCode
in interfaceSet<E>
- Overrides:
hashCode
in classAbstractSet<E>
-
equals
- Specified by:
equals
in interfaceCollection<E>
- Specified by:
equals
in interfaceSet<E>
- Overrides:
equals
in classAbstractSet<E>
-