Computes the bitwise AND of this container with another (intersection). This container as well
as the provided container are left unaffected.

@param x other container
@return aggregated container
349963
public int andCardinality(Container x) {
    if (this.isEmpty()) {
      return 0;
    } else if (x.isEmpty()) {
      return 0;
    } else {
      if (x instanceof ArrayContainer) {
        return andCardinality((ArrayContainer) x);
      } else if (x instanceof BitmapContainer) {
        return andCardinality((BitmapContainer) x);
      }
      return andCardinality((RunContainer) x);
    }
  }
1237216
public static int nextPow2Int(int x) {
    --x;
    x |= x >>> 1;
    x |= x >>> 2;
    x |= x >>> 4;
    x |= x >>> 8;
    x |= x >>> 16;
    return ++x;
  }
1030320
public static MutableRoaringBitmap addOffset(final ImmutableRoaringBitmap x, int offset) {
    int container_offset = offset >>> 16;
    int in_container_offset = offset % (1<<16);
    if(in_container_offset == 0) {
      MutableRoaringBitmap answer = x.toMutableRoaringBitmap();
      for(int pos = 0; pos < answer.highLowContainer.size(); pos++) {
        int key = BufferUtil.toIntUnsigned(answer.getMappeableRoaringArray()
            .getKeyAtIndex(pos));
        key += container_offset;
        if(key > 0xFFFF) {
          throw new IllegalArgumentException("Offset too large.");
        }
        answer.getMappeableRoaringArray().keys[pos] = (short) key;
      }
      return answer;
    } else {
      MutableRoaringBitmap answer = new MutableRoaringBitmap();
      for(int pos = 0; pos < x.highLowContainer.size(); pos++) {
        int key = BufferUtil.toIntUnsigned(x.highLowContainer.getKeyAtIndex(pos));
        key += container_offset;
        if(key > 0xFFFF) {
          throw new IllegalArgumentException("Offset too large.");
        }
        MappeableContainer c = x.highLowContainer.getContainerAtIndex(pos);
        MappeableContainer[] offsetted = BufferUtil.addOffset(c, 
          (short)in_container_offset);
        if( !offsetted[0].isEmpty()) {
          int current_size = answer.highLowContainer.size();
          int lastkey = 0;
          if(current_size > 0) {
            lastkey = answer.highLowContainer.getKeyAtIndex(
              current_size - 1);
          }
          if((current_size > 0) && (lastkey == key)) {
            MappeableContainer prev = answer.highLowContainer
                .getContainerAtIndex(current_size - 1);
            MappeableContainer orresult = prev.ior(offsetted[0]);
            answer.getMappeableRoaringArray().setContainerAtIndex(current_size - 1,
                orresult);
          } else {
            answer.getMappeableRoaringArray().append((short)key, offsetted[0]);
          }
        }
        if( !offsetted[1].isEmpty()) {
          if(key == 0xFFFF) {
            throw new IllegalArgumentException("Offset too large.");
          }
          answer.getMappeableRoaringArray().append((short)(key + 1), offsetted[1]);
        }
      }
      answer.repairAfterLazy();
      return answer;
    }
  }
1295401
public static BigFloat coth(BigFloat x) {
		return x.context.valueOf(BigDecimalMath.coth(x.value, x.context.mathContext));
	}
831143
public void flip(final int x) {
    final short hb = Util.highbits(x);
    final int i = highLowContainer.getIndex(hb);
    if (i >= 0) {
      Container c = highLowContainer.getContainerAtIndex(i).flip(Util.lowbits(x));
      if (!c.isEmpty()) {
        highLowContainer.setContainerAtIndex(i, c);
      } else {
        highLowContainer.removeAtIndex(i);
      }
    } else {
      final ArrayContainer newac = new ArrayContainer();
      highLowContainer.insertNewKeyValueAt(-i - 1, hb, newac.add(Util.lowbits(x)));
    }
  }
