JUtil

net.cscott.jutil
Class PersistentSet<T>

java.lang.Object
  extended by net.cscott.jutil.PersistentSet<T>
All Implemented Interfaces:
Iterable<T>

public class PersistentSet<T>
extends Object
implements 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.

Version:
$Id: PersistentSet.java,v 1.8 2006-10-30 19:58:06 cananian Exp $
Author:
C. Scott Ananian

Constructor Summary
PersistentSet()
          Creates an empty PersistentSet whose member objects will all implement Comparable.
PersistentSet(Comparator<T> c)
          Creates an empty PersistentSet whose member objects are ordered by the given Comparator.
 
Method Summary
 PersistentSet<T> add(T element)
          Creates and returns a new PersistentSet identical to this one, except it contains element.
 PersistentSet<T> addAll(PersistentSet<T> set)
          Add all the items in the given set to this set.
 Set<T> asSet()
          Collections view of the set.
 PersistentSet<T> clone()
          Cloning takes constant time, regardless of the size of the set.
 boolean contains(T element)
          Determines if the given element belongs to this set.
 boolean isEmpty()
          Determines if this PersistentSet has any members.
 Iterator<T> iterator()
          Unmodifiable iterator.
 PersistentSet<T> remove(T element)
          Make a new PersistentSet identical to this one, except that it does not contain element.
 int size()
          Count the number of elements in this PersistentSet.
 String toString()
          Human-readable representation of the set.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PersistentSet

public PersistentSet()
Creates an empty PersistentSet whose member objects will all implement Comparable. Note that good hashcode implementations for the member objects are still required.


PersistentSet

public PersistentSet(Comparator<T> c)
Creates an empty PersistentSet whose member objects are ordered by the given Comparator. Note that good hashcode implementations for the member objects are still required.

Method Detail

isEmpty

public boolean isEmpty()
Determines if this PersistentSet has any members.


size

public int size()
Count the number of elements in this PersistentSet.


add

public PersistentSet<T> add(T element)
Creates and returns a new PersistentSet identical to this one, except it contains element.


contains

public boolean contains(T element)
Determines if the given element belongs to this set.


remove

public PersistentSet<T> remove(T element)
Make a new PersistentSet identical to this one, except that it does not contain element.


addAll

public PersistentSet<T> addAll(PersistentSet<T> set)
Add all the items in the given set to this set.


clone

public PersistentSet<T> clone()
Cloning takes constant time, regardless of the size of the set.

Overrides:
clone in class Object

toString

public String toString()
Human-readable representation of the set.

Overrides:
toString in class Object

iterator

public Iterator<T> iterator()
Unmodifiable iterator.

Specified by:
iterator in interface Iterable<T>

asSet

public Set<T> asSet()
Collections view of the set.


JUtil

Copyright (c) 2006 C. Scott Ananian