/**
   * Rellena los registros del dbf.
   *
   * @param sds DOCUMENT ME!
   */
  private void createdbf(SelectableDataSource sds, BitSet bitset) {
    int i = 0;

    // for (int i = 0; i < fgs.length; i++) {
    try {
      if (sds == null) {
        for (int j = 0; j < geometries.length; j++) {
          enteros[0] = ValueFactory.createValue((double) i);
          dbfWrite.write(enteros);
          i++;
        }
      } else {
        for (int j = bitset.nextSetBit(0); j >= 0; j = bitset.nextSetBit(j + 1)) {
          for (int r = 0; r < sds.getFieldCount(); r++) {
            record[r] = sds.getFieldValue(j, r);
          }

          dbfWrite.write(record);
        }
      }
    } catch (IOException e1) {
      e1.printStackTrace();
    } catch (ReadDriverException e) {
      e.printStackTrace();
    }
  }
Example #2
0
  /** Let's do the work. */
  public void start() {
    StringBuilder sb = new StringBuilder();
    sb.append("P1").append("\n"); // magic number
    sb.append(Database.getTotalNbOfNonEmptyAttr())
        .append(" ") // width
        .append(Database.getNumberOfObjects())
        .append("\n"); // height

    System.out.print(sb);

    /*
     * OK, let's not keep everything in memory. Process one line, and
     * write it.
     */
    int i;
    BitSet set;
    boolean oneLine[] = new boolean[Database.getTotalNumberOfAttr() + 1];

    for (Enumeration<BitSet> e = this.database.elements(); e.hasMoreElements(); ) {
      sb = new StringBuilder();
      for (i = 0; i < oneLine.length; ++i) oneLine[i] = false; // re-init

      set = e.nextElement();
      for (i = set.nextSetBit(0); i >= 0; i = set.nextSetBit(i + 1)) {
        oneLine[i] = true;
      }

      for (i = 1; i < oneLine.length; ++i) // position 0 is not used
      {
        if (oneLine[i]) sb.append("1 ");
        else sb.append("0 ");
      }
      System.out.println(sb);
    }
  }
  /**
   * checks that we receive heartbeats and send out heart beats.
   *
   * @param approxTime the approximate time in milliseconds
   */
  void heartBeatMonitor(long approxTime) {
    for (int i = activeKeys.nextSetBit(0); i >= 0; i = activeKeys.nextSetBit(i + 1)) {
      try {
        final SelectionKey key = selectionKeysStore[i];
        if (!key.isValid() || !key.channel().isOpen()) {
          activeKeys.clear(i);
          continue;
        }
        try {
          sendHeartbeatIfRequired(approxTime, key);
        } catch (Exception e) {
          if (LOG.isDebugEnabled()) LOG.debug("", e);
        }

        try {
          heartbeatCheckHasReceived(key, approxTime);
        } catch (Exception e) {
          if (LOG.isDebugEnabled()) LOG.debug("", e);
        }

      } catch (Exception e) {
        if (LOG.isDebugEnabled()) LOG.debug("", e);
      }
    }
  }
Example #4
0
  /** Returns whether this Aspect would accept the given set. */
  public boolean isInterested(BitSet componentBits) {
    // Check if the entity possesses ALL of the components defined in the aspect.
    if (!allSet.isEmpty()) {
      for (int i = allSet.nextSetBit(0); i >= 0; i = allSet.nextSetBit(i + 1)) {
        if (!componentBits.get(i)) {
          return false;
        }
      }
    }

    // If we are STILL interested,
    // Check if the entity possesses ANY of the exclusion components, if it does then the system is
    // not interested.
    if (!exclusionSet.isEmpty() && exclusionSet.intersects(componentBits)) {
      return false;
    }

    // If we are STILL interested,
    // Check if the entity possesses ANY of the components in the oneSet. If so, the system is
    // interested.
    if (!oneSet.isEmpty() && !oneSet.intersects(componentBits)) {
      return false;
    }

    return true;
  }