468702
public Bbox intersection(Bbox other) {
		if (!this.intersects(other)) {
			return null;
		} else {
			double minx = other.getX() > this.getX() ? other.getX() : this.getX();
			double maxx = other.getEndPoint().getX() < this.getEndPoint().getX() ? other.getEndPoint().getX() : this
					.getEndPoint().getX();
			double miny = other.getY() > this.getY() ? other.getY() : this.getY();
			double maxy = other.getEndPoint().getY() < this.getEndPoint().getY() ? other.getEndPoint().getY() : this
					.getEndPoint().getY();
			return new Bbox(minx, miny, (maxx - minx), (maxy - miny));
		}
	}
635955
public static boolean intersects(final RoaringBitmap x1, final RoaringBitmap x2) {
    final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size();
    int pos1 = 0, pos2 = 0;

    while (pos1 < length1 && pos2 < length2) {
      final short s1 = x1.highLowContainer.getKeyAtIndex(pos1);
      final short s2 = x2.highLowContainer.getKeyAtIndex(pos2);
      if (s1 == s2) {
        final Container c1 = x1.highLowContainer.getContainerAtIndex(pos1);
        final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2);
        if (c1.intersects(c2)) {
          return true;
        }
        ++pos1;
        ++pos2;
      } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2
        pos1 = x1.highLowContainer.advanceUntil(s2, pos1);
      } else { // s1 > s2
        pos2 = x2.highLowContainer.advanceUntil(s1, pos2);
      }
    }
    return false;
  }
765982
@Pure
	public DoubleProperty secondAxisExtentProperty() {
		if (this.extentS == null) {
			this.extentS = new SimpleDoubleProperty(this, MathFXAttributeNames.SECOND_AXIS_EXTENT) {
				@Override
				protected void invalidated() {
					if (get() < 0.) {
						set(0.);
					}
				}
			};
		}
		return this.extentS;
	}
1229533
public static MutableRoaringBitmap and(final MutableRoaringBitmap x1,
      final MutableRoaringBitmap x2) {
    final MutableRoaringBitmap answer = new MutableRoaringBitmap();
    int pos1 = 0, pos2 = 0;
    final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size();

    while (pos1 < length1 && pos2 < length2) {
      final short s1 = x1.highLowContainer.getKeyAtIndex(pos1);
      final short s2 = x2.highLowContainer.getKeyAtIndex(pos2);

      if (s1 == s2) {
        final MappeableContainer c1 = x1.highLowContainer.getContainerAtIndex(pos1);
        final MappeableContainer c2 = x2.highLowContainer.getContainerAtIndex(pos2);
        final MappeableContainer c = c1.and(c2);
        if (!c.isEmpty()) {
          answer.getMappeableRoaringArray().append(s1, c);
        }
        ++pos1;
        ++pos2;
      } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2
        pos1 = x1.highLowContainer.advanceUntil(s2, pos1);
      } else { // s1 > s2
        pos2 = x2.highLowContainer.advanceUntil(s1, pos2);
      }
    }
    return answer;
  }
835307
public static <T extends Comparable<T>> Partition<T> intersect(Partition<T> p1, Partition<T> p2) throws MIDDException {

        if (p1.size() == 0 || p2.size() == 0) {
            return new Partition<T>();
        }

        List<Interval<T>> tempIntervals = combine(p1, p2);

        Interval<T> newInterval = null;
        Interval<T> superOfNewIntervalP1 = null;
        Interval<T> superOfNewIntervalP2 = null;

        // combine adjacent intervals which belong to the same type
        List<Interval<T>> outputPartition = new ArrayList<Interval<T>>();

        for (int i = 0; i < tempIntervals.size(); i++) {
            Interval<T> tempInterval = tempIntervals.get(i);
            Interval<T> superOfTempIntervalP1 = p1.getSuperInterval(tempInterval);
            Interval<T> superOfTempIntervalP2 = p2.getSuperInterval(tempInterval);

            // if it belongs to at most one partition, ignore!
            if (superOfTempIntervalP1 == null || superOfTempIntervalP2 == null) {
                continue;
            }

            if (newInterval == null) {
                newInterval = tempInterval;
                superOfNewIntervalP1 = superOfTempIntervalP1;
                superOfNewIntervalP2 = superOfTempIntervalP2;
                continue;
            }

            if (superOfNewIntervalP1 == superOfTempIntervalP1 && superOfNewIntervalP2 == superOfTempIntervalP2) {
                newInterval.includeBound(tempInterval);
            } else {
                outputPartition.add(newInterval);
                newInterval = tempInterval;
                superOfNewIntervalP1 = superOfTempIntervalP1;
                superOfNewIntervalP2 = superOfTempIntervalP2;
            }

        }
        if (newInterval != null) {
            outputPartition.add(newInterval);
        }
        return new Partition<T>(outputPartition);
    }
