public void testList() {
    // Long-long
    TLongArrayList llist = new TLongArrayList();
    assertTrue(serializesCorrectly(llist, "list-l-1"));
    llist.add(0);
    llist.add(1);
    assertTrue(serializesCorrectly(llist, "list-l-2"));
    llist.add(Long.MIN_VALUE);
    assertTrue(serializesCorrectly(llist, "list-l-3"));
    llist.add(Long.MAX_VALUE);
    assertTrue(serializesCorrectly(llist, "list-l-4"));

    // Int-int
    TIntArrayList ilist = new TIntArrayList();
    assertTrue(serializesCorrectly(ilist, "list-i-1"));
    ilist.add(0);
    ilist.add(1);
    assertTrue(serializesCorrectly(ilist, "list-i-2"));
    ilist.add(Integer.MIN_VALUE);
    assertTrue(serializesCorrectly(ilist, "list-i-3"));
    ilist.add(Integer.MAX_VALUE);
    assertTrue(serializesCorrectly(ilist, "list-i-4"));

    // Double-double
    TDoubleArrayList dlist = new TDoubleArrayList();
    assertTrue(serializesCorrectly(dlist, "list-d-1"));
    dlist.add(0);
    dlist.add(1);
    assertTrue(serializesCorrectly(dlist, "list-d-2"));
    dlist.add(Double.MIN_VALUE);
    assertTrue(serializesCorrectly(dlist, "list-d-3"));
    dlist.add(Double.MAX_VALUE);
    assertTrue(serializesCorrectly(dlist, "list-d-4"));
    // NOTE: trove doesn't deal well with NaN
    //        ddmap.add( Double.NaN, Double.NaN );
    //        assertTrue( serializesCorrectly( ddmap ) );
    dlist.add(Double.POSITIVE_INFINITY);
    assertTrue(serializesCorrectly(dlist, "list-d-5"));
    dlist.add(Double.NEGATIVE_INFINITY);
    assertTrue(serializesCorrectly(dlist, "list-d-6"));

    // Float-float
    TFloatArrayList flist = new TFloatArrayList();
    assertTrue(serializesCorrectly(flist, "list-f-1"));
    flist.add(0);
    flist.add(1);
    assertTrue(serializesCorrectly(flist, "list-f-2"));
    flist.add(Float.MIN_VALUE);
    assertTrue(serializesCorrectly(flist, "list-f-3"));
    flist.add(Float.MAX_VALUE);
    assertTrue(serializesCorrectly(flist, "list-f-4"));
    flist.add(Float.POSITIVE_INFINITY);
    assertTrue(serializesCorrectly(flist, "list-f-5"));
    flist.add(Float.NEGATIVE_INFINITY);
    assertTrue(serializesCorrectly(flist, "list-f-6"));
    // NOTE: trove doesn't deal well with NaN
    //        ffmap.add( Float.NaN );
    //        assertTrue( serializesCorrectly( ffmap ) );
  }
Esempio n. 2
0
  private boolean uniteClasses(int c1Index, int c2Index) {
    EqClass c1 = myEqClasses.get(c1Index);
    EqClass c2 = myEqClasses.get(c2Index);

    Set<DfaVariableValue> vars = ContainerUtil.newTroveSet();
    Set<DfaVariableValue> negatedVars = ContainerUtil.newTroveSet();
    int[] cs = new int[c1.size() + c2.size()];
    c1.set(0, cs, 0, c1.size());
    c2.set(0, cs, c1.size(), c2.size());

    int nConst = 0;
    for (int c : cs) {
      DfaValue dfaValue = unwrap(myFactory.getValue(c));
      if (dfaValue instanceof DfaConstValue) nConst++;
      if (dfaValue instanceof DfaVariableValue) {
        DfaVariableValue variableValue = (DfaVariableValue) dfaValue;
        if (variableValue.isNegated()) {
          negatedVars.add(variableValue.createNegated());
        } else {
          vars.add(variableValue);
        }
      }
      if (nConst > 1) return false;
    }
    if (ContainerUtil.intersects(vars, negatedVars)) return false;

    TLongArrayList c2Pairs = new TLongArrayList();
    long[] distincts = myDistinctClasses.toArray();
    for (long distinct : distincts) {
      int pc1 = low(distinct);
      int pc2 = high(distinct);
      boolean addedToC1 = false;

      if (pc1 == c1Index || pc2 == c1Index) {
        addedToC1 = true;
      }

      if (pc1 == c2Index || pc2 == c2Index) {
        if (addedToC1) return false;
        c2Pairs.add(distinct);
      }
    }

    EqClass newClass = new EqClass(c1);

    myEqClasses.set(c1Index, newClass);
    for (int i = 0; i < c2.size(); i++) {
      int c = c2.get(i);
      newClass.add(c);
      removeFromMap(c, c2Index);
      addToMap(c, c1Index);
    }

    for (int i = 0; i < c2Pairs.size(); i++) {
      long c = c2Pairs.get(i);
      myDistinctClasses.remove(c);
      myDistinctClasses.add(createPair(c1Index, low(c) == c2Index ? high(c) : low(c)));
    }
    myEqClasses.set(c2Index, null);

    return true;
  }