Package org.organicdesign.fp.collections
Class PersistentHashSet<E>
- java.lang.Object
-
- org.organicdesign.fp.collections.AbstractUnmodIterable<T>
-
- org.organicdesign.fp.collections.AbstractUnmodSet<E>
-
- org.organicdesign.fp.collections.PersistentHashSet<E>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.Set<E>,BaseSet<E>,ImSet<E>,Sized,UnmodCollection<E>,UnmodIterable<E>,UnmodSet<E>,Transformable<E>
public class PersistentHashSet<E> extends AbstractUnmodSet<E> implements ImSet<E>, java.io.Serializable
A wrapper that turns a PersistentTreeMap into a set. This file is a derivative work based on a Clojure collection licensed under the Eclipse Public License 1.0 Copyright Rich Hickey- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPersistentHashSet.MutableHashSet<E>
-
Field Summary
Fields Modifier and Type Field Description static PersistentHashSet<java.lang.Object>EMPTY
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontains(java.lang.Object key)Returns true if the set contains the given item.static <E> PersistentHashSet<E>empty()static <E> PersistentHashSet<E>empty(Equator<E> eq)static <E> PersistentHashSet.MutableHashSet<E>emptyMutable()Works around some type inference limitations of Java 8.static <E> PersistentHashSet.MutableHashSet<E>emptyMutable(Equator<E> eq)Works around some type inference limitations of Java 8.Equator<E>equator()Returns the Equator used by this set for equals comparisons and hashCodesUnmodIterator<E>iterator()Iterates over contents with no guarantees about their ordering.PersistentHashSet.MutableHashSet<E>mutable()Returns a mutable version of this immutable set.static <E> PersistentHashSet<E>of(java.lang.Iterable<E> elements)Returns a new PersistentHashSet of the values.static <E> PersistentHashSet<E>ofEq(Equator<E> eq, java.lang.Iterable<E> init)static <E> PersistentHashSet<E>ofMap(ImMap<E,?> map)PersistentHashSet<E>put(E o)Adds an element, returning a modified version of the set (leaving the original set unchanged).intsize()Returns the number of items in this collection or iterable.PersistentHashSet<E>without(E key)Removes this key from the set-
Methods inherited from class org.organicdesign.fp.collections.AbstractUnmodSet
equals
-
Methods inherited from class org.organicdesign.fp.collections.AbstractUnmodIterable
hashCode, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.organicdesign.fp.xform.Transformable
toImList, toImMap, toImRrbt, toImSet, toImSortedMap, toImSortedSet, toMutableList, toMutableMap, toMutableRrbt, toMutableSet, toMutableSortedMap, toMutableSortedSet
-
-
-
-
Field Detail
-
EMPTY
public static final PersistentHashSet<java.lang.Object> EMPTY
-
-
Method Detail
-
empty
public static <E> PersistentHashSet<E> empty()
-
emptyMutable
public static <E> PersistentHashSet.MutableHashSet<E> emptyMutable()
Works around some type inference limitations of Java 8.
-
empty
public static <E> PersistentHashSet<E> empty(Equator<E> eq)
-
emptyMutable
public static <E> PersistentHashSet.MutableHashSet<E> emptyMutable(Equator<E> eq)
Works around some type inference limitations of Java 8.
-
of
public static <E> PersistentHashSet<E> of(java.lang.Iterable<E> elements)
Returns a new PersistentHashSet of the values. The vararg version of this method isStaticImports.set(Object...)If the input contains duplicate elements, later values overwrite earlier ones.- Parameters:
elements- The items to put into a vector.- Returns:
- a new PersistentHashSet of the given elements.
-
ofEq
public static <E> PersistentHashSet<E> ofEq(Equator<E> eq, java.lang.Iterable<E> init)
-
ofMap
public static <E> PersistentHashSet<E> ofMap(ImMap<E,?> map)
-
contains
public boolean contains(java.lang.Object key)
Description copied from interface:UnmodSetReturns true if the set contains the given item. This is the defining method of a set. Sets have to override this because the default implementation in UnmodCollection is O(n) whereas a sorted set should be O(log n) or O(1).
-
equator
public Equator<E> equator()
Returns the Equator used by this set for equals comparisons and hashCodes
-
without
public PersistentHashSet<E> without(E key)
Description copied from interface:ImSetRemoves this key from the set
-
put
public PersistentHashSet<E> put(E o)
Description copied from interface:ImSetAdds an element, returning a modified version of the set (leaving the original set unchanged). If the element already exists in this set, the new value overwrites the old one. If the new element is the same as an old element (based on the address of that item in memory, not an equals test), the old set is returned unchanged.
-
iterator
public UnmodIterator<E> iterator()
Description copied from interface:UnmodSetIterates over contents with no guarantees about their ordering. An unmodifiable iterator A one-time use, mutable, not-thread-safe way to get each value of the underling collection in turn. I experimented with various thread-safe alternatives, but the JVM is optimized around iterators so this is the lowest common denominator of collection iteration, even though iterators are inherently mutable.- Specified by:
iteratorin interfacejava.util.Collection<E>- Specified by:
iteratorin interfacejava.lang.Iterable<E>- Specified by:
iteratorin interfacejava.util.Set<E>- Specified by:
iteratorin interfaceUnmodCollection<E>- Specified by:
iteratorin interfaceUnmodIterable<E>- Specified by:
iteratorin interfaceUnmodSet<E>
-
size
public int size()
Description copied from interface:SizedReturns the number of items in this collection or iterable.
-
-