def dense: BFInstance[A] = BFInstance[A]()

in algebird-core/src/main/scala/com/twitter/algebird/BloomFilter.scala [495:523]


  def dense: BFInstance[A] = BFInstance[A](hashes, bits.toBitSet(width), width)

  override def ++(other: BF[A]): BF[A] = {
    require(this.width == other.width)
    require(this.numHashes == other.numHashes)

    other match {
      case BFZero(_, _)       => this
      case BFItem(item, _, _) => this + item
      case bf @ BFSparse(_, otherBits, _) => {
        // assume same hashes used

        // This is expensive in general.
        // We check to see if we are filling < 5%
        // of the bits, if so, stay sparse, if not go dense
        val newMaxSize = numBits + bf.numBits
        if (newMaxSize < (width / 10)) {
          BFSparse(hashes, bits ++ otherBits, width)
        } else {
          // Make a dense bitset
          val lbs = LongBitSet.empty(width)
          lbs += bits.intIterator
          lbs += otherBits.intIterator
          BFInstance(hashes, lbs.toBitSetNoCopy, width)
        }
      }
      case _ => other ++ this
    }
  }