Example #5
0
 /**
  * Return iterable of feasible colors less than max for node v if it doesn't have a color
  * already.
  */
 public Iterable<Integer> nextColors(int v, int max) {
   LinkedList<Integer> cs = new LinkedList<Integer>();
   BitSet dv = domain[v];
   if (dv.cardinality() > 1)
     for (int c = dv.nextSetBit(0); c >= 0 && c < max; c = dv.nextSetBit(c + 1)) cs.add(c);
   return cs;
 }
Example #6
0
 public zziz zzgX() {
   int i = 0;
   int ai[] = null;
   if (zzGu != null) {
     int ai1[] = new int[zzGu.cardinality()];
     int j = zzGu.nextSetBit(0);
     do {
       ai = ai1;
       if (j < 0) {
         break;
       }
       ai1[i] = j;
       j = zzGu.nextSetBit(j + 1);
       i++;
     } while (true);
   }
   return new zziz(
       mName,
       zzGo,
       zzGp,
       zzGq,
       zzGr,
       zzGs,
       (zzit[]) zzGt.toArray(new zzit[zzGt.size()]),
       ai,
       zzGv);
 }
Example #7
0
  private static void placePhi(MethodNode mth, int regNum, LiveVarAnalysis la) {
    List<BlockNode> blocks = mth.getBasicBlocks();
    int blocksCount = blocks.size();
    BitSet hasPhi = new BitSet(blocksCount);
    BitSet processed = new BitSet(blocksCount);
    Deque<BlockNode> workList = new LinkedList<BlockNode>();

    BitSet assignBlocks = la.getAssignBlocks(regNum);
    for (int id = assignBlocks.nextSetBit(0); id >= 0; id = assignBlocks.nextSetBit(id + 1)) {
      processed.set(id);
      workList.add(blocks.get(id));
    }
    while (!workList.isEmpty()) {
      BlockNode block = workList.pop();
      BitSet domFrontier = block.getDomFrontier();
      for (int id = domFrontier.nextSetBit(0); id >= 0; id = domFrontier.nextSetBit(id + 1)) {
        if (!hasPhi.get(id) && la.isLive(id, regNum)) {
          BlockNode df = blocks.get(id);
          addPhi(df, regNum);
          hasPhi.set(id);
          if (!processed.get(id)) {
            processed.set(id);
            workList.add(df);
          }
        }
      }
    }
  }
Example #8
0
  private void testConsistency() {
    // test if there's an entry for every set bit in availabilityMap
    for (int i = availabilityMap.nextSetBit(0); i >= 0; i = availabilityMap.nextSetBit(i + 1)) {
      if (iBlockRegistry.getRaw(i) == null
          && iItemRegistry.getRaw(i) == null
          && !blockedIds.contains(i)) {
        throw new IllegalStateException(
            String.format("availabilityMap references empty entries for id %d.", i));
      }
    }

    for (int pass = 0; pass < 2; pass++) {
      boolean isBlock = pass == 0;
      String type = isBlock ? "block" : "item";
      FMLControlledNamespacedRegistry<?> registry = isBlock ? iBlockRegistry : iItemRegistry;
      registry.validateContent(
          (isBlock ? MAX_BLOCK_ID : MAX_ITEM_ID),
          type,
          availabilityMap,
          blockedIds,
          iBlockRegistry);
    }

    FMLLog.fine("Registry consistency check successful");
  }
Example #9
0
 public final void flushAll() {
   assert currentState == ISequencer.State.SLEEPING : "wrong state: " + currentState;
   for (int i = toPropagate.nextSetBit(0); i >= 0; i = toPropagate.nextSetBit(i + 1)) {
     master.requests[i].deque();
     toPropagate.clear(i);
   }
 }
