|
Scala Library
|
|
scala/collection/SetLike.scala]
trait
SetLike[A, +This <: SetLike[A, This] with Set[A]]
extends IterableLike[A, This] with Addable[A, This] with Subtractable[A, This]
A generic template for sets of type A.
To implement a concrete set, you need to provide implementations of the
following methods (where This is the type of the set in
question):
def contains(key: A): Boolean
def iterator: Iterator[A]
def +(elem: A): This
def -(elem: A): This
If you wish that methods like, take, drop,
filter return the same kind of set, you should also override:
def empty: This
It is also good idea to override methods foreach and
size for efficiency.
| Method Summary | |
def
|
&
(that : Set[A]) : This
Returns a new set consisting of all elements that are both in the current
set and in the argument set.
|
def
|
&~
(that : Set[A]) : This
The difference of this set and the given set
that. |
def
|
**
(that : Set[A]) : This
This method is an alias for
intersect.
It computes an intersection with set that.
It removes all the elements that are not present in that. |
abstract def
|
+
(elem : A) : This
Creates a new set with an additional element, unless the element is
already present.
|
abstract def
|
-
(elem : A) : This
Creates a new set with given element removed from this set, unless the
element is not present.
|
def
|
apply
(elem : A) : Boolean
This method allows sets to be interpreted as predicates.
It returns
true, iff this set contains element
elem. |
abstract def
|
contains
(elem : A) : Boolean
Checks if this set contains element
elem. |
def
|
diff
(that : Set[A]) : This
The difference of this set and the given set
that. |
abstract def
|
empty : This |
override def
|
equals
(that : Any) : Boolean
Compares this set with another object and returns true, iff the
other object is also a set which contains the same elements as
this set.
|
override def
|
hashCode
: Int
Returns a hash code value for the object.
|
def
|
intersect
(that : Set[A]) : This
Returns a new set consisting of all elements that are both in the current
set and in the argument set.
|
override def
|
isEmpty
: Boolean
Checks if this set is empty.
|
protected[this] override def
|
newBuilder
: Builder[A, This]
A common implementation of
newBuilder for all sets in terms
of empty. Overridden for mutable sets in
mutable.SetLike. |
override def
|
stringPrefix
: java.lang.String
Defines the prefix of this object's
toString representation. |
def
|
subsetOf
(that : Set[A]) : Boolean
Checks if this set is a subset of set
that. |
override def
|
toString
: java.lang.String
Need to override string, so that it's not the Function1's string that gets mixed in.
|
def
|
union
(that : Set[A]) : This
The union of this set and the given set
that. |
def
|
|
(that : Set[A]) : This
The union of this set and the given set
that. |
| Methods inherited from Subtractable | |
| -, --, -- |
| Methods inherited from Addable | |
| +, ++, ++ |
| Methods inherited from IterableLike | |
| iterator (abstract), thisCollection, toCollection, elements, foreach, forall, exists, find, foldRight, reduceRight, toIterable, head, take, slice, takeWhile, takeRight, dropRight, copyToArray, zip, zipAll, zipWithIndex, sameElements, toStream, canEqual, view, view, first, firstOption, projection |
| Methods inherited from TraversableLike | |
| repr, nonEmpty, size, hasDefiniteSize, ++, ++, map, flatMap, filter, filterNot, partialMap, remove, partition, groupBy, count, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, sum, product, min, max, headOption, tail, last, lastOption, init, drop, dropWhile, span, splitAt, copyToBuffer, copyToArray, toArray, toList, toSeq, toIndexedSeq, toSet, mkString, mkString, mkString, addString, addString, addString, withFilter |
| Methods inherited from AnyRef | |
| getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized |
| Methods inherited from Any | |
| ==, !=, isInstanceOf, asInstanceOf |
| Method Details |
abstract
def
empty : This
newBuilder for all sets in terms
of empty. Overridden for mutable sets in
mutable.SetLike.elem.elem - the element to check for membership.true iff elem is contained in this set.elem - the element to be addedelem - the element to be removedoverride
def
isEmpty : Boolean
true iff there is no element in the set.true, iff this set contains element
elem.elem - the element to check for membership.true iff elem is contained in this set.that - the set to intersect with.that - the set to intersect with.intersect.
def
**(that : Set[A]) : This
intersect.
It computes an intersection with set that.
It removes all the elements that are not present in that.that - the set to intersect withthat.that - the set of elements to addthat.that.that - the set of elements to addthat.union.that.that - the set of elements to removethat.that.that - the set of elements to removethat.diff.that.that - another set.true iff the other set is a superset of this set.
todo: rename to isSubsetOfoverride
def
stringPrefix : java.lang.String
toString representation.override
def
toString : java.lang.String
override
def
hashCode : Int
The default hashing algorithm is platform dependent.
Note that it is allowed for two objects to have identical hash
codes (o1.hashCode.equals(o2.hashCode)) yet not be
equal (o1.equals(o2) returns false). A
degenerate implementation could always return 0.
However, it is required that if two objects are equal
(o1.equals(o2) returns true) that they
have identical hash codes
(o1.hashCode.equals(o2.hashCode)). Therefore, when
overriding this method, be sure to verify that the behavior is
consistent with the equals method.
that - the other objecttrue iff this set and the other set contain the same elements.|
Scala Library
|
|