List of usage examples for java.util BitSet BitSet
private BitSet(long[] words)
From source file:org.apache.openjpa.kernel.StateManagerImpl.java
/** * Initialize with the given instance and state. *//*from ww w .ja v a 2 s . co m*/ protected void initialize(PersistenceCapable pc, PCState state) { if (pc == null) throw new UserException(_loc.get("init-null-pc", _meta)); if (pc.pcGetStateManager() != null && pc.pcGetStateManager() != this) throw new UserException(_loc.get("init-sm-pc", Exceptions.toString(pc))).setFailedObject(pc); pc.pcReplaceStateManager(this); FieldMetaData[] fmds = _meta.getFields(); _loaded = new BitSet(fmds.length); // mark primary key and non-persistent fields as loaded for (int i : _meta.getPkAndNonPersistentManagedFmdIndexes()) { _loaded.set(i); } _mappedByIdFields = _meta.getMappyedByIdFields(); // record whether there are any managed inverse fields if (_broker.getInverseManager() != null && _meta.hasInverseManagedFields()) _flags |= FLAG_INVERSES; pc.pcSetDetachedState(null); _pc = pc; if (_oid instanceof OpenJPAId) ((OpenJPAId) _oid).setManagedInstanceType(_meta.getDescribedType()); // initialize our state and add ourselves to the broker's cache setPCState(state); if (_oid == null || _broker.getStateManagerImplById(_oid, false) == null) { _broker.setStateManager(_id, this, BrokerImpl.STATUS_INIT); } if (state == PCState.PNEW) fireLifecycleEvent(LifecycleEvent.AFTER_PERSIST); // if this is a non-tracking PC, add a hard ref to the appropriate data // sets and give it an opportunity to make a state snapshot. if (!isIntercepting()) { saveFields(true); if (!isNew()) RedefinitionHelper.assignLazyLoadProxies(this); } }
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 www . j a va 2s. co m } } return result; }
From source file:bobs.is.compress.sevenzip.SevenZFile.java
private void readSubStreamsInfo(final DataInput header, final Archive archive) throws IOException { for (final Folder folder : archive.folders) { folder.numUnpackSubStreams = 1;/*w ww . ja v a 2 s. c o m*/ } int totalUnpackStreams = archive.folders.length; int nid = header.readUnsignedByte(); if (nid == NID.kNumUnpackStream) { totalUnpackStreams = 0; for (final Folder folder : archive.folders) { final long numStreams = readUint64(header); folder.numUnpackSubStreams = (int) numStreams; totalUnpackStreams += numStreams; } nid = header.readUnsignedByte(); } final SubStreamsInfo subStreamsInfo = new SubStreamsInfo(); subStreamsInfo.unpackSizes = new long[totalUnpackStreams]; subStreamsInfo.hasCrc = new BitSet(totalUnpackStreams); subStreamsInfo.crcs = new long[totalUnpackStreams]; int nextUnpackStream = 0; for (final Folder folder : archive.folders) { if (folder.numUnpackSubStreams == 0) { continue; } long sum = 0; if (nid == NID.kSize) { for (int i = 0; i < folder.numUnpackSubStreams - 1; i++) { final long size = readUint64(header); subStreamsInfo.unpackSizes[nextUnpackStream++] = size; sum += size; } } subStreamsInfo.unpackSizes[nextUnpackStream++] = folder.getUnpackSize() - sum; } if (nid == NID.kSize) { nid = header.readUnsignedByte(); } int numDigests = 0; for (final Folder folder : archive.folders) { if (folder.numUnpackSubStreams != 1 || !folder.hasCrc) { numDigests += folder.numUnpackSubStreams; } } if (nid == NID.kCRC) { final BitSet hasMissingCrc = readAllOrBits(header, numDigests); final long[] missingCrcs = new long[numDigests]; for (int i = 0; i < numDigests; i++) { if (hasMissingCrc.get(i)) { missingCrcs[i] = 0xffffFFFFL & Integer.reverseBytes(header.readInt()); } } int nextCrc = 0; int nextMissingCrc = 0; for (final Folder folder : archive.folders) { if (folder.numUnpackSubStreams == 1 && folder.hasCrc) { subStreamsInfo.hasCrc.set(nextCrc, true); subStreamsInfo.crcs[nextCrc] = folder.crc; ++nextCrc; } else { for (int i = 0; i < folder.numUnpackSubStreams; i++) { subStreamsInfo.hasCrc.set(nextCrc, hasMissingCrc.get(nextMissingCrc)); subStreamsInfo.crcs[nextCrc] = missingCrcs[nextMissingCrc]; ++nextCrc; ++nextMissingCrc; } } } nid = header.readUnsignedByte(); } if (nid != NID.kEnd) { throw new IOException("Badly terminated SubStreamsInfo"); } archive.subStreamsInfo = subStreamsInfo; }
From source file:org.lwes.serializer.Deserializer.java
public static BitSet deserializeBitSet(DeserializerState myState, byte[] bytes) { int size = deserializeUINT16(myState, bytes); int numBytes = (int) Math.ceil(size / 8.0); BitSet bitSet = new BitSet(size); int offset = myState.currentIndex(); int index = 0; for (int i = 0; i < numBytes; i++) { int val = bytes[offset + i]; for (int j = 0; j < 8; j++) { bitSet.set(index++, ((val & (1 << j)) != 0)); }// w w w . j ava 2 s. c o m } myState.incr(numBytes); return bitSet; }
From source file:org.wso2.andes.subscription.TopicSubscriptionBitMapStore.java
/** * This methods adds a constituent table with only null and other constituents. * This is required when a message comes with more than the available number of constituents. If wildcard * subscriptions are available for those, they should match. Hence need to create these empty constituent tables. *//* w w w .ja va 2 s .co m*/ private void addEmptyConstituentTable() { int noOfSubscriptions = subscriptionList.size(); Map<String, BitSet> constituentTable = new HashMap<String, BitSet>(); BitSet nullBitSet = new BitSet(noOfSubscriptions); BitSet otherBitSet = new BitSet(noOfSubscriptions); if (noOfSubscriptions > 0) { // Null constituent will always be true for empty constituents, hence need to flip nullBitSet.flip(0, noOfSubscriptions - 1); for (int subscriptionIndex = 0; subscriptionIndex < noOfSubscriptions; subscriptionIndex++) { // For 'other', if subscribers last constituent is multi level wild card then matching String[] allConstituent = subscriptionConstituents.get(subscriptionIndex); String lastConstituent = allConstituent[allConstituent.length - 1]; if (multiLevelWildCard.equals(lastConstituent)) { otherBitSet.set(subscriptionIndex); } else { otherBitSet.set(subscriptionIndex, false); } } } constituentTable.put(NULL_CONSTITUENT, nullBitSet); constituentTable.put(OTHER_CONSTITUENT, otherBitSet); constituentTables.add(constituentTable); }
From source file:org.onosproject.tetopology.management.SimpleTeTopologyStore.java
@Override public void updateNetwork(Network network) { InternalNetwork curNetwork = networkMap.get(network.networkId()); if (curNetwork != null) { // Existing topology update // Remove existing map entries first, removeNetworkMapEntrys(curNetwork, false); }/*from ww w . j a v a 2 s . co m*/ TeTopologyKey topoKey = null; if (network.teTopologyId() != null) { topoKey = newTeTopologyKey(network.teTopologyId()); } // Update TE nodes List<TeNodeKey> teNodeKeys = null; if (MapUtils.isNotEmpty(network.nodes())) { teNodeKeys = Lists.newArrayList(); for (Map.Entry<KeyId, NetworkNode> entry : network.nodes().entrySet()) { NetworkNodeKey nodeKey = new NetworkNodeKey(network.networkId(), entry.getKey()); TeNodeKey teNodeKey = null; if (topoKey != null && entry.getValue().teNode() != null) { teNodeKey = new TeNodeKey(topoKey, entry.getValue().teNode().teNodeId()); } updateNetworkNode(nodeKey, entry.getValue(), true, false, teNodeKey); teNodeKeys.add(teNodeKey); } } // Update TE links List<TeLinkTpGlobalKey> teLinkKeys = null; if (MapUtils.isNotEmpty(network.links())) { teLinkKeys = Lists.newArrayList(); for (Map.Entry<KeyId, NetworkLink> entry : network.links().entrySet()) { NetworkLinkKey linkKey = new NetworkLinkKey(network.networkId(), entry.getKey()); TeLinkTpGlobalKey teLinkKey = null; if (topoKey != null && entry.getValue().teLink() != null) { teLinkKey = new TeLinkTpGlobalKey(topoKey, entry.getValue().teLink().teLinkKey()); } updateNetworkLink(linkKey, entry.getValue(), true, false, teLinkKey); teLinkKeys.add(teLinkKey); } } // New network, update TE Topology first if (curNetwork == null) { InternalTeTopology intTopo = new InternalTeTopology(network.teTopologyId().topologyId()); intTopo.setTeNodeKeys(teNodeKeys); intTopo.setTeLinkKeys(teLinkKeys); BitSet flags = new BitSet(TeConstants.FLAG_MAX_BITS); flags.set(TeTopology.BIT_LEARNT); if (network.teTopologyId().clientId() == TeTopologyManager.DEFAULT_PROVIDER_ID) { // Hard rule for now flags.set(TeTopology.BIT_CUSTOMIZED); } CommonTopologyData common = new CommonTopologyData(network.networkId(), OptimizationType.NOT_OPTIMIZED, flags, network.ownerId()); intTopo.setTopologydata(common); teTopologyMap.put(topoKey, intTopo); // Assume new topology TeTopologyEvent topologyEvent = new TeTopologyEvent(TE_TOPOLOGY_ADDED, teTopology(topoKey)); notifyDelegate(topologyEvent); } // Finally Update networkMap InternalNetwork newNetwork = new InternalNetwork(network); newNetwork.setTeTopologyKey(topoKey); networkMap.put(network.networkId(), newNetwork); // Assume new network TeTopologyEvent topologyEvent = new TeTopologyEvent(NETWORK_ADDED, network(network.networkId())); notifyDelegate(topologyEvent); }
From source file:org.wso2.andes.subscription.ClusterSubscriptionBitMapHandler.java
/** * This methods adds a constituent table with only null and other constituents. * This is required when a message comes with more than the available number of constituents. If wildcard * subscriptions are available for those, they should match. Hence need to create these empty constituent tables. *///from w w w. j a v a 2s . c o m private void addEmptyConstituentTable() { int noOfSubscriptions = wildCardSubscriptionList.size(); Map<String, BitSet> constituentTable = new HashMap<String, BitSet>(); BitSet nullBitSet = new BitSet(noOfSubscriptions); BitSet otherBitSet = new BitSet(noOfSubscriptions); if (noOfSubscriptions > 0) { // Null constituent will always be true for empty constituents, hence need to flip nullBitSet.flip(0, noOfSubscriptions - 1); for (int subscriptionIndex = 0; subscriptionIndex < noOfSubscriptions; subscriptionIndex++) { // For 'other', if subscribers last constituent is multi level wild card then matching String[] allConstituent = subscriptionConstituents.get(subscriptionIndex); String lastConstituent = allConstituent[allConstituent.length - 1]; if (multiLevelWildCard.equals(lastConstituent)) { otherBitSet.set(subscriptionIndex); } else { otherBitSet.set(subscriptionIndex, false); } } } constituentTable.put(NULL_CONSTITUENT, nullBitSet); constituentTable.put(OTHER_CONSTITUENT, otherBitSet); constituentTables.add(constituentTable); }
From source file:bobs.is.compress.sevenzip.SevenZOutputFile.java
private void writeFileEmptyFiles(final DataOutput header) throws IOException { boolean hasEmptyFiles = false; int emptyStreamCounter = 0; final BitSet emptyFiles = new BitSet(0); for (final SevenZArchiveEntry file1 : files) { if (!file1.hasStream()) { final boolean isDir = file1.isDirectory(); emptyFiles.set(emptyStreamCounter++, !isDir); hasEmptyFiles |= !isDir;/*w w w.ja v a2s . co m*/ } } if (hasEmptyFiles) { header.write(NID.kEmptyFile); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream out = new DataOutputStream(baos); writeBits(out, emptyFiles, emptyStreamCounter); out.flush(); final byte[] contents = baos.toByteArray(); writeUint64(header, contents.length); header.write(contents); } }
From source file:hivemall.smile.classification.GradientTreeBoostingClassifierUDTF.java
/** * Train L-k tree boost./*from www . java 2 s . com*/ */ private void traink(final double[][] x, final int[] y, final int k) throws HiveException { final int numVars = SmileExtUtils.computeNumInputVars(_numVars, x); if (logger.isInfoEnabled()) { logger.info("k: " + k + ", numTrees: " + _numTrees + ", shirinkage: " + _eta + ", subsample: " + _subsample + ", numVars: " + numVars + ", minSamplesSplit: " + _minSamplesSplit + ", maxDepth: " + _maxDepth + ", maxLeafs: " + _maxLeafNodes + ", seed: " + _seed); } final int numInstances = x.length; final int numSamples = (int) Math.round(numInstances * _subsample); final double[][] h = new double[k][numInstances]; // boost tree output. final double[][] p = new double[k][numInstances]; // posteriori probabilities. final double[][] response = new double[k][numInstances]; // pseudo response. final int[][] order = SmileExtUtils.sort(_attributes, x); final RegressionTree.NodeOutput[] output = new LKNodeOutput[k]; for (int i = 0; i < k; i++) { output[i] = new LKNodeOutput(response[i], k); } final BitSet sampled = new BitSet(numInstances); final int[] bag = new int[numSamples]; final int[] perm = new int[numSamples]; for (int i = 0; i < numSamples; i++) { perm[i] = i; } long s = (this._seed == -1L) ? SmileExtUtils.generateSeed() : new smile.math.Random(_seed).nextLong(); final smile.math.Random rnd1 = new smile.math.Random(s); final smile.math.Random rnd2 = new smile.math.Random(rnd1.nextLong()); // out-of-bag prediction final int[] prediction = new int[numInstances]; for (int m = 0; m < _numTrees; m++) { for (int i = 0; i < numInstances; i++) { double max = Double.NEGATIVE_INFINITY; for (int j = 0; j < k; j++) { final double h_ji = h[j][i]; if (max < h_ji) { max = h_ji; } } double Z = 0.0d; for (int j = 0; j < k; j++) { double p_ji = Math.exp(h[j][i] - max); p[j][i] = p_ji; Z += p_ji; } for (int j = 0; j < k; j++) { p[j][i] /= Z; } } final RegressionTree[] trees = new RegressionTree[k]; Arrays.fill(prediction, -1); double max_h = Double.NEGATIVE_INFINITY; int oobTests = 0, oobErrors = 0; for (int j = 0; j < k; j++) { reportProgress(_progressReporter); final double[] response_j = response[j]; final double[] p_j = p[j]; final double[] h_j = h[j]; for (int i = 0; i < numInstances; i++) { if (y[i] == j) { response_j[i] = 1.0d; } else { response_j[i] = 0.0d; } response_j[i] -= p_j[i]; } SmileExtUtils.shuffle(perm, rnd1); for (int i = 0; i < numSamples; i++) { int index = perm[i]; bag[i] = index; sampled.set(i); } RegressionTree tree = new RegressionTree(_attributes, x, response[j], numVars, _maxDepth, _maxLeafNodes, _minSamplesSplit, _minSamplesLeaf, order, bag, output[j], rnd2); trees[j] = tree; for (int i = 0; i < numInstances; i++) { double h_ji = h_j[i] + _eta * tree.predict(x[i]); h_j[i] += h_ji; if (h_ji > max_h) { max_h = h_ji; prediction[i] = j; } } } // for each k // out-of-bag error estimate for (int i = sampled.nextClearBit(0); i < numInstances; i = sampled.nextClearBit(i + 1)) { oobTests++; if (prediction[i] != y[i]) { oobErrors++; } } sampled.clear(); float oobErrorRate = 0.f; if (oobTests > 0) { oobErrorRate = ((float) oobErrors) / oobTests; } // forward a row forward(m + 1, 0.d, _eta, oobErrorRate, trees); } // for each m }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.ExtractCommonOperatorsRule.java
private void candidatesGrow(List<Mutable<ILogicalOperator>> opList, List<Mutable<ILogicalOperator>> candidates) { List<Mutable<ILogicalOperator>> previousCandidates = new ArrayList<Mutable<ILogicalOperator>>(); previousCandidates.addAll(candidates); candidates.clear();//from ww w .j a v a 2 s. c o m boolean validCandidate = false; for (Mutable<ILogicalOperator> op : opList) { List<Mutable<ILogicalOperator>> inputs = op.getValue().getInputs(); for (int i = 0; i < inputs.size(); i++) { Mutable<ILogicalOperator> inputRef = inputs.get(i); validCandidate = false; for (Mutable<ILogicalOperator> candidate : previousCandidates) { // if current input is in candidates if (inputRef.getValue().equals(candidate.getValue())) { if (inputs.size() == 1) { validCandidate = true; } else { BitSet candidateInputBitMap = opToCandidateInputs.get(op); if (candidateInputBitMap == null) { candidateInputBitMap = new BitSet(inputs.size()); opToCandidateInputs.put(op, candidateInputBitMap); } candidateInputBitMap.set(i); if (candidateInputBitMap.cardinality() == inputs.size()) { validCandidate = true; } } break; } } } if (!validCandidate) continue; if (!candidates.contains(op)) candidates.add(op); } }