예제 #1
0
파일: Usage.java 프로젝트: nqzero/kilim
 /**
  * This is the standard liveness calculation (Dragon Book, section 10.6). At each BB (and its
  * corresponding usage), we evaluate "in" using use and def. in = use U (out \ def) where out = U
  * succ.in, for all successors
  *
  * <p>this algorithm has been modified to treat catch blocks as occurring anywhere ie, that vars
  * defined in a try may never be set however, this only applies to vars that have been defined at
  * least once (ie, born)
  */
 public boolean evalLiveIn(ArrayList<Usage> succUsage, ArrayList<Handler> handUsage) {
   BitSet out = new BitSet(nLocals);
   BitSet old_in = (BitSet) in.clone();
   if (handUsage == null) handUsage = new ArrayList();
   if (succUsage.size() == 0) {
     in = use;
   } else {
     // calculate out = U succ.in
     out = (BitSet) succUsage.get(0).in.clone();
     for (int i = 1; i < succUsage.size(); i++) {
       out.or(succUsage.get(i).in);
     }
     // calc out \ def == out & ~def == ~(out | def)
     // unless a var has been def'd in all catch blocks, assume it may fail to def
     BitSet def1 = (BitSet) def.clone();
     for (Handler handle : handUsage) def1.and(handle.catchBB.usage.def);
     def1.flip(0, nLocals);
     out.and(def1);
     for (Handler handler : handUsage) out.or(handler.catchBB.usage.use);
     // catch block vars may be def'd in this block, but we can't easily know if the
     // def has occurred before the throw
     // if the var has never been def'd (or was a parameter), then it can't be live
     out.and(born);
     out.or(use);
     in = out;
   }
   return !(in.equals(old_in));
 }
 @Override
 public final void filter(List<IRow> data, BitSet mask, BitSet mask_filteredOutInfluenceRanking) {
   if (!isFiltered()) return;
   if (!maskInvalid.isEmpty()) {
     BitSet todo = (BitSet) maskInvalid.clone();
     todo.and(mask);
     updateMask(todo, data, this.mask);
     maskInvalid.andNot(todo);
   }
   mask.and(this.mask);
   if (!isRankIndependentFilter) // mark that the masked out are persistent
   mask_filteredOutInfluenceRanking.and(this.mask);
 }
예제 #3
0
파일: Usage.java 프로젝트: nqzero/kilim
 /**
  * Called to coalesce a successor's usage into the current BB. Important: This should be called
  * before live variable analysis begins, because we don't bother merging this.in or this.born.
  */
 void absorb(Usage succ) {
   BitSet b = (BitSet) this.def.clone();
   b.flip(0, nLocals);
   b.and(succ.use);
   this.use.or(b);
   this.def.or(succ.def);
 }
예제 #4
0
  public static void main(String[] args) {
    BitSet bits1 = new BitSet(16);
    BitSet bits2 = new BitSet(16);

    for (int i = 0; i < 16; i++) {
      if ((i % 2) == 0) bits1.set(i);
      if ((i % 5) != 0) bits2.set(i);
    }
    System.out.println("Initial pattern in bits1: ");
    System.out.println(bits1);
    System.out.println("\nInitial pattern in bits2: ");
    System.out.println(bits2);

    // AND bits
    bits2.and(bits1);
    System.out.println("\nbits2 AND bits1: ");
    System.out.println(bits2);

    // OR bits
    bits2.or(bits1);
    System.out.println("\nbits2 OR bits1:  ");
    System.out.println(bits2);

    // XOR bits
    bits2.xor(bits1);
    System.out.println("\nbits2 XOR bits1: ");
    System.out.println(bits2);
  }
  /** Find non-locals variables. Algorithm from Briggs, Cooper, Harvey and Simpson */
  public BitSet findNonLocals() {
    BitSet nonLocals = new BitSet(nbVar);
    BitSet killed = new BitSet(nbVar);
    BitSet emptySet = new BitSet(nbVar);
    for (BasicBlock bb = firstBB; bb != null; bb = bb.getNext()) {
      // clear killed set
      killed.and(emptySet);

      Iterator insts = bb.getInstructions();
      while (insts.hasNext()) {
        QInst inst = (QInst) insts.next();
        QOperandBox[] ops = inst.getUses();
        for (int i = 0; i < ops.length; ++i) {
          QOperand op = ops[i].getOperand();
          if (op instanceof QVar) {
            int r = ((QVar) op).getRegister();
            if (!killed.get(r)) {
              nonLocals.set(r);
            }
          }
        }
        if (inst.defVar()) {
          QOperand op = inst.getDefined().getOperand();
          if (op instanceof QVar) {
            int r = ((QVar) op).getRegister();
            killed.set(r);
          }
        }
      }
    }
    return nonLocals;
  }
