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:
Serializable
,Iterable<E>
,Collection<E>
,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>, 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 class
PersistentHashSet.MutHashSet<E>
-
Nested classes/interfaces inherited from interface org.organicdesign.fp.collections.UnmodIterable
UnmodIterable.UnIterable
-
-
Field Summary
Fields Modifier and Type Field Description static PersistentHashSet<Object>
EMPTY
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
contains(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.MutHashSet<E>
emptyMutable()
Works around some type inference limitations of Java 8.static <E> PersistentHashSet.MutHashSet<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 hashCodes@NotNull UnmodIterator<E>
iterator()
Iterates over contents with no guarantees about their ordering.PersistentHashSet.MutHashSet<E>
mutable()
Returns a mutable version of this immutable set.static <E> PersistentHashSet<E>
of(Iterable<E> elements)
Returns a new PersistentHashSet of the values.static <E> PersistentHashSet<E>
ofEq(Equator<E> eq, Iterable<E> init)
static <E> PersistentHashSet<E>
ofMap(ImMap<E,?> map)
@NotNull PersistentHashSet<E>
put(E o)
Adds an element, returning a modified version of the set (leaving the original set unchanged).int
size()
Returns the number of items in this collection or iterable.@NotNull 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 java.util.Collection
parallelStream, stream, toArray
-
Methods inherited from interface java.util.Set
equals, hashCode, spliterator
-
Methods inherited from interface org.organicdesign.fp.xform.Transformable
any, toImList, toImMap, toImRrbt, toImSet, toImSortedMap, toImSortedSet, toMutList, toMutMap, toMutRrbt, toMutSet, toMutSortedMap, toMutSortedSet
-
-
-
-
Field Detail
-
EMPTY
public static final PersistentHashSet<Object> EMPTY
-
-
Method Detail
-
empty
public static <E> PersistentHashSet<E> empty()
-
emptyMutable
public static <E> PersistentHashSet.MutHashSet<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.MutHashSet<E> emptyMutable(Equator<E> eq)
Works around some type inference limitations of Java 8.
-
of
public static <E> PersistentHashSet<E> of(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, Iterable<E> init)
-
ofMap
public static <E> PersistentHashSet<E> ofMap(ImMap<E,?> map)
-
contains
public boolean contains(Object key)
Description copied from interface:UnmodSet
Returns 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
@NotNull public @NotNull PersistentHashSet<E> without(E key)
Description copied from interface:ImSet
Removes this key from the set
-
put
@NotNull public @NotNull PersistentHashSet<E> put(E o)
Description copied from interface:ImSet
Adds 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
@NotNull public @NotNull UnmodIterator<E> iterator()
Description copied from interface:UnmodSet
Iterates 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.
-
size
public int size()
Description copied from interface:Sized
Returns the number of items in this collection or iterable.
-
-