Packages

sealed abstract class BitSet extends AnyRef

A fast, immutable BitSet.

This implementation is taken from cats-collections. https://github.com/typelevel/cats-collections/blob/0336992942aba9aba4a322b629447fcabe251920/core/src/main/scala/cats/collections/BitSet.scala

A Bitset is a specialized type of set that tracks the Int values it contains: for each integer value, a BitSet uses a single bit to track whether the value is present (1) or absent (0). Bitsets are often sparse, since "missing" bits can be assumed to be zero.

Unlike scala's default immutable this BitSet does not do a full copy on each added value.

Internally the implementation is a tree. Each leaf uses an Array[Long] value to hold up to 2048 bits, and each branch uses an Array[BitSet] to hold up to 32 subtrees (null subtrees are treated as empty).

Bitset treats the values it stores as 32-bit unsigned values, which is relevant to the internal addressing methods as well as the order used by iterator.

The benchmarks suggest this bitset is MUCH faster than Scala's built-in bitset for cases where you may need many modifications and merges, (for example in a BloomFilter).

Self Type
BitSet
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. BitSet
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Abstract Value Members

  1. abstract def &(rhs: BitSet): BitSet

    Return the intersection of two bitsets as a new immutable bitset.

    Return the intersection of two bitsets as a new immutable bitset.

    The resulting bitset will only contain a value if that value is present in both input bitsets.

  2. abstract def +(n: Int): BitSet

    Return a bitset that contains n and whose other values are identical to this one's.

    Return a bitset that contains n and whose other values are identical to this one's. If this bitset already contains n then this method does nothing.

  3. abstract def -(n: Int): BitSet

    Return a bitset that does not contain n and whose other values are identical to this one's.

    Return a bitset that does not contain n and whose other values are identical to this one's. If this bitset does not contain n then this method does nothing.

  4. abstract def --(rhs: BitSet): BitSet

    Return this bitset minus the bits contained in the other bitset as a new immutable bitset.

    Return this bitset minus the bits contained in the other bitset as a new immutable bitset.

    The resulting bitset will contain exactly those values which do appear in the left-hand side but do not appear in the right-hand side.

    If the bitsets do not intersect, the left-hand side will be returned.

  5. abstract def ^(rhs: BitSet): BitSet

    Return the exclusive-or of two bitsets as a new immutable bitset.

  6. abstract def apply(n: Int): Boolean

    Look for a particular value in the bitset.

    Look for a particular value in the bitset.

    Returns whether this value's bit is set.

  7. abstract def intersects(rhs: BitSet): Boolean

    Returns whether the two bitsets intersect or not.

    Returns whether the two bitsets intersect or not.

    Equivalent to (x & y).nonEmpty but faster.

  8. abstract def isEmpty: Boolean

    Returns false if this bitset contains values, true otherwise.

  9. abstract def iterator: Iterator[Int]

    Iterate across all values in the bitset.

    Iterate across all values in the bitset.

    Values in the iterator will be seen in "unsigned order" (e.g. if present, -1 will always come last). Here's an abbreviated view of this order in practice:

    0, 1, 2, ... 2147483646, 2147483647, -2147483648, -2147483647, ... -1

    (This "unsigned order" is identical to the tree's internal order.)

  10. abstract def reverseIterator: Iterator[Int]

    Iterate across all values in the bitset in reverse order.

    Iterate across all values in the bitset in reverse order.

    The order here is exactly the reverse of .iterator.

  11. abstract def size: Long

    Returns the number of distinct values in this bitset.

    Returns the number of distinct values in this bitset.

    For branches, this method will return the sum of the sizes of all its subtrees. For leaves it returns the number of bits set in the leaf (i.e. the number of values the leaf contains).

  12. abstract def |(rhs: BitSet): BitSet

    Return the union of two bitsets as a new immutable bitset.

    Return the union of two bitsets as a new immutable bitset.

    If either bitset contains a given value, the resulting bitset will also contain it.

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. def compact: BitSet

    Return a compacted bitset containing the same values as this one.

    Return a compacted bitset containing the same values as this one.

    This method is used to prune out "empty" branches that don't contain values. By default, bitset does not try to remove empty leaves when removing values (since repeatedly checking for this across many deletions would be expensive).

    The bitset returned will have the same values as the current bitset, but is guaranteed not to contain any empty branches. Empty branches are not usually observable but would result in increased memory usage.

  7. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  8. def equals(that: Any): Boolean

    Universal equality.

    Universal equality.

    This method will only return true if the right argument is also a BitSet. It does not attempt to coerce either argument in any way (unlike Scala collections, for example).

    Two bitsets can be equal even if they have different underlying tree structure. (For example, one bitset's tree may have empty branches that the other lacks.)

    Definition Classes
    BitSet → AnyRef → Any
  9. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  10. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. def hashCode(): Int

    Universal hash code.

    Universal hash code.

    Bitsets that are the equal will hash to the same value. As in equals, the values present determine the hash code, as opposed to the tree structure.

    Definition Classes
    BitSet → AnyRef → Any
  12. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. def nonEmpty: Boolean

    Returns true if this bitset contains values, false otherwise.

  15. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  17. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  18. def toSet: Set[Int]

    Present a view of this bitset as a scala.Set[Int].

    Present a view of this bitset as a scala.Set[Int].

    This is provided for compatibility with Scala collections. Many of the set operations are implemented in terms of BitSet, but other operations (for example map) may copy these values into a different Set implementation.

  19. def toString(): String

    Produce a string representation of this BitSet.

    Produce a string representation of this BitSet.

    This representation will contain all the values in the bitset. For large bitsets, this operation may be very expensive.

    Definition Classes
    BitSet → AnyRef → Any
  20. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  21. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  22. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped