BitSet

cats.collections.BitSet
See theBitSet companion object
sealed abstract class BitSet

A fast, immutable BitSet.

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

Attributes

Companion
object
Source
BitSet.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Abstract methods

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.

Attributes

Source
BitSet.scala
def +(n: Int): BitSet

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.

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.

Attributes

Source
BitSet.scala
def -(n: Int): BitSet

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.

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.

Attributes

Source
BitSet.scala
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.

Attributes

Source
BitSet.scala
def ^(rhs: BitSet): BitSet

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

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

Attributes

Source
BitSet.scala
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.

Attributes

Source
BitSet.scala

Returns whether the two bitsets intersect or not.

Returns whether the two bitsets intersect or not.

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

Attributes

Source
BitSet.scala

Returns false if this bitset contains values, true otherwise.

Returns false if this bitset contains values, true otherwise.

Attributes

Source
BitSet.scala

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

Attributes

Source
BitSet.scala

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.

Attributes

Source
BitSet.scala
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).

Attributes

Source
BitSet.scala
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.

Attributes

Source
BitSet.scala

Concrete methods

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.

Attributes

Source
BitSet.scala
override 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.)

Attributes

Definition Classes
Any
Source
BitSet.scala
override 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.

Attributes

Definition Classes
Any
Source
BitSet.scala

Returns true if this bitset contains values, false otherwise.

Returns true if this bitset contains values, false otherwise.

Attributes

Source
BitSet.scala
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.

Attributes

Source
BitSet.scala
override 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.

Attributes

Definition Classes
Any
Source
BitSet.scala