Class FastSet<E>
- java.lang.Object
-
- javolution37.javolution.realtime.RealtimeObject
-
- javolution37.javolution.util.FastCollection<E>
-
- javolution37.javolution.util.FastSet<E>
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>, Reusable, Realtime
public class FastSet<E> extends FastCollection<E> implements java.util.Set<E>, Reusable
This class represents a set collection backed by a
FastMap; smooth capacity increase and no rehashing ever performed.Instances of this class can directly be allocated from the current thread stack using the
newInstance()factory method (e.g. for throw-away set to avoid the creation cost).FastSet, as for anyFastCollectionsub-class, supports thread-safe fast iterations without using iterators. For example:for (FastSet.Record r = set.head(), end = set.tail(); (r = r.getNext()) != end;) { Object value = set.valueOf(r); }- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javolution37.javolution.util.FastCollection
FastCollection.Record
-
Nested classes/interfaces inherited from class javolution37.javolution.realtime.RealtimeObject
RealtimeObject.Factory<T extends RealtimeObject>
-
Nested classes/interfaces inherited from interface javolution37.javolution.realtime.Realtime
Realtime.ObjectSpace
-
-
Constructor Summary
Constructors Constructor and Description FastSet()Creates a set of small initial capacity.FastSet(int capacity)Creates a set of specified initial capacity; unless the set size reaches the specified capacity, operations on this set will not allocate memory (no lazy object creation).FastSet(java.util.Set<? extends E> elements)Creates a set containing the specified elements, in the order they are returned by the set iterator.FastSet(java.lang.String id)Creates a persistent set associated to the specified unique identifier (convenience method).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanadd(E value)Adds the specified value to this set if it is not already present.voidclear()Removes all of the values from this collection (optional operation).booleancontains(java.lang.Object o)Indicates if this collection contains the specified value.voiddelete(FastCollection.Record record)Deletes the specified record from this collection.FastCollection.Recordhead()Returns the head record of this collection; it is the record such ashead().getNext()holds the first collection value.static <E> FastSet<E>newInstance()Returns a set allocated from the stack when executing in aPoolContext).booleanremove(java.lang.Object o)Removes the first occurrence in this collection of the specified value (optional operation).voidreset()Resets the internal state of this object to its default values.FastCollection<E>setValueComparator(FastComparator comparator)Sets the comparator to use for value equality or ordering if the collection is ordered (e.g.intsize()Returns the number of elements in this set (its cardinality).FastCollection.Recordtail()Returns the tail record of this collection; it is the record such astail().getPrevious()holds the last collection value.java.util.Set<E>unmodifiable()Returns the unmodifiable view associated to this collection.EvalueOf(FastCollection.Record record)Returns the collection value for the specified record.-
Methods inherited from class javolution37.javolution.util.FastCollection
addAll, containsAll, equals, getValueComparator, hashCode, isEmpty, iterator, removeAll, retainAll, toArray, toArray, toText
-
Methods inherited from class javolution37.javolution.realtime.RealtimeObject
export, move, moveHeap, preserve, toString, unpreserve
-
-
-
-
Constructor Detail
-
FastSet
public FastSet()
Creates a set of small initial capacity.
-
FastSet
public FastSet(java.lang.String id)
Creates a persistent set associated to the specified unique identifier (convenience method).- Parameters:
id- the unique identifier for this map.- Throws:
java.lang.IllegalArgumentException- if the identifier is not unique.- See Also:
PersistentReference
-
FastSet
public FastSet(int capacity)
Creates a set of specified initial capacity; unless the set size reaches the specified capacity, operations on this set will not allocate memory (no lazy object creation).- Parameters:
capacity- the initial capacity.
-
FastSet
public FastSet(java.util.Set<? extends E> elements)
Creates a set containing the specified elements, in the order they are returned by the set iterator.- Parameters:
elements- the elements to be placed into this fast set.
-
-
Method Detail
-
newInstance
public static <E> FastSet<E> newInstance()
Returns a set allocated from the stack when executing in aPoolContext).- Returns:
- a new, pre-allocated or recycled set instance.
-
size
public final int size()
Returns the number of elements in this set (its cardinality).- Specified by:
sizein interfacejava.util.Collection<E>- Specified by:
sizein interfacejava.util.Set<E>- Specified by:
sizein classFastCollection<E>- Returns:
- the number of elements in this set (its cardinality).
-
add
public final boolean add(E value)
Adds the specified value to this set if it is not already present.- Specified by:
addin interfacejava.util.Collection<E>- Specified by:
addin interfacejava.util.Set<E>- Overrides:
addin classFastCollection<E>- Parameters:
value- the value to be added to this set.- Returns:
trueif this set did not already contain the specified element.
-
unmodifiable
public java.util.Set<E> unmodifiable()
Description copied from class:FastCollectionReturns the unmodifiable view associated to this collection. Attempts to modify the returned collection result in anUnsupportedOperationExceptionbeing thrown. The view is typically part of the collection itself (created only once) and also an instance ofFastCollectionsupporting direct iterations.- Overrides:
unmodifiablein classFastCollection<E>- Returns:
- the unmodifiable view over this collection.
-
clear
public final void clear()
Description copied from class:FastCollectionRemoves all of the values from this collection (optional operation).- Specified by:
clearin interfacejava.util.Collection<E>- Specified by:
clearin interfacejava.util.Set<E>- Overrides:
clearin classFastCollection<E>
-
contains
public final boolean contains(java.lang.Object o)
Description copied from class:FastCollectionIndicates if this collection contains the specified value.- Specified by:
containsin interfacejava.util.Collection<E>- Specified by:
containsin interfacejava.util.Set<E>- Overrides:
containsin classFastCollection<E>- Parameters:
o- the value whose presence in this collection is to be tested.- Returns:
trueif this collection contains the specified value;falseotherwise.
-
remove
public final boolean remove(java.lang.Object o)
Description copied from class:FastCollectionRemoves the first occurrence in this collection of the specified value (optional operation).- Specified by:
removein interfacejava.util.Collection<E>- Specified by:
removein interfacejava.util.Set<E>- Overrides:
removein classFastCollection<E>- Parameters:
o- the value to be removed from this collection.- Returns:
trueif this collection contained the specified value;falseotherwise.
-
setValueComparator
public FastCollection<E> setValueComparator(FastComparator comparator)
Description copied from class:FastCollectionSets the comparator to use for value equality or ordering if the collection is ordered (e.g.FastTree).- Overrides:
setValueComparatorin classFastCollection<E>- Parameters:
comparator- the value comparator.- Returns:
this
-
reset
public void reset()
Description copied from interface:ReusableResets the internal state of this object to its default values.
-
head
public final FastCollection.Record head()
Description copied from class:FastCollectionReturns the head record of this collection; it is the record such ashead().getNext()holds the first collection value.- Specified by:
headin classFastCollection<E>- Returns:
- the head record.
-
tail
public final FastCollection.Record tail()
Description copied from class:FastCollectionReturns the tail record of this collection; it is the record such astail().getPrevious()holds the last collection value.- Specified by:
tailin classFastCollection<E>- Returns:
- the tail record.
-
valueOf
public final E valueOf(FastCollection.Record record)
Description copied from class:FastCollectionReturns the collection value for the specified record.- Specified by:
valueOfin classFastCollection<E>- Parameters:
record- the record whose current value is returned.- Returns:
- the current value.
-
delete
public final void delete(FastCollection.Record record)
Description copied from class:FastCollectionDeletes the specified record from this collection.Implementation must ensure that removing a record from the collection does not affect in any way the records preceding the record being removed (it might affect the next records though, e.g. in a list collection, the indices of the subsequent records will change).
- Specified by:
deletein classFastCollection<E>- Parameters:
record- the record to be removed.
-
-
DMelt 3.0 © DataMelt by jWork.ORG