List of usage examples for java.util BitSet set
public void set(int bitIndex)
From source file:org.onosproject.tetopology.management.impl.TeTopologyManager.java
private void updateMergedTopology(Map<Long, TeNode> teNodes, Map<TeLinkTpKey, TeLink> teLinks) { boolean newTopology = mergedTopology == null; BitSet flags = newTopology ? new BitSet(TeConstants.FLAG_MAX_BITS) : mergedTopology.flags(); flags.set(TeTopology.BIT_MERGED); CommonTopologyData commonData = new CommonTopologyData( newTopology ? TeMgrUtil.toNetworkId(mergedTopologyKey) : mergedTopology.networkId(), OptimizationType.NOT_OPTIMIZED, flags, DeviceId.deviceId("localHost")); mergedTopology = new DefaultTeTopology(mergedTopologyKey, teNodes, teLinks, Long.toString(mergedTopologyKey.topologyId()), commonData); mergedNetwork = TeMgrUtil.networkBuilder(mergedTopology); log.info("Nodes# {}, Links# {}", mergedTopology.teNodes().size(), mergedTopology.teLinks().size()); }
From source file:com.google.uzaygezen.core.LongArrayBitVector.java
@Override public BitSet toBitSet() { BitSet result = new BitSet(size); if (size != 0) { for (int i = nextSetBit(0); i != -1; i = nextSetBit(i + 1)) { result.set(i); }/*from w w w. java 2 s. c om*/ } return result; }
From source file:org.apache.tez.runtime.library.common.writers.UnorderedPartitionedKVWriter.java
private Event generateEvent() throws IOException { DataMovementEventPayloadProto.Builder payloadBuidler = DataMovementEventPayloadProto.newBuilder(); String host = getHost();/* w w w. j a va 2 s. c o m*/ int shufflePort = getShufflePort(); BitSet emptyPartitions = new BitSet(); for (int i = 0; i < numPartitions; i++) { if (numRecordsPerPartition[i] == 0) { emptyPartitions.set(i); } } if (emptyPartitions.cardinality() != 0) { // Empty partitions exist ByteString emptyPartitionsByteString = TezCommonUtils .compressByteArrayToByteString(TezUtilsInternal.toByteArray(emptyPartitions)); payloadBuidler.setEmptyPartitions(emptyPartitionsByteString); } if (emptyPartitions.cardinality() != numPartitions) { // Populate payload only if at least 1 partition has data payloadBuidler.setHost(host); payloadBuidler.setPort(shufflePort); payloadBuidler.setPathComponent(outputContext.getUniqueIdentifier()); } CompositeDataMovementEvent cDme = CompositeDataMovementEvent.create(0, numPartitions, payloadBuidler.build().toByteString().asReadOnlyByteBuffer()); return cDme; }
From source file:au.org.ala.delta.translation.intkey.IntkeyItemsFileWriter.java
private void writeMultiStateAttributes(IdentificationKeyCharacter character) { int charNumber = character.getFilteredCharacterNumber(); int numStates = character.getNumberOfStates(); List<BitSet> attributes = new ArrayList<BitSet>(); Iterator<FilteredItem> items = _dataSet.filteredItems(); while (items.hasNext()) { int itemNum = items.next().getItem().getItemNumber(); MultiStateAttribute attribute = (MultiStateAttribute) _dataSet.getAttribute(itemNum, character.getCharacterNumber()); List<Integer> states = new ArrayList<Integer>(); if (attribute.isImplicit()) { ControllingInfo controllingInfo = _dataSet.checkApplicability(attribute.getCharacter(), attribute.getItem()); if (!controllingInfo.isInapplicable()) { states = character.getPresentStates(attribute); }//from w ww. ja va 2 s . c o m } else { states = character.getPresentStates(attribute); } // Turn into bitset. BitSet bits = new BinaryKeyFileEncoder().encodeAttributeStates(states); if (isInapplicable(attribute)) { if (attribute.isInherited()) { bits.clear(); } bits.set(numStates); } attributes.add(bits); } _itemsFile.writeAttributeBits(charNumber, attributes, numStates + 1); }
From source file:cascading.tap.hadoop.ZipInputFormatTest.java
public void testSplits() throws Exception { JobConf job = new JobConf(); FileSystem currentFs = FileSystem.get(job); Path file = new Path(workDir, "test.zip"); Reporter reporter = Reporter.NULL;/*from w w w. jav a2 s .co m*/ int seed = new Random().nextInt(); LOG.info("seed = " + seed); Random random = new Random(seed); FileInputFormat.setInputPaths(job, file); for (int entries = 1; entries < MAX_ENTRIES; entries += random.nextInt(MAX_ENTRIES / 10) + 1) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(byteArrayOutputStream); long length = 0; LOG.debug("creating; zip file with entries = " + entries); // for each entry in the zip file for (int entryCounter = 0; entryCounter < entries; entryCounter++) { // construct zip entries splitting MAX_LENGTH between entries long entryLength = MAX_LENGTH / entries; ZipEntry zipEntry = new ZipEntry("/entry" + entryCounter + ".txt"); zipEntry.setMethod(ZipEntry.DEFLATED); zos.putNextEntry(zipEntry); for (length = entryCounter * entryLength; length < (entryCounter + 1) * entryLength; length++) { zos.write(Long.toString(length).getBytes()); zos.write("\n".getBytes()); } zos.flush(); zos.closeEntry(); } zos.flush(); zos.close(); currentFs.delete(file, true); OutputStream outputStream = currentFs.create(file); byteArrayOutputStream.writeTo(outputStream); outputStream.close(); ZipInputFormat format = new ZipInputFormat(); format.configure(job); LongWritable key = new LongWritable(); Text value = new Text(); InputSplit[] splits = format.getSplits(job, 100); BitSet bits = new BitSet((int) length); for (int j = 0; j < splits.length; j++) { LOG.debug("split[" + j + "]= " + splits[j]); RecordReader<LongWritable, Text> reader = format.getRecordReader(splits[j], job, reporter); try { int count = 0; while (reader.next(key, value)) { int v = Integer.parseInt(value.toString()); LOG.debug("read " + v); if (bits.get(v)) LOG.warn("conflict with " + v + " in split " + j + " at position " + reader.getPos()); assertFalse("key in multiple partitions.", bits.get(v)); bits.set(v); count++; } LOG.debug("splits[" + j + "]=" + splits[j] + " count=" + count); } finally { reader.close(); } } assertEquals("some keys in no partition.", length, bits.cardinality()); } }
From source file:org.unitime.timetable.solver.studentsct.StudentSectioningDatabaseLoader.java
public static BitSet getFreeTimeBitSet(Session session) { int startMonth = session.getPatternStartMonth(); int endMonth = session.getPatternEndMonth(); int size = DateUtils.getDayOfYear(0, endMonth + 1, session.getSessionStartYear()) - DateUtils.getDayOfYear(1, startMonth, session.getSessionStartYear()); BitSet ret = new BitSet(size); for (int i = 0; i < size; i++) ret.set(i); return ret;/* w w w . j a va2s .c om*/ }
From source file:org.apache.tez.dag.library.vertexmanager.ShuffleVertexManager.java
@Override public void onSourceTaskCompleted(String srcVertexName, Integer srcTaskId) { updateSourceTaskCount();/*www . ja v a 2s . com*/ SourceVertexInfo srcInfo = srcVertexInfo.get(srcVertexName); if (srcInfo.edgeProperty.getDataMovementType() == DataMovementType.SCATTER_GATHER) { //handle duplicate events for bipartite sources BitSet completedSourceTasks = srcInfo.finishedTaskSet; if (completedSourceTasks != null) { // duplicate notifications tracking if (!completedSourceTasks.get(srcTaskId)) { completedSourceTasks.set(srcTaskId); // source task has completed ++numBipartiteSourceTasksCompleted; } } } schedulePendingTasks(); }
From source file:com.bittorrent.mpetazzoni.client.SharedTorrent.java
/** * Return a copy of the bit field of available pieces for this torrent. * * <p>//from www. j a va2 s . co m * Available pieces are pieces available in the swarm, and it does not * include our own pieces. * </p> */ public BitSet getAvailablePieces() { if (!this.isInitialized()) { throw new IllegalStateException("Torrent not yet initialized!"); } BitSet availablePieces = new BitSet(this.pieces.length); synchronized (this.pieces) { for (Piece piece : this.pieces) { if (piece.available()) { availablePieces.set(piece.getIndex()); } } } return availablePieces; }
From source file:android.databinding.tool.expr.ExprModelTest.java
private void assertFlags(Expr a, int... flags) { BitSet bitset = new BitSet(); for (int flag : flags) { bitset.set(flag); }//from w ww . j a v a 2s. c o m assertEquals("flag test for " + a.getUniqueKey(), bitset, a.getShouldReadFlags()); }
From source file:org.apache.kylin.gridtable.GTScanRangePlanner.java
private ImmutableBitSet makeGridTableColumns(CuboidToGridTableMapping mapping, Set<TblColRef> dimensions) { BitSet result = new BitSet(); for (TblColRef dim : dimensions) { int idx = mapping.getIndexOf(dim); if (idx >= 0) result.set(idx); }/*from w w w . j ava2s . c om*/ return new ImmutableBitSet(result); }