Package net.cscott.jutil
Class PersistentSet<T>
java.lang.Object
net.cscott.jutil.PersistentSet<T>
- All Implemented Interfaces:
Iterable<T>
PersistentSet implements a persistent set, based on a
persistent randomized treap. Unlike the Sets returned
by PersistentSetFactory, PersistentSet
does not implement that standard Set API
but instead exposes the underlying functional operations.- Author:
- C. Scott Ananian <cananian@alumni.princeton.edu>
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an emptyPersistentSetwhose member objects will all implementComparable.PersistentSet(Comparator<T> c) Creates an emptyPersistentSetwhose member objects are ordered by the givenComparator. -
Method Summary
Modifier and TypeMethodDescriptionCreates and returns a newPersistentSetidentical to this one, except it containselement.addAll(PersistentSet<T> set) Add all the items in the given set to this set.asSet()Collections view of the set.clone()Cloning takes constant time, regardless of the size of the set.booleanDetermines if the given element belongs to this set.booleanisEmpty()Determines if thisPersistentSethas any members.iterator()Unmodifiable iterator.Make a newPersistentSetidentical to this one, except that it does not containelement.intsize()Count the number of elements in thisPersistentSet.toString()Human-readable representation of the set.Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
PersistentSet
public PersistentSet()Creates an emptyPersistentSetwhose member objects will all implementComparable. Note that good hashcode implementations for the member objects are still required. -
PersistentSet
Creates an emptyPersistentSetwhose member objects are ordered by the givenComparator. Note that good hashcode implementations for the member objects are still required.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Determines if thisPersistentSethas any members. -
size
public int size()Count the number of elements in thisPersistentSet. -
add
Creates and returns a newPersistentSetidentical to this one, except it containselement. -
contains
Determines if the given element belongs to this set. -
remove
Make a newPersistentSetidentical to this one, except that it does not containelement. -
addAll
Add all the items in the given set to this set. -
clone
Cloning takes constant time, regardless of the size of the set. -
toString
Human-readable representation of the set. -
iterator
Unmodifiable iterator. -
asSet
Collections view of the set.
-