예제 #6
0
  /**
   * Prob0 precomputation algorithm. i.e. determine the states of an STPG which, with min/max
   * probability 0, reach a state in {@code target}, while remaining in those in @{code remain}.
   * {@code min}=true gives Prob0E, {@code min}=false gives Prob0A.
   *
   * @param stpg The STPG
   * @param remain Remain in these states (optional: null means "all")
   * @param target Target states
   * @param min1 Min or max probabilities for player 1 (true=lower bound, false=upper bound)
   * @param min2 Min or max probabilities for player 2 (true=min, false=max)
   */
  public BitSet prob0(STPG stpg, BitSet remain, BitSet target, boolean min1, boolean min2) {
    int n, iters;
    BitSet u, soln, unknown;
    boolean u_done;
    long timer;

    // Start precomputation
    timer = System.currentTimeMillis();
    if (verbosity >= 1)
      mainLog.println(
          "Starting Prob0 (" + (min1 ? "min" : "max") + (min2 ? "min" : "max") + ")...");

    // Special case: no target states
    if (target.cardinality() == 0) {
      soln = new BitSet(stpg.getNumStates());
      soln.set(0, stpg.getNumStates());
      return soln;
    }

    // Initialise vectors
    n = stpg.getNumStates();
    u = new BitSet(n);
    soln = new BitSet(n);

    // Determine set of states actually need to perform computation for
    unknown = new BitSet();
    unknown.set(0, n);
    unknown.andNot(target);
    if (remain != null) unknown.and(remain);

    // Fixed point loop
    iters = 0;
    u_done = false;
    // Least fixed point - should start from 0 but we optimise by
    // starting from 'target', thus bypassing first iteration
    u.or(target);
    soln.or(target);
    while (!u_done) {
      iters++;
      // Single step of Prob0
      stpg.prob0step(unknown, u, min1, min2, soln);
      // Check termination
      u_done = soln.equals(u);
      // u = soln
      u.clear();
      u.or(soln);
    }

    // Negate
    u.flip(0, n);

    // Finished precomputation
    timer = System.currentTimeMillis() - timer;
    if (verbosity >= 1) {
      mainLog.print("Prob0 (" + (min1 ? "min" : "max") + (min2 ? "min" : "max") + ")");
      mainLog.println(" took " + iters + " iterations and " + timer / 1000.0 + " seconds.");
    }

    return u;
  }
예제 #7
0
  private boolean match(BitSet bitset, BitSet other) {
    BitSet intersection = (BitSet) other;

    intersection.and(bitset);

    return intersection.equals(bitset);
  }
