final class Set[A] extends Serializable
Set is a mutable hash set, with open addressing and double hashing.
Set provides constant-time membership tests, and amortized constant-time addition and removal. One underlying array stores items, and another tracks which buckets are used and defined.
When the type A is known (or the caller is specialized on A), Set[A] will store the values in an unboxed array.
- Self Type
- Set[A]
- Alphabetic
- By Inheritance
- Set
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
&(rhs: Set[A]): Set[A]
Intersect this set with the rhs set.
Intersect this set with the rhs set.
This has the effect of removing any item not in rhs.
This is an O(m min n) operation, where m and n are the sizes of the lhs and rhs sets.
-
def
&=(rhs: Set[A]): Unit
Remove any member of this which is not in rhs.
Remove any member of this which is not in rhs.
This is an O(m min n) operation, where m and n are the sizes of the lhs and rhs sets.
-
def
++=(arr: Array[A]): Unit
Add every item in items to the set.
Add every item in items to the set.
This is an O(n) operation, where n is the size of items.
-
def
++=(buf: Buffer[A]): Unit
Add every item in items to the set.
Add every item in items to the set.
This is an O(n) operation, where n is the size of items.
-
def
++=(items: Iterable[A]): Unit
Add every item in items to the set.
Add every item in items to the set.
This is an O(n) operation, where n is the size of items.
-
def
+=(item: A): Boolean
Add item to the set.
Add item to the set.
Returns whether or not the item was added. If item was already in the set, this method will do nothing and return false.
On average, this is an amortized O(1) operation; the worst-case is O(n), which will occur when the set must be resized.
-
def
--(rhs: Set[A]): Set[A]
Create a new set with the elements of lhs that are not in rhs.
Create a new set with the elements of lhs that are not in rhs.
This is an O(n) operation, where n is the size of the set.
-
def
--=(buf: Buffer[A]): Unit
Remove the members of buf from the set.
Remove the members of buf from the set.
This is an O(n) operation, where n is the length of buf.
-
def
--=(arr: Array[A]): Unit
Remove the members of arr from the set.
Remove the members of arr from the set.
This is an O(n) operation, where n is the length of arr.
-
def
--=(items: Iterable[A]): Unit
Remove the members of items from the set.
Remove the members of items from the set.
This is an O(n) operation, where n is the length of items.
-
def
--=(rhs: Set[A]): Unit
Remove members of rhs from the set.
Remove members of rhs from the set.
This operation is an O(m min n) operation, where m and n are the sizes of the lhs and rhs sets.
-
final
def
-=(item: A): Boolean
Remove an item from the set.
Remove an item from the set.
Returns whether the item was originally in the set or not.
This is an amortized O(1) operation.
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
add(item: A): Boolean
Synonym for +=.
-
def
addAll(items: Array[A]): Unit
Synonym for ++=.
-
def
addAll(items: Buffer[A]): Unit
Synonym for ++=.
-
def
addAll(items: Iterable[A]): Unit
Synonym for ++=.
-
final
def
apply(item: A): Boolean
Return whether the item is found in the Set or not.
Return whether the item is found in the Set or not.
On average, this is an O(1) operation; the (unlikely) worst-case is O(n).
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
- var buckets: Array[Byte]
-
final
def
clear(): Unit1[A]
Clears the set's internal state.
Clears the set's internal state.
After calling this method, the set's state is identical to that obtained by calling Set.empty[A].
The previous arrays are not retained, and will become available for garbage collection. This method returns a null of type Unit1[A] to trigger specialization without allocating an actual instance.
This is an O(1) operation, but may generate a lot of garbage if the set was previously large.
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
compact(): Unit1[A]
Compacts the set's internal arrays to reduce memory usage.
Compacts the set's internal arrays to reduce memory usage.
This operation should be used if a set has been shrunk (e.g. through --=) and is not likely to grow again.
This method will shrink the set to the smallest possible size that allows it to be <66% full. It returns a null of type Unit1[A] to trigger specialization without allocating an actual instance.
This is an O(n) operation, where n it the set's size.
-
final
def
copy(): Set[A]
Make a (shallow) copy of this set.
Make a (shallow) copy of this set.
This method creates a copy of the set with the same structure. However, the actual elements will not be copied.
This is an O(n) operation.
-
def
count(p: (A) ⇒ Boolean): Int
Count how many elements of the set satisfy the predicate p.
Count how many elements of the set satisfy the predicate p.
This is an O(n) operation, where n is the size of the set.
- implicit val ct: ClassTag[A]
-
def
difference(rhs: Set[A]): Set[A]
This is a synonym for --.
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(that: Any): Boolean
Check if two Sets are equal.
Check if two Sets are equal.
Equal means the sets have the same type (which is checked using the ClassTag instances) and the same contents.
Comparing Sets with any of Scala's collection types will return false.
On average this is an O(n) operation. In some cases a false result can be returned more quickly.
- Definition Classes
- Set → AnyRef → Any
-
def
exists(p: (A) ⇒ Boolean): Boolean
Determine if any member of the set satisifes the predicate p.
Determine if any member of the set satisifes the predicate p.
This is an O(n) operation, where n is the size of the set. However, it will return as soon as a true result is obtained.
-
def
filterSelf(p: (A) ⇒ Boolean): Unit
Remove any member of the set that does not satisfy p.
Remove any member of the set that does not satisfy p.
After this method, all membrers of the set will satisfy p.
This is an O(n) operation, where n is the size of the set.
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
find(p: (A) ⇒ Boolean): Option[A]
Find a member of the set that satisfies the predicate p.
Find a member of the set that satisfies the predicate p.
The method returns Some(item) if item satisfies p, and None if none of set's elements satisfy p. Since Set is not ordered, if multiple elements satisfy the predicate there is no guarantee which one wil be found.
This is an O(n) operation, where n is the size of the set. However, it will return as soon as a member satisfying the predicate is found.
-
def
findAll(p: (A) ⇒ Boolean): Set[A]
Create a new set containing all the members of this set that satisfy p.
Create a new set containing all the members of this set that satisfy p.
This is an O(n) operation, where n is the size of the set.
-
def
fold[B](init: B)(f: (B, A) ⇒ B): B
Fold the set's values into a single value, using the provided initial state and combining function f.
Fold the set's values into a single value, using the provided initial state and combining function f.
Like foreach, fold makes no guarantees about the order that elements will be reached.
This is an O(n) operation, where n is the size of the set.
-
def
forall(p: (A) ⇒ Boolean): Boolean
Determine if every member of the set satisifes the predicate p.
Determine if every member of the set satisifes the predicate p.
This is an O(n) operation, where n is the size of the set. However, it will return as soon as a false result is obtained.
-
def
foreach(f: (A) ⇒ Unit): Unit
Loop over the set's contents, appying f to each element.
Loop over the set's contents, appying f to each element.
There is no guaranteed order that the set's elements will be traversed in, so use of foreach should not rely on a particular order.
This is an O(n) operation, where n is the length of the buffer.
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
grow(): Unit1[A]
Grow the underlying array to best accomodate the set's size.
Grow the underlying array to best accomodate the set's size.
To preserve hashing access speed, the set's size should never be more than 66% of the underlying array's size. When this size is reached, the set needs to be updated (using this method) to have a larger array.
The underlying array's size must always be a multiple of 2, which means this method grows the array's size by 2x (or 4x if the set is very small). This doubling helps amortize the cost of resizing, since as the set gets larger growth will happen less frequently. This method returns a null of type Unit1[A] to trigger specialization without allocating an actual instance.
Growing is an O(n) operation, where n is the set's size.
-
def
hashCode(): Int
Hash the contents of the set to an Int value.
Hash the contents of the set to an Int value.
By xor'ing all the set's values together, we can be sure that sets with the same contents will have the same hashCode regardless of the order those elements appear.
This is an O(n) operation.
- Definition Classes
- Set → AnyRef → Any
-
def
intersection(rhs: Set[A]): Set[A]
Synonym for &.
-
final
def
isEmpty: Boolean
Return true if the Set is empty, false otherwise.
Return true if the Set is empty, false otherwise.
This is an O(1) operation.
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- var items: Array[A]
-
def
iterator(): Iterator[A]
Return an iterator over this set's contents.
Return an iterator over this set's contents.
This method does not do any copying or locking. Thus, if the set is modified while the iterator is "live" the results will be undefined and probably bad. Also, since sets are not ordered, there is no guarantee elements will be returned in a particular order.
Use this.copy.iterator to get a "clean" iterator if needed.
Creating the iterator is an O(1) operation.
- var len: Int
- var limit: Int
-
def
map[B](f: (A) ⇒ B)(implicit arg0: ClassTag[B]): Set[B]
Translate this Set into another Set using the given function f.
Translate this Set into another Set using the given function f.
Note that the resulting set may be smaller than this set, if f is not a one-to-one function (an injection).
This is an O(n) operation, where n is the size of the set.
- var mask: Int
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
nonEmpty: Boolean
Return true if the Set is non-empty, false otherwise.
Return true if the Set is non-empty, false otherwise.
This is an O(1) operation.
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
partition(p: (A) ⇒ Boolean): (Set[A], Set[A])
Partition this set into two new sets, the first consisting of all members that fail to satisfy the predicate p, and the second for all those that do satisfy the predicate.
Partition this set into two new sets, the first consisting of all members that fail to satisfy the predicate p, and the second for all those that do satisfy the predicate.
This is an O(n) operation, where n is the size of the set.
-
def
remove(item: A): Boolean
Synonym for -=.
-
final
def
size: Int
Return the size of this Set as an Int.
Return the size of this Set as an Int.
Since Sets use arrays, their size is limited to what a 32-bit signed integer can represent.
This is an O(1) operation.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toArray(): Array[A]
Copy the set's elements into an array.
Copy the set's elements into an array.
This is an O(n) operation, where n is the size of the set.
-
def
toBuffer(): Buffer[A]
Copy the set's elements into a buffer.
Copy the set's elements into a buffer.
This is an O(n) operation, where n is the size of the set.
-
def
toIterable(): Iterable[A]
Wrap this set in an Iterable[A] instance.
Wrap this set in an Iterable[A] instance.
This method exists as a cheap way to get compatibility with Scala collections without copying/conversion. Note that since Scala collections are not specialized, using this iterable will box values as they are accessed (although the underlying set will still be unboxed).
Like iterator, this method directly wraps the set. Thus, you should not mutate the set while using the resulting iterable, or risk corruption and undefined behavior.
To get a "safe" value that is compatible with Scala collections, consider using toScalaSet.
Creating the Iterable[A] instance is an O(1) operation.
-
def
toMap[B](f: (A) ⇒ B)(implicit arg0: ClassTag[B]): Map[A, B]
Copy the sets contents into a Map.
Copy the sets contents into a Map. The elements of the set will be keys, and each keys' value will be determined with the provided function.
This is an O(n) operation, where n is the size of the set.
-
def
toScalaSet(): scala.collection.immutable.Set[A]
Create an immutable instance of scala's Set[A].
Create an immutable instance of scala's Set[A].
This method copies the elements into a new instance which is compatible with Scala's collections and Set[A] type.
This is an O(n) operation, where n is the size of the set.
-
def
toSortedBuffer(implicit o: Order[A]): Buffer[A]
Copy the set's elements into a sorted buffer.
Copy the set's elements into a sorted buffer.
Elements will be arranged from lowest-to-highest.
This is an O(n) operation, where n is the size of the set.
-
def
toString(): String
Return a string representation of the contents of the set.
Return a string representation of the contents of the set.
This is an O(n) operation.
- Definition Classes
- Set → AnyRef → Any
-
def
union(rhs: Set[A]): Set[A]
Synonym for |.
-
final
def
update(item: A, b: Boolean): Boolean
Set/unset the value of item in the set.
Set/unset the value of item in the set.
Like += and -= this is an amortized O(1) operation.
- var used: Int
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
|(rhs: Set[A]): Set[A]
Return new set which is the union of lhs and rhs.
Return new set which is the union of lhs and rhs.
The new set will contain all members of lhs and rhs.
This is an O(m max n) operation, where m and n are the sizes of the sets.
-
def
|=(rhs: Set[A]): Unit
Union this set with the rhs set.
Union this set with the rhs set.
This has the effect of adding all members of rhs to lhs.
This is an O(n) operation, where n is rhs.size.