Example #10
0
File: Hover.java Project: mrG7/gmol
  @Override
  public void setProperty(String propertyName, Object value, BitSet bsSelected) {

    // if (Logger.debugging) {
    // Logger.debug("Hover.setProperty(" + propertyName + "," + value + ")");
    // }

    if ("target" == propertyName) {
      if (value == null) atomIndex = -1;
      else {
        atomIndex = ((Integer) value).intValue();
      }
      return;
    }

    if ("text" == propertyName) {
      text = (String) value;
      if (text != null && text.length() == 0) text = null;
      return;
    }

    if ("specialLabel" == propertyName) {
      specialLabel = (String) value;
      return;
    }

    if ("atomLabel" == propertyName) {
      String text = (String) value;
      if (text != null && text.length() == 0) text = null;
      int count = viewer.getAtomCount();
      if (atomFormats == null || atomFormats.length < count) atomFormats = new String[count];
      for (int i = bsSelected.nextSetBit(0); i >= 0; i = bsSelected.nextSetBit(i + 1))
        atomFormats[i] = text;
      return;
    }

    if ("xy" == propertyName) {
      xy = (Point3i) value;
      return;
    }

    if ("label" == propertyName) {
      labelFormat = (String) value;
      if (labelFormat != null && labelFormat.length() == 0) labelFormat = null;
      return;
    }

    if (propertyName == "deleteModelAtoms") {
      if (atomFormats != null) {
        int firstAtomDeleted = ((int[]) ((Object[]) value)[2])[1];
        int nAtomsDeleted = ((int[]) ((Object[]) value)[2])[2];
        atomFormats =
            (String[]) ArrayUtil.deleteElements(atomFormats, firstAtomDeleted, nAtomsDeleted);
      }
      atomIndex = -1;
      return;
    }

    super.setProperty(propertyName, value, null);
  }
Example #11
0
  // maintain the list by checking only the variable that has changed when
  // * checking if a tuple is valid.
  // *
  // * @param idx : the variable changed
  public void maintainList(/*int idx*/ ) {
    int cidx = 0;
    int nLast = last.get();
    while (cidx <= nLast) {
      int idxt = listuples[cidx++];
      int[] tuple = relation.getTuple(idxt);

      if (valcheck.isValid(tuple /*,idx*/)) {
        // extract the supports
        for (int i = futureVars.nextSetBit(0); i > -1; i = futureVars.nextSetBit(i + 1)) {
          if (!gacValues[i].get(tuple[i] - offsets[i])) {
            gacValues[i].set(tuple[i] - offsets[i]);
            nbGacValues[i]++;
            if (nbGacValues[i] == vars[i].getDomainSize()) {
              futureVars.clear(i);
            }
          }
        }
      } else {
        // remove the tuple from the current list
        cidx--;
        final int temp = listuples[nLast];
        listuples[nLast] = listuples[cidx];
        listuples[cidx] = temp;
        last.add(-1);
        nLast--;
      }
    }
  }