예제 #8
0
  /**
   * Splits events of a row if they overlap an island. Islands are areas between the token which are
   * included in the result.
   *
   * @param row
   * @param graph
   * @param text
   * @param startTokenIndex token index of the first token in the match
   * @param endTokenIndex token index of the last token in the match
   */
  private static void splitRowsOnIslands(
      Row row,
      final SDocumentGraph graph,
      STextualDS text,
      long startTokenIndex,
      long endTokenIndex) {

    BitSet tokenCoverage = new BitSet();
    // get the sorted token
    List<SToken> sortedTokenList = graph.getSortedTokenByText();
    // add all token belonging to the right text to the bit set
    ListIterator<SToken> itToken = sortedTokenList.listIterator();
    while (itToken.hasNext()) {
      SToken t = itToken.next();
      if (text == null || text == CommonHelper.getTextualDSForNode(t, graph)) {
        RelannisNodeFeature feat =
            (RelannisNodeFeature) t.getFeature(ANNIS_NS, FEAT_RELANNIS_NODE).getValue();
        long tokenIndexRaw = feat.getTokenIndex();

        tokenIndexRaw = clip(tokenIndexRaw, startTokenIndex, endTokenIndex);
        int tokenIndex = (int) (tokenIndexRaw - startTokenIndex);
        tokenCoverage.set(tokenIndex);
      }
    }

    ListIterator<GridEvent> itEvents = row.getEvents().listIterator();
    while (itEvents.hasNext()) {
      GridEvent event = itEvents.next();
      BitSet eventBitSet = new BitSet();
      eventBitSet.set(event.getLeft(), event.getRight() + 1);

      // restrict event bitset on the locations where token are present
      eventBitSet.and(tokenCoverage);

      // if there is is any 0 bit before the right border there is a break in the event
      // and we need to split it
      if (eventBitSet.nextClearBit(event.getLeft()) <= event.getRight()) {
        // remove the original event
        row.removeEvent(itEvents);

        // The event bitset now marks all the locations which the event should
        // cover.
        // Make a list of new events for each connected range in the bitset
        int subElement = 0;
        int offset = eventBitSet.nextSetBit(0);
        while (offset >= 0) {
          int end = eventBitSet.nextClearBit(offset) - 1;
          if (offset < end) {
            GridEvent newEvent = new GridEvent(event);
            newEvent.setId(event.getId() + "_islandsplit_" + subElement++);
            newEvent.setLeft(offset);
            newEvent.setRight(end);
            row.addEvent(itEvents, newEvent);
          }
          offset = eventBitSet.nextSetBit(end + 1);
        }
      } // end if we need to split
    }
  }
예제 #9
0
파일: Usage.java 프로젝트: nqzero/kilim
 /**
  * evolve the born value a single iteration by mixing in either pred or combo
  *
  * @param pred if combo is null, use pred.born
  * @param combo if non-null, the value to mix in
  * @return true if the evolution resulted in a change in the born value
  */
 boolean evalBornIn(Usage pred, BitSet combo) {
   BitSet old = (BitSet) born.clone();
   if (combo == null) combo = pred.born;
   if (firstBorn) born.or(combo);
   else born.and(combo);
   firstBorn = false;
   return !old.equals(born);
 }
