LongRangeSet (long leftFrom, long leftTo, long rightFrom, long rightTo, BitString globalMask) { BitString leftBits = BitString.fromRange(leftFrom, leftTo); BitString rightBits = BitString.fromRange(rightFrom, rightTo); LongRangeSet fromBits = fromBits(leftBits.and(rightBits).and(globalMask)); if (leftFrom == leftTo && rightFrom == rightTo) { return point(leftFrom & rightFrom & (globalMask.myBits | ~globalMask.myMask)).meet(fromBits); } if (leftFrom == leftTo && Long.bitCount(leftFrom + 1) == 1) { return bitwiseMask(rightFrom, rightTo, leftFrom).meet(fromBits); } if (rightFrom == rightTo && Long.bitCount(rightFrom + 1) == 1) { return bitwiseMask(leftFrom, leftTo, rightFrom).meet(fromBits); } return fromBits; }