Example #12
0
  public void saveToXml(Element ele) {
    Document doc = ele.getOwnerDocument();

    ele.setAttribute("id", String.valueOf(partNumber));
    SaveUtil.appendChildTextElement(ele, "title", String.valueOf(title));
    SaveUtil.appendChildTextElement(ele, "instrument", String.valueOf(instrument));
    for (int t = 0; t < getTrackCount(); t++) {
      if (!isTrackEnabled(t)) continue;

      TrackInfo trackInfo = abcSong.getSequenceInfo().getTrackInfo(t);

      Element trackEle = (Element) ele.appendChild(doc.createElement("track"));
      trackEle.setAttribute("id", String.valueOf(t));
      if (trackInfo.hasName()) trackEle.setAttribute("name", trackInfo.getName());

      if (trackTranspose[t] != 0)
        SaveUtil.appendChildTextElement(trackEle, "transpose", String.valueOf(trackTranspose[t]));
      if (trackVolumeAdjust[t] != 0)
        SaveUtil.appendChildTextElement(
            trackEle, "volumeAdjust", String.valueOf(trackVolumeAdjust[t]));

      if (instrument.isPercussion) {
        BitSet[] enabledSetByTrack = isCowbellPart() ? cowbellsEnabled : drumsEnabled;
        BitSet enabledSet = (enabledSetByTrack == null) ? null : enabledSetByTrack[t];
        if (enabledSet != null) {
          Element drumsEnabledEle = ele.getOwnerDocument().createElement("drumsEnabled");
          trackEle.appendChild(drumsEnabledEle);

          if (isCowbellPart()) {
            drumsEnabledEle.setAttribute("defaultEnabled", String.valueOf(false));

            // Only store the drums that are enabled
            for (int i = enabledSet.nextSetBit(0); i >= 0; i = enabledSet.nextSetBit(i + 1)) {
              Element drumEle = ele.getOwnerDocument().createElement("note");
              drumsEnabledEle.appendChild(drumEle);
              drumEle.setAttribute("id", String.valueOf(i));
              drumEle.setAttribute("isEnabled", String.valueOf(true));
            }
          } else {
            drumsEnabledEle.setAttribute("defaultEnabled", String.valueOf(true));

            // Only store the drums that are disabled
            for (int i = enabledSet.nextClearBit(0); i >= 0; i = enabledSet.nextClearBit(i + 1)) {
              if (i >= MidiConstants.NOTE_COUNT) break;

              Element drumEle = ele.getOwnerDocument().createElement("note");
              drumsEnabledEle.appendChild(drumEle);
              drumEle.setAttribute("id", String.valueOf(i));
              drumEle.setAttribute("isEnabled", String.valueOf(false));
            }
          }
        }

        if (!isCowbellPart()) {
          if (drumNoteMap[t] != null)
            drumNoteMap[t].saveToXml((Element) trackEle.appendChild(doc.createElement("drumMap")));
        }
      }
    }
  }
 /**
  * Returns <code>true</code> if this sequent is contained in the other.
  *
  * @param other the other sequent.
  * @return true if this sequent is contained in the other.
  */
 public boolean isContained(SingleSuccedentSequentOnBitSet other) {
   if (this.rightSide != other.rightSide) return false;
   for (int i = leftSide.nextSetBit(0); i >= 0; i = leftSide.nextSetBit(i + 1)) {
     if (!other.leftSide.get(i)) return false;
   }
   return true;
 }
Example #14
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
    }
  }
Example #15
0
 private int selectVariable() {
   int id;
   int cc = random.nextInt(notFrozen.cardinality());
   for (id = notFrozen.nextSetBit(0); id >= 0 && cc > 0; id = notFrozen.nextSetBit(id + 1)) {
     cc--;
   }
   return id;
 }
Example #16
0
 /**
  * Creates new instance for nested structure.
  *
  * @param base parent's level
  * @param offsets offsets from parent's level.
  */
 public IndentLevel(IndentLevel base, int... offsets) {
   final BitSet src = base.levels;
   for (int i = src.nextSetBit(0); i >= 0; i = src.nextSetBit(i + 1)) {
     for (int offset : offsets) {
       levels.set(i + offset);
     }
   }
 }
  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));
    }
  }
Example #18
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;
  }
Example #19
0
 /** @inheritDoc */
 @Override
 int[] toArray() {
   int[] xs = new int[count()];
   int n = 0;
   for (int i = set.nextSetBit(0); i >= 0; i = set.nextSetBit(i + 1)) {
     xs[n++] = i;
   }
   return xs;
 }
Example #20
0
 @Test
 public void testBitSetNextSetBit() throws Exception {
   BitSet bit = new BitSet();
   bit.set(0);
   int position = bit.nextSetBit(0);
   assertThat(position, is(0));
   position = bit.nextSetBit(1);
   assertThat(position, is(-1));
 }
