Package org.dellroad.stuff.util
Class LongSet
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Long>,Collection<Long>,Set<Long>
A set of non-zero
long values.
This implementation uses long[] arrays and open addressing to minimize memory overhead.
Equivalent Set methods taking long instead of Long are also provided.
Instances will throw IllegalStateException if their capacity is exceeded.
Instances do not accept zero values and are not thread safe.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(long value) booleanvoidclear()clone()booleancontains(long value) booleaninthashCode()booleanisEmpty()iterator()Returns a sequentialLongStreamwith this instance as its source.booleanremove(long value) booleanlongRemove a single, arbitrarylongvalue from this instance and return it.intsize()Long[]toArray()long[]Methods inherited from class java.util.AbstractSet
equals, removeAllMethods inherited from class java.util.AbstractCollection
addAll, containsAll, retainAll, toArray, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
addAll, containsAll, retainAll, spliterator, toArray
-
Constructor Details
-
LongSet
public LongSet()Constructs an empty instance. -
LongSet
public LongSet(int capacity) Constructs an instance with the given initial capacity.- Parameters:
capacity- initial capacity- Throws:
IllegalArgumentException- ifcapacityis negative
-
LongSet
Constructs an instance initialized with the given values.- Parameters:
values- initial contents for this instance- Throws:
IllegalArgumentException- ifvaluesis nullIllegalArgumentException- if any value invaluesis nullIllegalArgumentException- if any value invaluesis zero
-
LongSet
public LongSet(long[] values) Constructs an instance initialized with the values in the given array.- Parameters:
values- initial contents for this instance- Throws:
IllegalArgumentException- ifvaluesis nullNullPointerException- if any value invaluesis zero
-
-
Method Details
-
removeOne
public long removeOne()Remove a single, arbitrarylongvalue from this instance and return it.- Returns:
- the removed value, or zero if this instance is empty
-
longStream
Returns a sequentialLongStreamwith this instance as its source.- Returns:
- stream of contents
-
iterator
-
size
public int size()- Specified by:
sizein interfaceCollection<Long>- Specified by:
sizein interfaceSet<Long>- Specified by:
sizein classAbstractCollection<Long>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<Long>- Specified by:
isEmptyin interfaceSet<Long>- Overrides:
isEmptyin classAbstractCollection<Long>
-
contains
- Specified by:
containsin interfaceCollection<Long>- Specified by:
containsin interfaceSet<Long>- Overrides:
containsin classAbstractCollection<Long>
-
contains
public boolean contains(long value) -
add
- Specified by:
addin interfaceCollection<Long>- Specified by:
addin interfaceSet<Long>- Overrides:
addin classAbstractCollection<Long>
-
add
public boolean add(long value) -
remove
- Specified by:
removein interfaceCollection<Long>- Specified by:
removein interfaceSet<Long>- Overrides:
removein classAbstractCollection<Long>
-
remove
public boolean remove(long value) -
clear
public void clear()- Specified by:
clearin interfaceCollection<Long>- Specified by:
clearin interfaceSet<Long>- Overrides:
clearin classAbstractCollection<Long>
-
toArray
- Specified by:
toArrayin interfaceCollection<Long>- Specified by:
toArrayin interfaceSet<Long>- Overrides:
toArrayin classAbstractCollection<Long>
-
toLongArray
public long[] toLongArray() -
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<Long>- Specified by:
hashCodein interfaceSet<Long>- Overrides:
hashCodein classAbstractSet<Long>
-
clone
-