private[algebird] def |=()

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


    private[algebird] def |=(rhs: BitSet): Unit =
      if (height > rhs.height) {
        if (rhs.offset < offset || limit <= rhs.offset) {
          throw InternalError("union outside of branch jurisdiction")
        } else {
          // this branch contains rhs, so find its index
          val i = index(rhs.offset)
          val c0 = children(i)
          if (c0 == null) {
            val c1 = newChild(i)
            c1 |= rhs
            children(i) = c1
          } else {
            c0 |= rhs
          }
        }
      } else if (height < rhs.height) {
        throw InternalError("branch too short for union")
      } else if (offset != rhs.offset) {
        throw InternalError("branch misaligned")
      } else {
        // height == rhs.height, so we know rhs is a Branch.
        val Branch(_, _, rcs) = rhs
        var i = 0
        while (i < 32) {
          val x = children(i)
          val y = rcs(i)
          if (x == null) children(i) = y
          else if (y != null) x |= rcs(i)
          i += 1
        }
      }