예제 #10
0
  public int selectBestBlockForDownload(Friend remoteFriend) throws IOException {
    if (T.t) {
      T.debug("Selecting best block for download. Remote: " + remoteFriend);
    }
    BlockMask bm = blockMasks.get(remoteFriend.getGuid());
    if (bm == null) {
      if (T.t) {
        T.info("Ehh. Don't know anything about this friends block mask. Can't download.");
      }
      return -1;
    }

    BitSet interestingBlocks = getInterestingBlocks(bm);

    // remove bocks in progress from interesting blocks:
    BlockFile bf = storage.getBlockFile(root);
    BitSet blocksInProgress = bf == null ? new BitSet() : bf.getBlocksInProgress();
    blocksInProgress.flip(0, fd.getNumberOfBlocks());
    blocksInProgress.and(interestingBlocks);

    if (blocksInProgress.cardinality() > 0) {
      // there are blocks of interest that are NOT in progress. Take one of these
      interestingBlocks = blocksInProgress;
    } // else there are only blocks in progress. Use any of them

    int highestBlockNumber = 0;
    if (bf != null) {
      highestBlockNumber = bf.getHighestCompleteBlock();
    }
    highestBlockNumber += manager.getCore().getSettings().getInternal().getMaxfileexpandinblocks();
    // we prefer to load blocks below highestBlockNumber
    if (interestingBlocks.nextSetBit(0) < highestBlockNumber) {
      // we're good - there are interesting blocks below the highest block number.

      // remove all blocks above highest block number:
      if (highestBlockNumber + 1 < fd.getNumberOfBlocks()) {
        interestingBlocks.clear(highestBlockNumber + 1, fd.getNumberOfBlocks());
      }
    }

    // select a random block of the ones we're interested in - change this to rarest first in the
    // future
    int c = interestingBlocks.cardinality();
    int n = (int) (Math.random() * c);
    for (int i = interestingBlocks.nextSetBit(0), j = 0;
        i >= 0;
        i = interestingBlocks.nextSetBit(i + 1), j++) {
      if (j == n) {
        return i;
      }
    }

    if (T.t) {
      T.trace("Can't find any block to download from " + remoteFriend);
    }
    return -1;
  }
  private void changeServiceDependencies(final double addFactor, final double removeFactor) {
    BitSet servicesInNeighbourhood[] = new BitSet[numNeighbourhoods];
    for (int s = 0; s < servicesInNeighbourhood.length; ++s) {
      servicesInNeighbourhood[s] = new BitSet();
    }

    IntAVLTreeSet serviceToNeighbourhoods[] = new IntAVLTreeSet[services.length];
    for (int s = 0; s < services.length; ++s) serviceToNeighbourhoods[s] = new IntAVLTreeSet();

    for (Process p : processes) {
      int n = machines[assignment[p.id]].neighborhood;
      int s = p.service;

      servicesInNeighbourhood[n].set(s);

      serviceToNeighbourhoods[s].add(n);
    }

    for (int sid = 0; sid < services.length; sid++) {
      IntAVLTreeSet neighbourhoods = serviceToNeighbourhoods[sid];

      BitSet intersection = null;
      for (int n : neighbourhoods) {
        if (intersection == null) {
          intersection = new BitSet();
          intersection.or(servicesInNeighbourhood[n]);
        } else intersection.and(servicesInNeighbourhood[n]);
      }

      // intersection - all possible services I can depend on

      for (int d : services[sid].dependencies) intersection.clear(d);

      intersection.clear(sid); // exclude itself
      // services we can add as new dependencies

      int[] list = new int[intersection.cardinality()];
      int i = 0;
      for (int q = intersection.nextSetBit(0); q >= 0; q = intersection.nextSetBit(q + 1)) {
        list[i++] = q;
      }
      MyArrayUtils.shuffle(list, random);

      int addCount = nextInt(0, 1 + (int) (addFactor * services[sid].dependencies.length));
      // addCount = 0;
      int removeCount = nextInt(0, 1 + (int) (addFactor * services[sid].dependencies.length));

      int[] newdependencies =
          org.apache.commons.lang.ArrayUtils.addAll(
              services[sid].dependencies,
              Arrays.copyOfRange(list, 0, Math.min(list.length, addCount)));
      MyArrayUtils.shuffle(newdependencies, random);

      services[sid].dependencies =
          Arrays.copyOfRange(newdependencies, 0, Math.max(0, newdependencies.length - removeCount));
    }
  }
예제 #12
0
  public void testItShouldNotFullyIntersectTheFingerprintDerivedFromASubstructure() {
    BitSet benzene = fingerprinter.getFingerprint(Molecules.createBenzene());
    BitSet phenol = fingerprinter.getFingerprint(Molecules.createPhenol());
    BitSet intersection = (BitSet) phenol.clone();

    intersection.and(benzene);

    assertFalse(match(phenol, benzene));
  }
예제 #13
0
 /**
  * Given the current set of potential matching rules, obtain the rules which match the current
  * field defined either by key or anykey. The rules are represented by bitsets which are
  * intersected to return the remain potentially matching rules. If after bitset intersection, the
  * resulting bitset is empty, an exception is thrown to halt the search.
  *
  * @param src - the current set of potentially matching rules.
  * @param map - the data structure holding all the possible values defined by all flow space rules
  *     for given field.
  * @param key - the key (or field value) used to index the data structure.
  * @param anykey - the 'any' value for this field.
  * @param wildcards - the set of wildcards defined by this match
  * @param wild - the specific wildcard value for this field
  * @return - true if field was wildcarded and false otherwise.
  * @throws NoMatch - if the set of rules (ie. the src bitset) is empty after intersection.
  */
 private <K> boolean testEmpty(
     BitSet src, Map<K, BitSet> map, K key, K anykey, int wildcards, int wild) throws NoMatch {
   if ((wildcards & wild) != 0) return true;
   BitSet any = get(map, anykey);
   any.or(get(map, key));
   src.and(any);
   if (src.isEmpty()) throw new NoMatch("No Match");
   return false;
 }