Example #21
0
 /**
  * Test containment. Should be a method on BitSet.
  *
  * @param container possible container to be tested
  * @param containee possible containee to be tested
  * @return true if container contains containee
  * @internal
  * @deprecated This API is ICU internal only.
  */
 @Deprecated
 public static final boolean contains(BitSet container, BitSet containee) {
   for (int i = containee.nextSetBit(0); i >= 0; i = containee.nextSetBit(i + 1)) {
     if (!container.get(i)) {
       return false;
     }
   }
   return true;
 }
Example #22
0
 @Override
 public double getMaxExitRate(BitSet subset) {
   int i;
   double d, max = Double.NEGATIVE_INFINITY;
   for (i = subset.nextSetBit(0); i >= 0; i = subset.nextSetBit(i + 1)) {
     d = trans.get(i).sum();
     if (d > max) max = d;
   }
   return max;
 }
 @Override
 public int compareTo(ImmutableBitmap other) {
   // TODO: find out what this is supposed to even do
   BitSet otherSet = ((WrappedImmutableBitSetBitmap) other).bitmap;
   int lengthCompare = Integer.compare(otherSet.length(), bitmap.length());
   if (lengthCompare != 0) {
     return lengthCompare;
   }
   return Integer.compare(otherSet.nextSetBit(0), bitmap.nextSetBit(0));
 }
Example #24
0
 public int compare(BitSet arg0, BitSet arg1) {
   int diff = arg0.cardinality() - arg1.cardinality();
   if (diff != 0) return diff;
   int i0 = arg0.nextSetBit(0);
   int i1 = arg1.nextSetBit(0);
   while ((diff = i0 - i1) == 0 && i0 > 0) {
     i0 = arg0.nextSetBit(i0 + 1);
     i1 = arg1.nextSetBit(i1 + 1);
   }
   return diff;
 }
Example #25
0
 /**
  * Produce a readable string of a set of scripts
  *
  * @param scripts a BitSet of UScript values
  * @return a readable string of a set of scripts
  * @internal
  * @deprecated This API is ICU internal only.
  */
 @Deprecated
 public static String displayScripts(BitSet scripts) {
   StringBuilder result = new StringBuilder();
   for (int i = scripts.nextSetBit(0); i >= 0; i = scripts.nextSetBit(i + 1)) {
     if (result.length() != 0) {
       result.append(' ');
     }
     result.append(UScript.getShortName(i));
   }
   return result.toString();
 }
 private int repairMatching() throws ContradictionException {
   for (int i = free.nextSetBit(0); i >= 0 && i < n; i = free.nextSetBit(i + 1)) {
     tryToMatch(i);
   }
   int card = 0;
   for (int i = 0; i < n; i++) {
     if (digraph.getPredOf(i).size() > 0) {
       card++;
     }
   }
   return card;
 }
  public void closeBuild() throws HyracksDataException {
    for (int i = 0; i < numOfPartitions; i++) { // Remove Empty Partitions' allocated frame
      if (buildPSizeInTups[i] == 0) {
        buildPSizeInFrames[i]--;
        nextBuff[curPBuff[i]] = nextFreeBuffIx;
        nextFreeBuffIx = curPBuff[i];
        curPBuff[i] = INVALID_BUFFER;
        freeFramesCounter++;
      }
    }

    ByteBuffer buff = null;
    for (int i = pStatus.nextSetBit(0);
        i >= 0;
        i =
            pStatus.nextSetBit(
                i
                    + 1)) { // flushing and DeAllocating the dedicated buffers for the spilled
                            // partitions
      buff = memBuffs[i];
      accessorBuild.reset(buff);
      if (accessorBuild.getTupleCount() > 0) {
        buildWrite(i, buff);
        buildPSizeInFrames[i]++;
      }
      nextBuff[i] = nextFreeBuffIx;
      nextFreeBuffIx = i;
      freeFramesCounter++;
      curPBuff[i] = INVALID_BUFFER;

      if (buildRFWriters[i] != null) {
        buildRFWriters[i].close();
      }
    }

    partitionTune(); // Trying to bring back as many spilled partitions as possible, making them
                     // resident

    int inMemTupCount = 0;
    numOfSpilledParts = 0;

    for (int i = 0; i < numOfPartitions; i++) {
      if (!pStatus.get(i)) {
        inMemTupCount += buildPSizeInTups[i];
      } else {
        numOfSpilledParts++;
      }
    }

    createInMemoryJoiner(inMemTupCount);
    cacheInMemJoin();
    this.isTableEmpty = (inMemTupCount == 0);
  }
