Package org.plumelib.util
Class LimitedSizeLongSet
java.lang.Object
org.plumelib.util.LimitedSizeLongSet
- All Implemented Interfaces:
Serializable,Cloneable
LimitedSizeLongSet stores up to some maximum number of unique values. If more than that many
elements are added, then functionality is degraded: most operations return a conservative
estimate (because the internal representation is nulled, in order to save space).
The advantage of this class over LimitedSizeSet<Long> is that it does not autobox the
long values, so it takes less memory.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @org.checkerframework.checker.index.qual.IndexOrHigh({"values"}) intThe number of active elements (equivalently, the first unused index).protected long @Nullable @MinLen(1) [] -
Constructor Summary
ConstructorsConstructorDescriptionLimitedSizeLongSet(@org.checkerframework.checker.index.qual.Positive int maxValues) Create a new LimitedSizeLongSet that can hold maxValues values. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(long elt) Add an element to this set.voidAdd all elements ofsto this set.clone()booleancontains(long elt) Returns true if this set contains the given element.booleanisEmpty()Returns true if this is empty.@org.checkerframework.checker.index.qual.Positive intmaxSize()An upper bound on how many distinct elements can be individually represented in the set.static LimitedSizeLongSetmerge(@org.checkerframework.checker.index.qual.Positive int maxValues, List<LimitedSizeLongSet> slist) Merges a list ofLimitedSizeLongSetobjects into a single object that represents the values seen by the entire list.booleanReturns true if more elements have been added than this set can contain (which is the integer that was passed to the constructor when creating this set).@org.checkerframework.checker.index.qual.IndexOrHigh({"this.values"}) intsize()A lower bound on the number of elements in the set.toString()
-
Field Details
-
values
protected long @Nullable @MinLen(1) [] values -
numValues
protected @org.checkerframework.checker.index.qual.IndexOrHigh({"values"}) int numValuesThe number of active elements (equivalently, the first unused index).
-
-
Constructor Details
-
LimitedSizeLongSet
public LimitedSizeLongSet(@org.checkerframework.checker.index.qual.Positive int maxValues) Create a new LimitedSizeLongSet that can hold maxValues values.- Parameters:
maxValues- the maximum number of values this set will be able to hold; must be positive
-
-
Method Details
-
add
public void add(long elt) Add an element to this set.- Parameters:
elt- the element to add to this set
-
addAll
Add all elements ofsto this set.- Parameters:
s- the elements to add to this set
-
contains
@Pure public boolean contains(long elt) Returns true if this set contains the given element.- Parameters:
elt- the element whose membership to test- Returns:
- true if this set contains
elt
-
size
@Pure public @org.checkerframework.checker.index.qual.IndexOrHigh({"this.values"}) int size(@GuardSatisfied LimitedSizeLongSet this) A lower bound on the number of elements in the set. Returns either the number of elements that have been inserted in the set, or maxSize(), whichever is less.- Returns:
- a number that is a lower bound on the number of elements added to the set
-
isEmpty
@Pure public boolean isEmpty()Returns true if this is empty.- Returns:
- true if this is empty
-
maxSize
public @org.checkerframework.checker.index.qual.Positive int maxSize()An upper bound on how many distinct elements can be individually represented in the set. Returns maxValues+1 (where maxValues is the argument to the constructor).- Returns:
- maximum capacity of the set representation
-
repNulled
@EnsuresNonNullIf(result=false, expression="values") @Pure public boolean repNulled(@GuardSatisfied LimitedSizeLongSet this) Returns true if more elements have been added than this set can contain (which is the integer that was passed to the constructor when creating this set).- Returns:
- true if this set has been filled to capacity and its internal representation is nulled
-
clone
-
merge
public static LimitedSizeLongSet merge(@org.checkerframework.checker.index.qual.Positive int maxValues, List<LimitedSizeLongSet> slist) Merges a list ofLimitedSizeLongSetobjects into a single object that represents the values seen by the entire list. Returns the new object, whose maxValues is the given integer.- Parameters:
maxValues- the maximum size for the returned setslist- a list of sets, whose elements will be merged- Returns:
- a set that merges the elements of slist
-
toString
-