예제 #14
0
 public synchronized void commit() {
   Object[] o = observers.toArray();
   for (int i = 0; i < o.length; i++) {
     BitSet tmp = (BitSet) changeMap.clone();
     ObserverEntry oe = (ObserverEntry) o[i];
     tmp.and(oe.ids);
     if (tmp.length() != 0) oe.observer.update(this, oe.tag);
   }
 }
예제 #15
0
    Coverage getCoveredBasicBlocks() {
      BitSet bExec = getExecutedInsn();
      BitSet bb = getBasicBlocks();
      int nCov = 0;

      if (excludeHandlers) {
        BitSet handlers = getHandlers();
        bb.and(handlers);
      }

      if (bExec != null) {
        BitSet bCov = new BitSet(bb.size());
        bCov.or(bb);
        bCov.and(bExec);
        nCov = bCov.cardinality();
      }

      return new Coverage(bb.cardinality(), nCov);
    }
예제 #16
0
 /** Change this SprayPattern to be (this & p), only 1s both places survive. */
 public SprayPattern and(SprayPattern p) {
   if (size != p.size) throw new IndexOutOfBoundsException();
   if (is(false)) ; // No change
   else if (is(true)) set(p);
   else if (p.is(false)) set(false);
   else if (p.is(true)) ; // No change
   else {
     array.and(p.array);
     update();
   }
   return this;
 }
예제 #17
0
 private BitSet getInterestingBlocks(BlockMask remote) throws IOException {
   if (T.t) {
     T.ass(fd != null, "Need a FD for this call to work");
   }
   BitSet interestingBlocks = new BitSet();
   BlockMask myBm = manager.getCore().getFileManager().getBlockMask(fd.getRootHash());
   if (myBm != null) {
     interestingBlocks.or(myBm);
   }
   interestingBlocks.flip(0, fd.getNumberOfBlocks());
   interestingBlocks.and(remote);
   return interestingBlocks;
 }
