Ejemplo n.º 1
0
  @Test
  public void testCopy() {
    Graph g = initUnsorted(createGraph());
    EdgeIteratorState eb = g.edge(6, 5, 11, true);
    eb.setWayGeometry(Helper.createPointList(12, 10, -1, 3));
    LevelGraph lg = new GraphBuilder(encodingManager).levelGraphCreate();
    GHUtility.copyTo(g, lg);
    eb = lg.getEdgeProps(eb.getEdge(), 6);
    assertEquals(Helper.createPointList(-1, 3, 12, 10), eb.getWayGeometry());
    assertEquals(0, lg.getLevel(0));
    assertEquals(0, lg.getLevel(1));
    assertEquals(0, lg.getLatitude(0), 1e-6);
    assertEquals(1, lg.getLongitude(0), 1e-6);
    assertEquals(2.5, lg.getLatitude(1), 1e-6);
    assertEquals(4.5, lg.getLongitude(1), 1e-6);
    assertEquals(9, lg.getNodes());
    EdgeIterator iter = lg.createEdgeExplorer().setBaseNode(8);
    iter.next();
    assertEquals(2.05, iter.getDistance(), 1e-6);
    assertEquals("11", BitUtil.toBitString(iter.getFlags(), 2));
    iter.next();
    assertEquals(0.5, iter.getDistance(), 1e-6);
    assertEquals("11", BitUtil.toBitString(iter.getFlags(), 2));

    iter = lg.createEdgeExplorer().setBaseNode(7);
    iter.next();
    assertEquals(2.1, iter.getDistance(), 1e-6);
    assertEquals("01", BitUtil.toBitString(iter.getFlags(), 2));
    assertTrue(iter.next());
    assertEquals(0.7, iter.getDistance(), 1e-6);
  }
 /**
  * Returns the popcount or cardinality of "a and not b" or "intersection(a, not(b))". Neither set
  * is modified.
  */
 public static long andNotCount(BitSet a, BitSet b) {
   long tot =
       BitUtil.pop_andnot(a.getBits(), b.getBits(), 0, Math.min(a.getNumWords(), b.getNumWords()));
   if (a.getNumWords() > b.getNumWords()) {
     tot += BitUtil.pop_array(a.getBits(), b.getNumWords(), a.getNumWords() - b.getNumWords());
   }
   return tot;
 }
 /**
  * Returns the popcount or cardinality of the exclusive-or of the two sets. Neither set is
  * modified.
  */
 public static long xorCount(BitSet a, BitSet b) {
   long tot =
       BitUtil.pop_xor(a.getBits(), b.getBits(), 0, Math.min(a.getNumWords(), b.getNumWords()));
   if (a.getNumWords() < b.getNumWords()) {
     tot += BitUtil.pop_array(b.getBits(), a.getNumWords(), b.getNumWords() - a.getNumWords());
   } else if (a.getNumWords() > b.getNumWords()) {
     tot += BitUtil.pop_array(a.getBits(), b.getNumWords(), a.getNumWords() - b.getNumWords());
   }
   return tot;
 }
  public int indexOfNthSetBit(int n) {

    int result = 0;
    int count = 0;
    for (int i = 0; i < myNumWords; i++) {
      int currentCount = BitUtil.pop(myBits[i]);
      if ((count + currentCount) >= n) {
        long bitmask = 1L;
        while (true) {
          if ((myBits[i] & bitmask) != 0) {
            count++;
            if (count == n) {
              return result;
            }
          }
          bitmask = bitmask << 1;
          result++;
        }
      } else {
        count = count + currentCount;
        result = result + 64;
      }
    }

    return -1;
  }
  /**
   * Returns the index of the first set bit starting at the index specified. -1 is returned if there
   * are no more set bits.
   */
  public long nextSetBit(long index) {
    int i = (int) (index >>> 6);
    if (i >= myNumWords) {
      return -1;
    }
    int subIndex = (int) index & 0x3f; // index within the word
    long word = myBits[i] >>> subIndex; // skip all the bits to the right of index

    if (word != 0) {
      return (((long) i) << 6) + (subIndex + BitUtil.ntz(word));
    }

    while (++i < myNumWords) {
      word = myBits[i];
      if (word != 0) {
        return (((long) i) << 6) + BitUtil.ntz(word);
      }
    }

    return -1;
  }
  /**
   * Returns the index of the first set bit starting at the index specified. -1 is returned if there
   * are no more set bits.
   */
  public int nextSetBit(int index) {
    int i = index >> 6;
    if (i >= myNumWords) {
      return -1;
    }
    int subIndex = index & 0x3f; // index within the word
    long word = myBits[i] >> subIndex; // skip all the bits to the right of index

    if (word != 0) {
      return (i << 6) + subIndex + BitUtil.ntz(word);
    }

    while (++i < myNumWords) {
      word = myBits[i];
      if (word != 0) {
        return (i << 6) + BitUtil.ntz(word);
      }
    }

    return -1;
  }
 /**
  * Returns the popcount or cardinality of the intersection of the two sets. Neither set is
  * modified.
  */
 public static long intersectionCount(BitSet a, BitSet b) {
   return BitUtil.pop_intersect(
       a.getBits(), b.getBits(), 0, Math.min(a.getNumWords(), b.getNumWords()));
 }
 /** @return the number of set bits */
 public long cardinality() {
   return BitUtil.pop_array(myBits, 0, myNumWords);
 }