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
ConstructorsConstructorDescriptionArraySet()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 TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends E> c) voidclear()booleanbooleancontainsAll(Collection<?> c) booleanisEmpty()iterator()booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) intsize()Object[]toArray()<T> T[]toArray(T[] a) voidMethods inherited from class java.util.AbstractSet
equals, hashCodeMethods inherited from class java.util.AbstractCollection
toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods 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:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
contains
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>
-
iterator
-
toArray
- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Overrides:
toArrayin classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Overrides:
toArrayin classAbstractCollection<E>
-
add
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>
-
remove
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-
containsAll
- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceSet<E>- Overrides:
containsAllin classAbstractCollection<E>
-
addAll
- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceSet<E>- Overrides:
addAllin classAbstractCollection<E>
-
retainAll
- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceSet<E>- Overrides:
retainAllin classAbstractCollection<E>
-
removeAll
- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceSet<E>- Overrides:
removeAllin classAbstractSet<E>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>
-