676932
@Benchmark
  public int intersectionAndIter(BitmapsForIntersection state)
  {
    ImmutableBitmap intersection = factory.intersection(Arrays.asList(state.bitmaps));
    return iter(intersection);
  }
606027
public IntBiMap union(IntBiMap other) {
    int newLength = keys.length + other.keys.length;

    int[] newKeys = Arrays.copyOf(keys, newLength);
    ArrayUtils.copy(other.keys, 0, newKeys, keys.length, other.keys.length);
    int[] newValues = Arrays.copyOf(values, newLength);
    ArrayUtils.copy(other.values, 0, newValues, values.length, other.values.length);

    return IntBiMap.fromUnsortedKeyValues(newKeys, newValues);
  }
461559
public boolean checkedAdd(final int x) {
    final short hb = BufferUtil.highbits(x);
    final int i = highLowContainer.getIndex(hb);
    if (i >= 0) {
      MappeableContainer C = highLowContainer.getContainerAtIndex(i);
      int oldcard = C.getCardinality();
      C = C.add(BufferUtil.lowbits(x));
      getMappeableRoaringArray().setContainerAtIndex(i, C);
      return C.getCardinality() > oldcard;
    } else {
      final MappeableArrayContainer newac = new MappeableArrayContainer();
      getMappeableRoaringArray().insertNewKeyValueAt(-i - 1, hb, newac.add(BufferUtil.lowbits(x)));
      return true;
    }
  }
151759
public double[] postConvert(double[] X) {
		if (X.length != standardN) {
			throw new IllegalArgumentException("wrong array dimension: " + X.length);
		}
		double[] ret = new double[originalN];
		int cntSplitted = 0;
		for (int i = standardS; i < standardN; i++) {
			if (splittedVariablesList.contains(i - standardS)) {
				// this variable was splitted: x = xPlus-xMinus
				ret[i - standardS] = X[i] - X[standardN + cntSplitted];
				cntSplitted++;
			} else {
				ret[i - standardS] = X[i];
			}
		}
		// this.postconvertedX = ret;
		return ret;
	}
969079
private int getSegmentForX(int x) {
        if (autoScroll.get()) {
            int playHead = (x - (getWidth() / 2));
            int offset = Util.timeToHalfFrame(getFurthestPlaybackPosition()) / scale.get();
            return  (playHead + offset) * scale.get();
        }
        return x * scale.get();
    }
1074669
protected Container getContainer(short x) {
    int i = this.binarySearch(0, size, x);
    if (i < 0) {
      return null;
    }
    return this.values[i];
  }
416941
Container toBitmapOrArrayContainer(int card) {
    // int card = this.getCardinality();
    if (card <= ArrayContainer.DEFAULT_MAX_SIZE) {
      ArrayContainer answer = new ArrayContainer(card);
      answer.cardinality = 0;
      for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) {
        int runStart = toIntUnsigned(this.getValue(rlepos));
        int runEnd = runStart + toIntUnsigned(this.getLength(rlepos));

        for (int runValue = runStart; runValue <= runEnd; ++runValue) {
          answer.content[answer.cardinality++] = (short) runValue;
        }
      }
      return answer;
    }
    BitmapContainer answer = new BitmapContainer();
    for (int rlepos = 0; rlepos < this.nbrruns; ++rlepos) {
      int start = toIntUnsigned(this.getValue(rlepos));
      int end = start + toIntUnsigned(this.getLength(rlepos)) + 1;
      Util.setBitmapRange(answer.bitmap, start, end);
    }
    answer.cardinality = card;
    return answer;
  }