예제 #18
0
  @SuppressWarnings("null")
  @Test
  public void flipTestBigA() {
    final int numCases = 1000000;
    System.out.println("flipTestBigA for " + numCases + " tests");
    final BitSet bs = new BitSet();
    final Random r = new Random(3333);
    int checkTime = 2;
    RoaringBitmap rb1 = new RoaringBitmap(), rb2 = null; // alternate
    // between
    // them

    for (int i = 0; i < numCases; ++i) {
      final int start = r.nextInt(65536 * 20);
      int end = r.nextInt(65536 * 20);
      if (r.nextDouble() < 0.1) end = start + r.nextInt(100);

      if ((i & 1) == 0) {
        rb2 = RoaringBitmap.flip(rb1, start, end);
        // tweak the other, catch bad sharing
        rb1.flip(r.nextInt(65536 * 20), r.nextInt(65536 * 20));
      } else {
        rb1 = RoaringBitmap.flip(rb2, start, end);
        rb2.flip(r.nextInt(65536 * 20), r.nextInt(65536 * 20));
      }

      if (start < end) bs.flip(start, end); // throws exception
      // otherwise
      // insert some more ANDs to keep things sparser
      if (r.nextDouble() < 0.2 && (i & 1) == 0) {
        final RoaringBitmap mask = new RoaringBitmap();
        final BitSet mask1 = new BitSet();
        final int startM = r.nextInt(65536 * 20);
        final int endM = startM + 100000;
        mask.flip(startM, endM);
        mask1.flip(startM, endM);
        mask.flip(0, 65536 * 20 + 100000);
        mask1.flip(0, 65536 * 20 + 100000);
        rb2.and(mask);
        bs.and(mask1);
      }

      if (i > checkTime) {
        System.out.println("check after " + i + ", card = " + rb2.getCardinality());
        final RoaringBitmap rb = (i & 1) == 0 ? rb2 : rb1;
        final boolean status = equals(bs, rb);
        Assert.assertTrue(status);
        checkTime *= 1.5;
      }
    }
  }
  private BlockDataFlowState generateDFState(CFGBlock block) {
    int totalGlobals = this.uniqueGlobals.get(block.getMethodName()).size();

    // Get the original inBitSet for this block
    BitSet origIn;
    if (this.cfgBlocksState.containsKey(block)) {
      origIn = this.cfgBlocksState.get(block).getIn();
    } else {
      origIn = new BitSet(totalGlobals);
      origIn.set(0, totalGlobals);
    }

    // Calculate the in BitSet by taking intersection of predecessors
    BlockDataFlowState bFlow = new BlockDataFlowState(totalGlobals);

    // If there exist at least one successor, set Out to all True
    if (block.getSuccessors().size() > 0) {
      bFlow.getOut().set(0, totalGlobals);
    }

    BitSet out = bFlow.getOut();
    for (CFGBlock pred : block.getSuccessors()) {
      if (this.cfgBlocksState.containsKey(pred)) {
        out.and(this.cfgBlocksState.get(pred).getIn());
      }
    }

    calculateGenKillSets(block, bFlow);

    // Calculate Out
    BitSet in = bFlow.getIn(); // IN = (OUT - KILL) U GEN
    in.or(out);
    in.xor(bFlow.getKill());
    in.or(bFlow.getGen());

    if (!in.equals(origIn)) {
      // Add successors to cfgBlocks list
      for (CFGBlock pred : block.getPredecessors()) {
        if (!cfgBlocksToProcess.contains(pred)) {
          cfgBlocksToProcess.add(pred);
        }
      }
    }

    // Remove this block, since it has been processed
    cfgBlocksToProcess.remove(block);

    return bFlow;
  }
예제 #20
0
  BitSet singleBitDiff(BitSet x, BitSet y) {
    BitSet t = new BitSet(x.length());
    t.or(x);
    t.flip(0, t.size());
    t.and(y);

    switch (t.cardinality()) {
      case 0:
        return t;
      case 1:
        return t;
      default:
        return new BitSet();
    }
  }
예제 #21
0
 BitSet addClause(BooleanQuery bq, BitSet result) {
   final BitSet rnd = sets[r.nextInt(sets.length)];
   Query q =
       new ConstantScoreQuery(
           new Filter() {
             @Override
             public DocIdSet getDocIdSet(IndexReader reader) {
               return new DocIdBitSet(rnd);
             };
           });
   bq.add(q, BooleanClause.Occur.MUST);
   if (validate) {
     if (result == null) result = (BitSet) rnd.clone();
     else result.and(rnd);
   }
   return result;
 }
예제 #22
0
 public BitSet getCharContainingIndexSet(char[] nameChars) {
   BitSet sets = new BitSet(sources.size());
   sets.set(0, sources.size());
   for (char c : nameChars) {
     c = Character.toLowerCase(c);
     BitSet charSet = index.get(c);
     if (charSet == null) {
       sets.clear();
       break;
     } else {
       sets.and(charSet);
       if (sets.isEmpty()) {
         break;
       }
     }
   }
   return sets;
 }
예제 #23
0
  protected Set<HierNode<T>> gcs(Set<HierNode<T>> set) {
    Set<HierNode<T>> s = new HashSet<HierNode<T>>();

    Iterator<HierNode<T>> iter = set.iterator();
    BitSet a = new BitSet(this.size());
    a.or(iter.next().getBitMask());
    while (iter.hasNext()) {
      a.and(iter.next().getBitMask());
    }
    // System.out.println( "Root mask for ceil " + toBinaryString( a ) );
    for (HierNode<T> node : getNodes()) {
      if (superset(node.getBitMask(), a) >= 0) {
        s.add(node);
      }
    }

    Set<HierNode<T>> cl = ceil(s);
    return cl;
  }
