Package fj.data
Class Set<A>
java.lang.Object
fj.data.Set<A>
- All Implemented Interfaces:
Iterable<A>
Provides an in-memory, immutable set, implemented as a red/black tree.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <A> Set
<A> Return the elements of the given iterator as a set.private static <A> Set
<A> final <B> Set
<B> Binds the given function across this set.(package private) abstract Set.Color
color()
delete()
First-class deletion function.Deletes the given element from this set.static <A> Set
<A> The empty set.final boolean
Filters elements from this set by returning only elements which producetrue
when the given function is applied to them.final <B> B
Folds this Set using the given monoid.final <B> B
foldMapRight
(F<A, B> f, Monoid<B> m) Folds this Set from the right using the given monoid.final int
hashCode()
(package private) abstract A
head()
insert()
First-class insertion function.Inserts the given element into this set.A first class function forintersect(Set)
.Remove all elements from this set that do not occur in the given set.final boolean
isEmpty()
private boolean
isTR()
static <A> Set
<A> iterableSet
(Ord<A> o, Iterable<A> as) Return the elements of the given iterable as a set.iterator()
Returns an iterator over this set.static <A> Set
<A> iteratorSet
(Ord<A> o, Iterator<A> as) Return the elements of the given iterator as a set.static <A> Set
<A> Join a set of sets into a single set.l()
Find element equal to the given one.Find smallest element greater or equal to the given one.Find smallest element greater than the given one.Find largest element smaller or equal to the given one.Find largest element smaller than the given one.final <B> Set
<B> Maps the given function across this set.max()
member()
First-class membership check.final boolean
Checks if the given element is a member of this set.min()
minus()
A first class function forminus(Set)
.Remove all elements from this set that occur in the given set.ord()
Returns the order of this Set.r()
static <A> Set
<A> Constructs a set from the given elements.static <A> Set
<A> Returns a set with a single element.final int
size()
Returns the size of this set.Splits this set at the given element.final boolean
Returns true if this set is a subset of the given set.Returns a java.util.HashSet representation of this set.Returns a java.util.List representation of this set.Returns a java.util.Set representation of this set.Returns a java.util.TreeSet representation of this set.toList()
Returns a list representation of this set.Returns a list representation of this set in reverse order.toStream()
Returns a stream representation of this set.Returns a stream representation of this set in reverse order.final String
toString()
private static <A> Set.Tree
<A> union()
A first class function forunion(Set)
.Add all the elements of the given set to this set.Updates, with the given function, the first element in the set that is equal to the given element, according to the order.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
ord
-
-
Constructor Details
-
Set
-
-
Method Details
-
isEmpty
public final boolean isEmpty() -
color
-
l
-
head
-
r
-
ord
Returns the order of this Set.- Returns:
- the order of this Set.
-
update
Updates, with the given function, the first element in the set that is equal to the given element, according to the order.- Parameters:
a
- An element to replace.f
- A function to transforms the found element.- Returns:
- A pair of: (1) True if an element was found that matches the given element, otherwise false. (2) A new set with the given function applied to the first set element that was equal to the given element.
-
tryUpdate
-
empty
The empty set.- Parameters:
ord
- An order for the type of elements.- Returns:
- the empty set.
-
equals
-
hashCode
public final int hashCode() -
toString
-
member
Checks if the given element is a member of this set.- Parameters:
x
- An element to check for membership in this set.- Returns:
- true if the given element is a member of this set.
-
member
First-class membership check.- Returns:
- A function that returns true if the given element if a member of the given set.
-
insert
Inserts the given element into this set.- Parameters:
x
- An element to insert into this set.- Returns:
- A new set with the given element inserted.
-
insert
First-class insertion function.- Returns:
- A function that inserts a given element into a given set.
-
ins
-
makeBlack
-
tr
-
balance
-
isTR
private boolean isTR() -
iterator
Returns an iterator over this set. -
single
Returns a set with a single element.- Parameters:
o
- An order for the type of element.a
- An element to put in a set.- Returns:
- A new set with the given element in it.
-
map
Maps the given function across this set.- Parameters:
o
- An order for the elements of the new set.f
- A function to map across this set.- Returns:
- The set of the results of applying the given function to the elements of this set.
-
foldMap
Folds this Set using the given monoid.- Parameters:
f
- A transformation from this Set's elements, to the monoid.m
- The monoid to fold this Set with.- Returns:
- The result of folding the Set with the given monoid.
-
foldMapRight
Folds this Set from the right using the given monoid.- Parameters:
f
- A transformation from this Set's elements, to the monoid.m
- The monoid to fold this Set with.- Returns:
- The result of folding the Set from the right with the given monoid.
-
toList
Returns a list representation of this set.- Returns:
- a list representation of this set.
-
toJavaSet
Returns a java.util.Set representation of this set.- Returns:
- a java.util.Set representation of this set.
-
toJavaHashSet
Returns a java.util.HashSet representation of this set.- Returns:
- a java.util.HashSet representation of this set.
-
toJavaTreeSet
Returns a java.util.TreeSet representation of this set.- Returns:
- a java.util.TreeSet representation of this set.
-
toJavaList
Returns a java.util.List representation of this set.- Returns:
- a java.util.List representation of this set.
-
toListReverse
Returns a list representation of this set in reverse order.- Returns:
- a list representation of this set in reverse order.
-
toStream
Returns a stream representation of this set.- Returns:
- a stream representation of this set.
-
toStreamReverse
Returns a stream representation of this set in reverse order.- Returns:
- a stream representation of this set in reverse order.
-
bind
Binds the given function across this set.- Parameters:
o
- An order for the elements of the target set.f
- A function to bind across this set.- Returns:
- A new set after applying the given function and joining the resulting sets.
-
union
Add all the elements of the given set to this set.- Parameters:
s
- A set to add to this set.- Returns:
- A new set containing all elements of both sets.
-
union
A first class function forunion(Set)
.- Returns:
- A function that adds all the elements of one set to another set.
- See Also:
-
filter
Filters elements from this set by returning only elements which producetrue
when the given function is applied to them.- Parameters:
f
- The predicate function to filter on.- Returns:
- A new set whose elements all match the given predicate.
-
delete
Deletes the given element from this set.- Parameters:
a
- an element to remove.- Returns:
- A new set containing all the elements of this set, except the given element.
-
delete
First-class deletion function.- Returns:
- A function that deletes a given element from a given set.
-
intersect
Remove all elements from this set that do not occur in the given set.- Parameters:
s
- A set of elements to retain.- Returns:
- A new set which is the intersection of this set and the given set.
-
intersect
A first class function forintersect(Set)
.- Returns:
- A function that intersects two given sets.
- See Also:
-
minus
Remove all elements from this set that occur in the given set.- Parameters:
s
- A set of elements to delete.- Returns:
- A new set which contains only the elements of this set that do not occur in the given set.
-
minus
A first class function forminus(Set)
.- Returns:
- A function that removes all elements of one set from another set.
- See Also:
-
min
-
max
-
size
public final int size()Returns the size of this set.- Returns:
- The number of elements in this set.
-
split
Splits this set at the given element. Returns a product-3 of:- A set containing all the elements of this set which are less than the given value.
- An option of a value equal to the given value, if one was found in this set, otherwise None.
- A set containing all the elements of this set which are greater than the given value.
- Parameters:
a
- A value at which to split this set.- Returns:
- Two sets and an optional value, where all elements in the first set are less than the given value and all the elements in the second set are greater than the given value, and the optional value is the given value if found, otherwise None.
-
lookup
Find element equal to the given one.- Parameters:
a
- An element to compare with.- Returns:
- Some element in this set equal to the given one, or None.
-
lookupLT
Find largest element smaller than the given one.- Parameters:
a
- An element to compare with.- Returns:
- Some largest element in this set smaller than the given one, or None.
-
lookupGT
Find smallest element greater than the given one.- Parameters:
a
- An element to compare with.- Returns:
- Some smallest element in this set greater than the given one, or None.
-
lookupLE
Find largest element smaller or equal to the given one.- Parameters:
a
- An element to compare with.- Returns:
- Some largest element in this set smaller or equal to the given one, or None.
-
lookupGE
Find smallest element greater or equal to the given one.- Parameters:
a
- An element to compare with.- Returns:
- Some smallest element in this set greater or equal to the given one, or None.
-
subsetOf
Returns true if this set is a subset of the given set.- Parameters:
s
- A set which is a superset of this set if this method returns true.- Returns:
- true if this set is a subset of the given set.
-
join
Join a set of sets into a single set.- Parameters:
o
- An order for the elements of the new set.s
- A set of sets.- Returns:
- A new set which is the join of the given set of sets.
-
iterableSet
Return the elements of the given iterable as a set.- Parameters:
o
- An order for the elements of the new set.as
- An iterable of elements to add to a set.- Returns:
- A new set containing the elements of the given iterable.
-
iteratorSet
Return the elements of the given iterator as a set.- Parameters:
o
- An order for the elements of the new set.as
- An iterator of elements to add to a set.- Returns:
- A new set containing the elements of the given iterator.
-
arraySet
Return the elements of the given iterator as a set.- Parameters:
o
- An order for the elements of the new set.as
- An iterator of elements to add to a set.- Returns:
- A new set containing the elements of the given iterator.
-
set
Constructs a set from the given elements.- Parameters:
o
- An order for the elements of the new set.as
- The elements to add to a set.- Returns:
- A new set containing the elements of the given iterable.
-