List of usage examples for java.util BitSet set
public void set(int fromIndex, int toIndex)
From source file:org.apache.carbondata.core.scan.partition.PartitionUtil.java
public static BitSet generateBitSetBySize(int size, boolean isContainAll) { BitSet bitSet = new BitSet(size); if (isContainAll) { bitSet.set(0, size); }//from ww w . ja va 2s .c om return bitSet; }
From source file:org.efaps.admin.datamodel.attributetype.BitEnumType.java
/** * @param _int integer the BitSet is wanted for * @return BitSet representing the given integer *///from ww w . j a va 2 s. c o m public static BitSet getBitSet(final int _int) { final char[] bits = Integer.toBinaryString(_int).toCharArray(); ArrayUtils.reverse(bits); final BitSet bitSet = new BitSet(bits.length); for (int i = 0; i < bits.length; i++) { if (bits[i] == '1') { bitSet.set(i, true); } else { bitSet.set(i, false); } } return bitSet; }
From source file:org.apache.hawq.pxf.service.utilities.AnalyzeUtils.java
/** * Marks sampleSize bits out of the poolSize, in a uniform way. * * @param poolSize pool size//from w w w. j a va2 s .com * @param sampleSize sample size * @return bit set with sampleSize bits set out of poolSize. */ static public BitSet generateSamplingBitSet(int poolSize, int sampleSize) { int skip = 0, chosen = 0, curIndex = 0; BitSet bitSet = new BitSet(); if (poolSize <= 0 || sampleSize <= 0) { return bitSet; } if (sampleSize >= poolSize) { LOG.debug("sampling bit map has " + poolSize + " elements (100%)"); bitSet.set(0, poolSize); return bitSet; } skip = (poolSize / sampleSize) + 1; while (chosen < sampleSize) { bitSet.set(curIndex); chosen++; if (chosen == sampleSize) { break; } for (int i = 0; i < skip; ++i) { curIndex = nextClearBitModulo((++curIndex) % poolSize, poolSize, bitSet); if (curIndex == -1) { // should never happen throw new IllegalArgumentException("Trying to sample more than pool size " + "(pool size " + poolSize + ", sampling size " + sampleSize); } } } LOG.debug("sampling bit map has " + chosen + " elements:" + bitSet.toString()); return bitSet; }
From source file:HexUtil.java
/** * Read bits from a byte array into a bitset * @param b the byte[] to read from// ww w . jav a2s.c om * @param ba the bitset to write to */ public static void bytesToBits(byte[] b, BitSet ba, int maxSize) { int x = 0; for (int i = 0; i < b.length; i++) { for (int j = 0; j < 8; j++) { if (x > maxSize) break; int mask = 1 << j; boolean value = (mask & b[i]) != 0; ba.set(x, value); x++; } } }
From source file:com.roche.sequencing.bioinformatics.common.utils.BitSetUtil.java
/** * converts a string to a bitset counting all 1's as true and all other characters as false * //from ww w.ja va 2 s . co m * @param bitsAsBinaryString * @return */ public static BitSet createBitSetFromBinaryString(String bitsAsBinaryString) { BitSet bitSet = new BitSet(bitsAsBinaryString.length()); for (int i = 0; i < bitsAsBinaryString.length(); i++) { if (bitsAsBinaryString.substring(i, i + 1).equals("1")) { bitSet.set(i, true); } else { bitSet.set(i, false); } } return bitSet; }
From source file:de.uniba.wiai.lspi.chord.data.ID.java
private static BitSet bitsetResize(final BitSet a, final int numBits) { assert (numBits > 0); final BitSet b = new BitSet(numBits); for (int i = 0; i < Math.min(a.size(), numBits); ++i) b.set(i, a.get(i)); return b;/* w ww . j a v a2 s . c om*/ }
From source file:org.omnaest.utils.structure.array.ArrayUtils.java
/** * Calculates a {@link BitSet} which has its bits set to true at the same index where the related element from one array to the * other array is not {@link #equals(Object)} * /*from w ww .j ava 2 s. c om*/ * @param elements1 * @param elements2 * @return {@link BitSet} with modified index bits set to true */ public static <E> BitSet differenceBitSet(E[] elements1, E[] elements2) { final BitSet retvals = new BitSet(); if (elements1 == null && elements2 != null) { retvals.set(0, elements2.length); } else if (elements1 != null && elements2 == null) { retvals.set(0, elements1.length); } else if (elements1 != null && elements2 != null) { for (int ii = 0; ii < elements1.length || ii < elements2.length; ii++) { if (ii >= elements1.length || ii >= elements2.length) { retvals.set(ii); } else if (!org.apache.commons.lang3.ObjectUtils.equals(elements1[ii], elements2[ii])) { retvals.set(ii); } } } return retvals; }
From source file:com.roche.sequencing.bioinformatics.common.utils.BitSetUtil.java
/** * /* ww w .j av a 2s.c o m*/ * @param fromBitSet * @param fromBitSetLength * @param toBitSet * @param toBitsetStartInBits * @return the number of bits written */ public static int copy(BitSet fromBitSet, int fromBitSetLength, BitSet toBitSet, int toBitsetStartInBits) { for (int fromBitIndex = 0; fromBitIndex < fromBitSetLength; fromBitIndex++) { boolean isBitOn = fromBitSet.get(fromBitIndex); int toBitIndex = toBitsetStartInBits + fromBitIndex; toBitSet.set(toBitIndex, isBitOn); } return fromBitSetLength; }
From source file:de.uniba.wiai.lspi.chord.data.ID.java
private static void partHashSet(final BitSet dst, final int dstOffset, final BitSet src, final int srcLen) { assert (dstOffset + srcLen <= dst.size()); for (int i = 0; i < Math.min(src.size(), srcLen); ++i) dst.set(dstOffset + i, src.get(i)); }
From source file:de.uniba.wiai.lspi.chord.data.ID.java
public static IdSpan ServiceId(ServiceId svcId) { final ID bgn = new ID(hashServiceId(svcId)); final BitSet bsEndIncl = (BitSet) bgn.id.clone(); final Fn2<Integer, Integer, Unit> endFillBits = (Integer offset, Integer len) -> { assert (offset + len <= kTotalBitLen); bsEndIncl.set(offset, offset + len); return Unit.U; };/*from w ww . ja va2 s . c o m*/ for (int i = svcId.partsGivenCount(); i < ServiceId.kPartsSemantic; ++i) endFillBits.apply(i * kSemanticPartBitLen, kSemanticPartBitLen); if (svcId.getProviderPart() == null) endFillBits.apply(kSemanticTotalBitLen, kProviderBitLen); final ID end = new ID(bsEndIncl); return IdSpan.Inclusive(bgn, end); }