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]
Linear Supertypes
Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Set
  2. Serializable
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Set(as: Array[A], bs: Array[Byte], n: Int, u: Int)(implicit ct: ClassTag[A])
    Attributes
    protected[debox]

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. 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.

  12. 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.

  13. 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.

  14. 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.

  15. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  16. final def add(item: A): Boolean

    Synonym for +=.

  17. def addAll(items: Array[A]): Unit

    Synonym for ++=.

  18. def addAll(items: Buffer[A]): Unit

    Synonym for ++=.

  19. def addAll(items: Iterable[A]): Unit

    Synonym for ++=.

  20. 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).

  21. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  22. var buckets: Array[Byte]
  23. 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.

  24. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  25. 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.

  26. 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.

  27. 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.

  28. implicit val ct: ClassTag[A]
  29. def difference(rhs: Set[A]): Set[A]

    This is a synonym for --.

  30. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  31. 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
  32. 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.

  33. 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.

  34. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  35. 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.

  36. 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.

  37. 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.

  38. 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.

  39. 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.

  40. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  41. 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.

  42. 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
  43. def intersection(rhs: Set[A]): Set[A]

    Synonym for &.

  44. 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.

  45. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  46. var items: Array[A]
  47. 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.

  48. var len: Int
  49. var limit: Int
  50. 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.

  51. var mask: Int
  52. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  53. 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.

  54. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  55. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  56. 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.

  57. def remove(item: A): Boolean

    Synonym for -=.

  58. 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.

  59. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  60. 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.

  61. 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.

  62. 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.

  63. 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.

  64. 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.

  65. 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.

  66. 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
  67. def union(rhs: Set[A]): Set[A]

    Synonym for |.

  68. 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.

  69. var used: Int
  70. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  71. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  72. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  73. 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.

  74. 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.

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped