def &()

in algebird-core/src/main/scala/com/twitter/algebird/immutable/BitSet.scala [588:626]


    def &(rhs: BitSet): BitSet =
      if (this eq rhs) {
        this
      } else if (height > rhs.height) {
        if (rhs.offset < offset || limit <= rhs.offset) {
          Empty
        } else {
          // this branch contains rhs, so find its index
          val i = index(rhs.offset)
          val c0 = children(i)
          if (c0 != null) c0 & rhs else Empty
        }
      } else if (height < rhs.height) {
        // use commuativity to handle this in previous case
        rhs & this
      } else if (offset != rhs.offset) {
        // same height, but non-overlapping
        Empty
      } else {
        // height == rhs.height, so we know rhs is a Branch.
        val Branch(_, _, rcs) = rhs
        val cs = new Array[BitSet](32)
        var i = 0
        var nonEmpty = false
        while (i < 32) {
          val x = children(i)
          val y = rcs(i)
          if (x != null && y != null) {
            val xy = x & y
            if (!(xy eq Empty)) {
              nonEmpty = true
              cs(i) = xy
            }
          }
          i += 1
        }
        if (nonEmpty) Branch(offset, height, cs)
        else Empty
      }