예제 #24
0
 private BitSet getCode(Object value, CodedHierarchy x) {
   if (value instanceof Class) {
     String typeName = ((Class) value).getName();
     return x.getCode(typeName);
   } else if (value instanceof String) {
     return x.getCode(value);
   } else if (value instanceof Collection) {
     BitSet code = null;
     for (Object o : ((Collection) value)) {
       if (code == null) {
         code = (BitSet) getCode(o, x).clone();
       } else {
         code.and(getCode(o, x));
       }
     }
     return code;
   }
   throw new UnsupportedOperationException(" IsA Operator : Unsupported literal " + value);
 }
예제 #25
0
  @Test
  public void flipTestBig() {
    final int numCases = 1000000;
    System.out.println("flipTestBig for " + numCases + " tests");
    final RoaringBitmap rb = new RoaringBitmap();
    final BitSet bs = new BitSet();
    final Random r = new Random(3333);
    int checkTime = 2;

    for (int i = 0; i < numCases; ++i) {
      final int start = r.nextInt(65536 * 20);
      int end = r.nextInt(65536 * 20);
      if (r.nextDouble() < 0.1) end = start + r.nextInt(100);
      rb.flip(start, end);
      if (start < end) bs.flip(start, end); // throws exception
      // otherwise
      // insert some more ANDs to keep things sparser
      if (r.nextDouble() < 0.2) {
        final RoaringBitmap mask = new RoaringBitmap();
        final BitSet mask1 = new BitSet();
        final int startM = r.nextInt(65536 * 20);
        final int endM = startM + 100000;
        mask.flip(startM, endM);
        mask1.flip(startM, endM);
        mask.flip(0, 65536 * 20 + 100000);
        mask1.flip(0, 65536 * 20 + 100000);
        rb.and(mask);
        bs.and(mask1);
      }
      // see if we can detect incorrectly shared containers
      if (r.nextDouble() < 0.1) {
        final RoaringBitmap irrelevant = RoaringBitmap.flip(rb, 10, 100000);
        irrelevant.flip(5, 200000);
        irrelevant.flip(190000, 260000);
      }
      if (i > checkTime) {
        System.out.println("check after " + i + ", card = " + rb.getCardinality());
        Assert.assertTrue(equals(bs, rb));
        checkTime *= 1.5;
      }
    }
  }
예제 #26
0
 public BitSet bits(IndexReader reader) throws IOException {
   // Iterate through list of filters and apply the boolean AND operation
   // on each bitSet. The AND operator has the affect that only documents
   // that are allowed by every single filter in the filter list will be
   // allowed by this MultiFilter.
   int filterListSize = filterList.size();
   if (filterListSize > 0) {
     BitSet bits = ((Filter) filterList.get(0)).bits(reader);
     for (int i = 1; i < filterListSize; i++) {
       bits.and(((Filter) filterList.get(i)).bits(reader));
     }
     return bits;
   }
   // There are no filters defined. In this case, we return a new
   // BitSet that will filter out all documents. This is probably the most
   // consistent behavior with the Lucene API. It's also a lot more
   // efficient considering the BitSet implementation.
   else {
     return new BitSet(reader.maxDoc());
   }
 }
예제 #27
0
  /**
   * Create a new bitmap by performing the I-STEP with this bitmap and the bitmap of an item.
   *
   * @param bitmapItem the bitmap of the item
   * @param sequencesSize the sequence lengths
   * @param lastBitIndex the last bit index
   * @return the new bitmap
   */
  Bitmap createNewBitmapIStep(Bitmap bitmapItem, List<Integer> sequencesSize, int lastBitIndex) {
    // INTERSECTION_COUNT++;

    // We create the new bitmap
    BitSet newBitset = new BitSet(lastBitIndex); // TODO: USE LAST SET BIT
    Bitmap newBitmap = new Bitmap(newBitset);

    // We do an AND with the bitmap of the item
    for (int bit = bitmap.nextSetBit(0); bit >= 0; bit = bitmap.nextSetBit(bit + 1)) {
      if (bitmapItem.bitmap.get(bit)) { // if both bits are TRUE

        // set the bit
        newBitmap.bitmap.set(bit);
        // update the support
        int sid = bitToSID(bit, sequencesSize);

        if (sid != newBitmap.lastSID) {
          newBitmap.sidsum += sid;
          newBitmap.support++;
        }
        newBitmap.lastSID = sid; // remember the last SID

        // new
        int tid = bit - sequencesSize.get(sid);
        if (firstItemsetID == -1 || tid < firstItemsetID) {
          firstItemsetID = tid;
        }
        // end new

      }
    }
    // Then do the AND
    newBitset.and(bitmapItem.bitmap);

    // We return the resulting bitmap
    return newBitmap;
  }