Example #28
0
  /**
   * Get the list of sids corresponding to this bitmap as a string
   *
   * @param sequencesSize the list of sequence length to know how many bits are allocated to each
   *     sequence
   * @return a string
   */
  public String getSIDs(List<Integer> sequencesSize) {
    StringBuilder builder = new StringBuilder();

    // We do an AND with the bitmap of the item and this bitmap
    for (int bitK = bitmap.nextSetBit(0); bitK >= 0; bitK = bitmap.nextSetBit(bitK + 1)) {

      // find the sid of this bit
      int sid = bitToSID(bitK, sequencesSize);
      builder.append(" " + sid);
    }
    return builder.toString();
  }
Example #29
0
  /**
   * Create a new bitmap for the s-step by doing a AND between this bitmap and the bitmap of an
   * item.
   *
   * @param bitmapItem the bitmap of the item used for the S-Step
   * @param sequencesSize the sequence lengths
   * @param lastBitIndex the last bit index
   * @param maxGap
   * @return return the new bitmap
   */
  Bitmap createNewBitmapSStep(
      Bitmap bitmapItem, List<Integer> sequencesSize, int lastBitIndex, int maxGap) {
    // INTERSECTION_COUNT++;

    // create a new bitset that will be use for the new bitmap
    BitSet newBitset = new BitSet(lastBitIndex);
    // create the new bitmap
    Bitmap newBitmap = new Bitmap(newBitset);

    // We do an AND with the bitmap of the item and this bitmap
    for (int bitK = bitmap.nextSetBit(0); bitK >= 0; bitK = bitmap.nextSetBit(bitK + 1)) {

      // find the sid of this bit
      int sid = bitToSID(bitK, sequencesSize);

      // get the last bit for this sid
      int lastBitOfSID = lastBitOfSID(sid, sequencesSize, lastBitIndex);

      boolean match = false;
      for (int bit = bitmapItem.bitmap.nextSetBit(bitK + 1);
          bit >= 0 && bit <= lastBitOfSID && (bit - bitK <= maxGap);
          bit = bitmapItem.bitmap.nextSetBit(bit + 1)) {

        // new
        int tid = bit - sequencesSize.get(sid);

        newBitmap.bitmap.set(bit);

        match = true;

        //				System.out.println();
        //				System.out.println("bit " + bit);
        //				System.out.println("sid " + sid);
        //				System.out.println("seqSize " + sequencesSize.get(sid));
        //				System.out.println("tid " + tid);
        if (firstItemsetID == -1 || tid < firstItemsetID) {
          firstItemsetID = tid;
        }
      }
      if (match) {
        // update the support
        if (sid != newBitmap.lastSID) {
          newBitmap.support++;
          newBitmap.sidsum += sid;
        }
        newBitmap.lastSID = sid;
      }
      bitK = lastBitOfSID; // to skip the bit from the same sequence
    }
    // We return the resulting bitmap
    return newBitmap;
  }
 @Override
 public double evaluateSubset(BitSet bs) throws IllegalArgumentException {
   double score = 0;
   for (Instance datum : dataDiscretized) {
     double p = 1;
     for (int i = bs.nextSetBit(0);
         i >= 0;
         i = bs.nextSetBit(i + 1)) // for each selected feature @i
     p *= probs[i][trueLabel][(int) datum.value(i)];
     score += (datum.classValue() == trueLabel) ? p : 1 - p;
   }
   return score;
 }