java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
com.aoapps.collections.ArraySet<E>
- All Implemented Interfaces:
Serializable
,Iterable<E>
,Collection<E>
,Set<E>
A compact
Set
implementation that stores the elements in hashCode order.
The emphasis is to use as little heap space as possible - this is not a general-purpose
Set
implementation as it has specific constraints about the order elements
may be added or removed. To avoid the possibility of O(n^2) behavior, the elements must
already be sorted and be added in ascending order. Also, only the last element may be
removed.
This set does not support null values.
This set will generally operate at O(log n) due to binary search. In general, it will not be as fast as the O(1) behavior of HashSet. Here we give up speed to save space.
This set is not thread safe.
- Author:
- AO Industries, Inc.
- See Also:
-
Constructor Summary
ConstructorDescriptionArraySet()
Deprecated.This is for convention only, please provide a previously sorted ArrayList for best performance.ArraySet
(int initialCapacity) Deprecated.This is for convention only, please provide a previously sorted ArrayList for best performance.Uses the provided elements list without copying, which must already be sorted in hashCode order and unique.ArraySet
(Collection<? extends E> c) Deprecated.This is for convention only, please provide a previously sorted ArrayList for best performance. -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends E> c) void
clear()
boolean
boolean
containsAll
(Collection<?> c) boolean
isEmpty()
iterator()
boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) int
size()
Object[]
toArray()
<T> T[]
toArray
(T[] a) void
Methods inherited from class java.util.AbstractSet
equals, hashCode
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
-
Constructor Details
-
ArraySet
Deprecated.This is for convention only, please provide a previously sorted ArrayList for best performance. -
ArraySet
Deprecated.This is for convention only, please provide a previously sorted ArrayList for best performance. -
ArraySet
Deprecated.This is for convention only, please provide a previously sorted ArrayList for best performance. -
ArraySet
Uses the provided elements list without copying, which must already be sorted in hashCode order and unique.The sort order and uniqueness is only checked with assertions enabled.
- See Also:
-
-
Method Details
-
trimToSize
public void trimToSize() -
size
public int size()- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceSet<E>
- Specified by:
size
in classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceSet<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
-
contains
- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceSet<E>
- Overrides:
contains
in classAbstractCollection<E>
-
iterator
-
toArray
- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceSet<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceSet<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
add
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceSet<E>
- Overrides:
add
in classAbstractCollection<E>
-
remove
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceSet<E>
- Overrides:
remove
in classAbstractCollection<E>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceSet<E>
- Overrides:
containsAll
in classAbstractCollection<E>
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceSet<E>
- Overrides:
addAll
in classAbstractCollection<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceSet<E>
- Overrides:
retainAll
in classAbstractCollection<E>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceSet<E>
- Overrides:
removeAll
in classAbstractSet<E>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceSet<E>
- Overrides:
clear
in classAbstractCollection<E>
-