예제 #28
0
 /* (non-Javadoc)
  * @see java.util.BitSet#and(java.util.BitSet)
  */
 public void and(java.util.BitSet set) {
   super.and(set);
   makeDirty();
 }
예제 #29
0
 /**
  * The writeReplace method is called when ObjectOutputStream is preparing to write the object to
  * the stream. The ObjectOutputStream checks whether the class defines the writeReplace method. If
  * the method is defined, the writeReplace method is called to allow the object to designate its
  * replacement in the stream. The object returned should be either of the same type as the object
  * passed in or an object that when read and resolved will result in an object of a type that is
  * compatible with all references to the object.
  *
  * @return the replaced object
  * @throws ObjectStreamException
  */
 protected Object writeReplace() throws ObjectStreamException {
   java.util.BitSet copy = new java.util.BitSet();
   copy.and(this);
   return copy;
 }
예제 #30
0
 /**
  * Set an identifier to analyze. Afterwards, call methods like getScripts()
  *
  * @param identifier the identifier to analyze
  * @return self
  * @internal
  * @deprecated This API is ICU internal only.
  */
 @Deprecated
 public IdentifierInfo setIdentifier(String identifier) {
   this.identifier = identifier;
   clear();
   BitSet scriptsForCP = new BitSet();
   int cp;
   for (int i = 0; i < identifier.length(); i += Character.charCount(i)) {
     cp = Character.codePointAt(identifier, i);
     // Store a representative character for each kind of decimal digit
     if (UCharacter.getType(cp) == UCharacterCategory.DECIMAL_DIGIT_NUMBER) {
       // Just store the zero character as a representative for comparison. Unicode guarantees it
       // is cp - value
       numerics.add(cp - UCharacter.getNumericValue(cp));
     }
     UScript.getScriptExtensions(cp, scriptsForCP);
     scriptsForCP.clear(UScript.COMMON);
     scriptsForCP.clear(UScript.INHERITED);
     //            if (temp.cardinality() == 0) {
     //                // HACK for older version of ICU
     //                requiredScripts.set(UScript.getScript(cp));
     //            } else
     switch (scriptsForCP.cardinality()) {
       case 0:
         break;
       case 1:
         // Single script, record it.
         requiredScripts.or(scriptsForCP);
         break;
       default:
         if (!requiredScripts.intersects(scriptsForCP) && scriptSetSet.add(scriptsForCP)) {
           scriptsForCP = new BitSet();
         }
         break;
     }
   }
   // Now make a final pass through to remove alternates that came before singles.
   // [Kana], [Kana Hira] => [Kana]
   // This is relatively infrequent, so doesn't have to be optimized.
   // We also compute any commonalities among the alternates.
   if (scriptSetSet.size() > 0) {
     commonAmongAlternates.set(0, UScript.CODE_LIMIT);
     for (Iterator<BitSet> it = scriptSetSet.iterator(); it.hasNext(); ) {
       final BitSet next = it.next();
       // [Kana], [Kana Hira] => [Kana]
       if (requiredScripts.intersects(next)) {
         it.remove();
       } else {
         // [[Arab Syrc Thaa]; [Arab Syrc]] => [[Arab Syrc]]
         commonAmongAlternates.and(next); // get the intersection.
         for (BitSet other : scriptSetSet) {
           if (next != other && contains(next, other)) {
             it.remove();
             break;
           }
         }
       }
     }
   }
   if (scriptSetSet.size() == 0) {
     commonAmongAlternates.clear();
   }
   return this;
 }