def |()

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


    def |(rhs: BitSet): BitSet =
      if (this eq rhs) {
        this
      } else if (height > rhs.height) {
        if (rhs.offset < offset || limit <= rhs.offset) {
          // this branch doesn't contain rhs
          BitSet.adoptedUnion(this, rhs)
        } else {
          // this branch contains rhs, so find its index
          val i = index(rhs.offset)
          val c0 = children(i)
          val c1 =
            if (c0 != null) c0 | rhs
            else if (height == 1) rhs
            else {
              val cc = newChild(i)
              cc |= rhs
              cc
            }
          replace(i, c1)
        }
      } 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
        BitSet.adoptedUnion(this, rhs)
      } else {
        // height == rhs.height, so we know rhs is a Branch.
        val Branch(_, _, rcs) = rhs
        val cs = new Array[BitSet](32)
        var i = 0
        while (i < 32) {
          val x = children(i)
          val y = rcs(i)
          cs(i) = if (x == null) y else if (y == null) x else x | y
          i += 1
        }
        Branch(offset, height, cs)
      }