/**
  * Update the piece availabilities for a given peer
  *
  * @param peerID String
  * @param has BitSet
  */
 public synchronized void peerAvailability(String peerID, BitSet has) {
   this.peerAvailabilies.put(peerID, has);
   BitSet interest = (BitSet) (has.clone());
   interest.andNot(this.isComplete);
   DownloadTask dt = this.task.get(peerID);
   if (dt != null) {
     if (interest.cardinality() > 0 && !dt.peer.isInteresting()) {
       dt.ms.addMessageToQueue(new Message_PP(PeerProtocol.INTERESTED, 2));
       dt.peer.setInteresting(true);
     }
   }
   dt = null;
 }
예제 #2
0
 public List<TOE> next() {
   List<TOE> ret = new LinkedList<TOE>();
   for (int i = 0; i < N; i++)
     for (int j = 0; j < M; j++)
     // if(G.get(i*M+j))
     {
       BitSet Gnew = (BitSet) (G.clone());
       int[] x = {0, 1, -1, 0, 0};
       int[] y = {0, 0, 0, 1, -1};
       for (int k = 0; k < 5; k++) {
         int xi = x[k];
         int yi = y[k];
         if ((i + xi) >= 0 && (i + xi) < N && (j + yi) >= 0 && (j + yi) < M) {
           Gnew.flip((i + xi) * M + (j + yi));
         }
       }
       TOE to = new TOE(N, M, Gnew);
       to.mx = i;
       to.my = j;
       ret.add(to);
     }
   return ret;
 }
  public void rTest(final int N) {
    System.out.println("rtest N=" + N);
    for (int gap = 1; gap <= 65536; gap *= 2) {
      final BitSet bs1 = new BitSet();
      final MutableRoaringBitmap rb1 = new MutableRoaringBitmap();
      for (int x = 0; x <= N; x += gap) {
        bs1.set(x);
        rb1.add(x);
      }
      if (bs1.cardinality() != rb1.getCardinality()) throw new RuntimeException("different card");
      if (!equals(bs1, rb1)) throw new RuntimeException("basic  bug");
      for (int offset = 1; offset <= gap; offset *= 2) {
        final BitSet bs2 = new BitSet();
        final MutableRoaringBitmap rb2 = new MutableRoaringBitmap();
        for (int x = 0; x <= N; x += gap) {
          bs2.set(x + offset);
          rb2.add(x + offset);
        }
        if (bs2.cardinality() != rb2.getCardinality()) throw new RuntimeException("different card");
        if (!equals(bs2, rb2)) throw new RuntimeException("basic  bug");

        BitSet clonebs1;
        // testing AND
        clonebs1 = (BitSet) bs1.clone();
        clonebs1.and(bs2);
        if (!equals(clonebs1, MutableRoaringBitmap.and(rb1, rb2)))
          throw new RuntimeException("bug and");
        {
          final MutableRoaringBitmap t = rb1.clone();
          t.and(rb2);
          if (!equals(clonebs1, t)) throw new RuntimeException("bug inplace and");
          if (!t.equals(MutableRoaringBitmap.and(rb1, rb2))) {
            System.out.println(
                t.highLowContainer.getContainerAtIndex(0).getClass().getCanonicalName());
            System.out.println(
                MutableRoaringBitmap.and(rb1, rb2)
                    .highLowContainer
                    .getContainerAtIndex(0)
                    .getClass()
                    .getCanonicalName());

            throw new RuntimeException("bug inplace and");
          }
        }

        // testing OR
        clonebs1 = (BitSet) bs1.clone();
        clonebs1.or(bs2);

        if (!equals(clonebs1, MutableRoaringBitmap.or(rb1, rb2)))
          throw new RuntimeException("bug or");
        {
          final MutableRoaringBitmap t = rb1.clone();
          t.or(rb2);
          if (!equals(clonebs1, t)) throw new RuntimeException("bug or");
          if (!t.equals(MutableRoaringBitmap.or(rb1, rb2))) throw new RuntimeException("bug or");
          if (!t.toString().equals(MutableRoaringBitmap.or(rb1, rb2).toString()))
            throw new RuntimeException("bug or");
        }
        // testing XOR
        clonebs1 = (BitSet) bs1.clone();
        clonebs1.xor(bs2);
        if (!equals(clonebs1, MutableRoaringBitmap.xor(rb1, rb2))) {
          throw new RuntimeException("bug xor");
        }
        {
          final MutableRoaringBitmap t = rb1.clone();
          t.xor(rb2);
          if (!equals(clonebs1, t)) throw new RuntimeException("bug xor");

          if (!t.equals(MutableRoaringBitmap.xor(rb1, rb2))) {
            System.out.println(t);
            System.out.println(MutableRoaringBitmap.xor(rb1, rb2));
            System.out.println(
                Arrays.equals(t.toArray(), MutableRoaringBitmap.xor(rb1, rb2).toArray()));
            throw new RuntimeException("bug xor");
          }
        }
        // testing NOTAND
        clonebs1 = (BitSet) bs1.clone();
        clonebs1.andNot(bs2);
        if (!equals(clonebs1, MutableRoaringBitmap.andNot(rb1, rb2))) {
          throw new RuntimeException("bug andnot");
        }
        clonebs1 = (BitSet) bs2.clone();
        clonebs1.andNot(bs1);
        if (!equals(clonebs1, MutableRoaringBitmap.andNot(rb2, rb1))) {
          throw new RuntimeException("bug andnot");
        }
        {
          final MutableRoaringBitmap t = rb2.clone();
          t.andNot(rb1);
          if (!equals(clonebs1, t)) {
            throw new RuntimeException("bug inplace andnot");
          }
          final MutableRoaringBitmap g = MutableRoaringBitmap.andNot(rb2, rb1);
          if (!equals(clonebs1, g)) {
            throw new RuntimeException("bug andnot");
          }
          if (!t.equals(g)) throw new RuntimeException("bug");
        }
        clonebs1 = (BitSet) bs1.clone();
        clonebs1.andNot(bs2);
        if (!equals(clonebs1, MutableRoaringBitmap.andNot(rb1, rb2))) {
          throw new RuntimeException("bug andnot");
        }
        {
          final MutableRoaringBitmap t = rb1.clone();
          t.andNot(rb2);
          if (!equals(clonebs1, t)) {
            throw new RuntimeException("bug andnot");
          }
          final MutableRoaringBitmap g = MutableRoaringBitmap.andNot(rb1, rb2);
          if (!equals(clonebs1, g)) {
            throw new RuntimeException("bug andnot");
          }
          if (!t.equals(g)) throw new RuntimeException("bug");
        }
      }
    }
  }