/** * Gets background color for cell for row ic. Override it if you want to change the color from the * default. */ public Color getBackgroundColorOfCell(int it, boolean selected) { if (observedStates == null) { doCalcs(); if (observedStates == null) return null; } if (observedStates.getParentData() != null) { captureCharacterDataFromObservedStates(); Associable tInfo = data.getTaxaInfo(false); NameReference genBankColor = NameReference.getNameReference("genbankcolor"); Object obj = tInfo.getAssociatedObject(genBankColor, it); // not saved to file if (obj instanceof Color) return (Color) obj; } if (bits == null || it < 0 || it > bits.getSize()) return null; String note = getNote(it); if (selected) { if (bits.isBitOn(it)) return ColorDistribution.darkGreen; else return ColorDistribution.darkRed; } else if (bits.isBitOn(it)) { if (StringUtil.blank(note)) return ColorDistribution.veryLightGreen; if (!(note.equalsIgnoreCase("x"))) return ColorDistribution.lightGreenYellowish; return ColorDistribution.lightGreenYellow; } else { if (StringUtil.blank(note)) return ColorDistribution.brown; if (!(note.equalsIgnoreCase("x"))) { return Color.red; } return ColorDistribution.lightRed; } }
/** * Ensures that the bit set has the capacity to represent the given value. * * @param value {@code >= 0;} value to represent */ private void ensureCapacity(int value) { if (value >= Bits.getMax(bits)) { int[] newBits = Bits.makeBitSet(Math.max(value + 1, 2 * Bits.getMax(bits))); System.arraycopy(bits, 0, newBits, 0, bits.length); bits = newBits; } }
public void onNewConnection(long id) { Bits toSend = new Bits(); toSend.writeByte((byte) NetCode.CONNECT_UDP.ordinal()); toSend.writeLong(id); toSend.writeShort((short) udpServer.getPort()); sendData(id, toSend); }
public String getStringForTaxon(int it) { String note = getNote(it); if (note != null) return note; if (observedStates == null) doCalcs(); if (bits == null || it < 0 || it > bits.getSize()) return "?"; if (bits.isBitOn(it)) return "Yes"; else return "No Data"; }
public void atPut(int offset, boolean value) { int index = indexFor(offset); int pos = offset % bitsPerWord; if (value) { data[index] = Bits.setNthBit(data[index], pos); } else { data[index] = Bits.clearNthBit(data[index], pos); } }
public void readFrom(DataInput in) throws Exception { status = in.readInt(); classname = Bits.readString(in); name = Bits.readString(in); start_time = in.readLong(); stop_time = in.readLong(); failure_type = Bits.readString(in); failure_msg = Bits.readString(in); stack_trace = Bits.readString(in); }
public void writeTo(DataOutput out) throws Exception { out.writeInt(status); Bits.writeString(classname, out); Bits.writeString(name, out); out.writeLong(start_time); out.writeLong(stop_time); Bits.writeString(failure_type, out); Bits.writeString(failure_msg, out); Bits.writeString(stack_trace, out); }
public boolean equals(Bits compare) { int equal = 0; if (bits.length == compare.length()) { for (int i = 0; i < bits.length; i++) { if (this.getBit(i).getValue() == compare.getBit(i).getValue()) equal++; } } if (equal == compare.length()) { return true; } return false; }
private int count_bit_noESC_from3(final int[] ix, int ixPos, final int end, int t1, Bits s) { /* No ESC-words */ int sum1 = 0; int sum2 = 0; int sum3 = 0; final int xlen = Tables.ht[t1].xlen; final int[] hlen1 = Tables.ht[t1].hlen; final int[] hlen2 = Tables.ht[t1 + 1].hlen; final int[] hlen3 = Tables.ht[t1 + 2].hlen; do { final int x = ix[ixPos + 0] * xlen + ix[ixPos + 1]; ixPos += 2; sum1 += hlen1[x]; sum2 += hlen2[x]; sum3 += hlen3[x]; } while (ixPos < end); int t = t1; if (sum1 > sum2) { sum1 = sum2; t++; } if (sum1 > sum3) { sum1 = sum3; t = t1 + 2; } s.bits += sum1; return t; }
private int count_bit_noESC_from2(final int[] ix, int ixPos, final int end, int t1, Bits s) { /* No ESC-words */ int sum = 0, sum2; final int xlen = Tables.ht[t1].xlen; final int[] hlen; if (t1 == 2) hlen = Tables.table23; else hlen = Tables.table56; do { final int x = ix[ixPos + 0] * xlen + ix[ixPos + 1]; ixPos += 2; sum += hlen[x]; } while (ixPos < end); sum2 = sum & 0xffff; sum >>= 16; if (sum > sum2) { sum = sum2; t1++; } s.bits += sum; return t1; }
private static void printDocs(DirectoryReader r) throws Throwable { for (AtomicReaderContext ctx : r.leaves()) { // TODO: improve this AtomicReader sub = ctx.reader(); Bits liveDocs = sub.getLiveDocs(); System.out.println(" " + ((SegmentReader) sub).getSegmentInfo()); for (int docID = 0; docID < sub.maxDoc(); docID++) { StoredDocument doc = sub.document(docID); if (liveDocs == null || liveDocs.get(docID)) { System.out.println(" docID=" + docID + " id:" + doc.get("id")); } else { System.out.println(" DEL docID=" + docID + " id:" + doc.get("id")); } } } }
final void readTIndexed32() { int index = -1; if (interrupted()) index = resumeInt(); if (index < 0) { if (!canReadInteger()) { interruptInt(index); return; } int bits = readInteger(); for (int i = 0; i < _versions.length; i++) ((TIndexed32Read) _versions[i]).setBits(bits); index = 0; } if (_versions[0] instanceof Version32) { Version32 version32 = (Version32) _versions[0]; TGenerated generated = (TGenerated) version32.object(); for (; index < generated.getFieldCount(); index++) { if (Bits.get(version32.getBits(), index)) { version32.readWrite(this, index, _versions); if (interrupted()) { interruptInt(index); return; } } } } }
public void writeTo(DataOutput out) throws Exception { out.writeByte(type); switch (type) { case DATA: Bits.writeLong(seqno, out); out.writeShort(conn_id); out.writeBoolean(first); break; case ACK: Bits.writeLong(seqno, out); out.writeShort(conn_id); break; case SEND_FIRST_SEQNO: Bits.writeLong(seqno, out); break; } }
public void readFrom(DataInput in) throws Exception { type = in.readByte(); switch (type) { case DATA: seqno = Bits.readLong(in); conn_id = in.readShort(); first = in.readBoolean(); break; case ACK: seqno = Bits.readLong(in); conn_id = in.readShort(); break; case SEND_FIRST_SEQNO: seqno = Bits.readLong(in); break; } }
/** @inheritDoc */ public String toString() { StringBuilder sb = new StringBuilder(); sb.append('{'); boolean first = true; for (int i = Bits.findFirst(bits, 0); i >= 0; i = Bits.findFirst(bits, i + 1)) { if (!first) { sb.append(", "); } first = false; sb.append(i); } sb.append('}'); return sb.toString(); }
public final int size() { int retval = Global.BYTE_SIZE; // type switch (type) { case DATA: retval += Bits.size(seqno) // seqno + Global.SHORT_SIZE // conn_id + Global.BYTE_SIZE; // first break; case ACK: retval += Bits.size(seqno) + Global.SHORT_SIZE; // conn_id break; case SEND_FIRST_SEQNO: retval += Bits.size(seqno); break; } return retval; }
/** Test Bits.nextBit(int). */ public static void main(String[] args) { java.util.Random r = new java.util.Random(); Bits bits = new Bits(); int dupCount = 0; for (int i = 0; i < 125; i++) { int k; do { k = r.nextInt(250); } while (bits.isMember(k)); System.out.println("adding " + k); bits.incl(k); } int count = 0; for (int i = bits.nextBit(0); i >= 0; i = bits.nextBit(i + 1)) { System.out.println("found " + i); count++; } if (count != 125) throw new Error(); }
public CharBuffer get(char[] dst, int offset, int length) { if ((length << 1) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) { checkBounds(offset, length, dst.length); int pos = position(); int lim = limit(); assert (pos <= lim); int rem = (pos <= lim ? lim - pos : 0); if (length > rem) throw new BufferUnderflowException(); if (order() != ByteOrder.nativeOrder()) Bits.copyToCharArray(ix(pos), dst, offset << 1, length << 1); else Bits.copyToByteArray(ix(pos), dst, offset << 1, length << 1); position(pos + length); } else { super.get(dst, offset, length); } return this; }
public CharBuffer put(char[] src, int offset, int length) { if ((length << 1) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) { checkBounds(offset, length, src.length); int pos = position(); int lim = limit(); assert (pos <= lim); int rem = (pos <= lim ? lim - pos : 0); if (length > rem) throw new BufferOverflowException(); if (order() != ByteOrder.nativeOrder()) Bits.copyFromCharArray(src, offset << 1, ix(pos), length << 1); else Bits.copyFromByteArray(src, offset << 1, ix(pos), length << 1); position(pos + length); } else { super.put(src, offset, length); } return this; }
public void doCalcs() { if (bits != null) bits.clearAllBits(); if (taxa == null) return; if (bits == null) bits = new Bits(taxa.getNumTaxa()); else bits.resetSize(taxa.getNumTaxa()); if (observedStates == null) { tInfo = null; observedStates = matrixSourceTask.getCurrentMatrix(taxa); if (observedStates != null) { captureCharacterDataFromObservedStates(); if (data != null) tInfo = data.getTaxaInfo(true); } } if (observedStates == null) return; for (int it = 0; it < taxa.getNumTaxa(); it++) { if (hasData(it)) bits.setBit(it); } }
/** * Codebook Search Unquantification (Split Shape). * * @param exc - excitation array. * @param es - position in excitation array. * @param nsf - number of samples in subframe. * @param bits - Speex bits buffer. */ public final void unquant(float[] exc, int es, int nsf, @NotNull Bits bits) { int i, j; /* Decode codewords and gains */ for (i = 0; i < nb_subvect; i++) { if (have_sign != 0) signs[i] = bits.unpack(1); else signs[i] = 0; ind[i] = bits.unpack(shape_bits); } /* Compute decoded excitation */ for (i = 0; i < nb_subvect; i++) { float s = 1.0f; if (signs[i] != 0) s = -1.0f; for (j = 0; j < subvect_size; j++) { exc[es + subvect_size * i + j] += s * 0.03125f * (float) shape_cb[ind[i] * subvect_size + j]; } } }
public static void writeSingleHits( IntBP positions, FloatBP weights, IntBP las, String prefix, int chrom) throws IOException { String postmp = getPositionsFname(prefix, chrom) + ".tmp"; String weightstmp = getWeightsFname(prefix, chrom) + ".tmp"; String lastmp = getLaSFname(prefix, chrom) + ".tmp"; RandomAccessFile positionsRAF = new RandomAccessFile(postmp, "rw"); RandomAccessFile weightsRAF = new RandomAccessFile(weightstmp, "rw"); RandomAccessFile lasRAF = new RandomAccessFile(lastmp, "rw"); Bits.sendBytes(positions.bb, 0, positions.bb.limit(), positionsRAF.getChannel()); Bits.sendBytes(weights.bb, 0, weights.bb.limit(), weightsRAF.getChannel()); Bits.sendBytes(las.bb, 0, las.bb.limit(), lasRAF.getChannel()); positionsRAF.close(); weightsRAF.close(); lasRAF.close(); /* ideally this part with the renames would atomic... */ (new File(postmp)).renameTo(new File(getPositionsFname(prefix, chrom))); (new File(weightstmp)).renameTo(new File(getWeightsFname(prefix, chrom))); (new File(lastmp)).renameTo(new File(getLaSFname(prefix, chrom))); }
/** @inheritDoc */ public void merge(IntSet other) { if (other instanceof BitIntSet) { BitIntSet o = (BitIntSet) other; ensureCapacity(Bits.getMax(o.bits) + 1); Bits.or(bits, o.bits); } else if (other instanceof ListIntSet) { ListIntSet o = (ListIntSet) other; int sz = o.ints.size(); if (sz > 0) { ensureCapacity(o.ints.get(sz - 1)); } for (int i = 0; i < o.ints.size(); i++) { Bits.set(bits, o.ints.get(i), true); } } else { IntIterator iter = other.iterator(); while (iter.hasNext()) { add(iter.next()); } } }
private int count_bit_noESC(final int[] ix, int ixPos, final int end, Bits s) { /* No ESC-words */ int sum1 = 0; final int[] hlen1 = Tables.ht[1].hlen; do { final int x = ix[ixPos + 0] * 2 + ix[ixPos + 1]; ixPos += 2; sum1 += hlen1[x]; } while (ixPos < end); s.bits += sum1; return 1; }
/** * Choose the Huffman table that will encode ix[begin..end] with the fewest bits. * * <p>Note: This code contains knowledge about the sizes and characteristics of the Huffman tables * as defined in the IS (Table B.7), and will not work with any arbitrary tables. */ private int choose_table(final int[] ix, final int ixPos, final int endPos, final Bits s) { int max = ix_max(ix, ixPos, endPos); switch (max) { case 0: return max; case 1: return count_bit_noESC(ix, ixPos, endPos, s); case 2: case 3: return count_bit_noESC_from2(ix, ixPos, endPos, huf_tbl_noESC[max - 1], s); case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: return count_bit_noESC_from3(ix, ixPos, endPos, huf_tbl_noESC[max - 1], s); default: /* try tables with linbits */ if (max > QuantizePVT.IXMAX_VAL) { s.bits = QuantizePVT.LARGE_BITS; return -1; } max -= 15; int choice2; for (choice2 = 24; choice2 < 32; choice2++) { if (Tables.ht[choice2].linmax >= max) { break; } } int choice; for (choice = choice2 - 8; choice < 24; choice++) { if (Tables.ht[choice].linmax >= max) { break; } } return count_bit_ESC(ix, ixPos, endPos, choice, choice2, s); } }
@Test public void testRandom() throws IOException { int numBytes = 1024; byte[] bits = new byte[numBytes]; ThreadLocalRandom.current().nextBytes(bits); BigInteger n = new BigInteger(bits); InputStream src = new ByteArrayInputStream(Bits.swapEndian(n.toByteArray())); BitInputStream in = new BitInputStream(src); int numBits = numBytes * 8; for (int i = 0; i < numBits; i++) { Assert.assertEquals(n.testBit(i), in.readBit()); } }
private boolean getNextLHC(PhEntry<T> result) { while (true) { if (++nFound > nMaxEntry) { return false; } long currentPos = Bits.readArray(node.ba, currentOffsetKey, Node.IK_WIDTH(dims)); currentOffsetKey += postEntryLenLHC; // check HC-pos if (checkHcPos(currentPos)) { // check post-fix if (readValue(nFound - 1, currentPos, result)) { next = currentPos; // This is required for kNN-adjusting of iterators return true; } } else if (currentPos > maskUpper) { return false; } } }
private int count_bit_ESC( final int[] ix, int ixPos, final int end, int t1, final int t2, Bits s) { /* ESC-table is used */ final int linbits = Tables.ht[t1].xlen * 65536 + Tables.ht[t2].xlen; int sum = 0, sum2; do { int x = ix[ixPos++]; int y = ix[ixPos++]; if (x != 0) { if (x > 14) { x = 15; sum += linbits; } x *= 16; } if (y != 0) { if (y > 14) { y = 15; sum += linbits; } x += y; } sum += Tables.largetbl[x]; } while (ixPos < end); sum2 = sum & 0xffff; sum >>= 16; if (sum > sum2) { sum = sum2; t1 = t2; } s.bits += sum; return t1; }
/** * Process <code>SERIAL_SIZE</code> short of speech. * * @param serial input : serial array encoded in bits_ld8k * @param sp16 output : speech short array */ void process(short[] serial, short[] sp16) { Bits.bits2prm_ld8k(serial, 2, parm, 1); /* the hardware detects frame erasures by checking if all bits are set to zero */ parm[0] = 0; /* No frame erasure */ for (int i = 2; i < SERIAL_SIZE; i++) if (serial[i] == 0) parm[0] = 1; /* frame erased */ /* check parity and put 1 in parm[4] if parity error */ parm[4] = PParity.check_parity_pitch(parm[3], parm[4]); int t0_first = decLd8k.decod_ld8k(parm, voicing, synth, synth_offset, Az_dec); /* Decoder */ /* Post-filter and decision on voicing parameter */ voicing = 0; float[] ptr_Az = Az_dec; /* Decoded Az for post-filter */ int ptr_Az_offset = 0; for (int i = 0; i < L_FRAME; i += L_SUBFR) { int sf_voic; /* voicing for subframe */ sf_voic = postfil.post(t0_first, synth, synth_offset + i, ptr_Az, ptr_Az_offset, pst_out, i); if (sf_voic != 0) { voicing = sf_voic; } ptr_Az_offset += MP1; } Util.copy(synth_buf, L_FRAME, synth_buf, M); postPro.post_process(pst_out, L_FRAME); floats2shorts(pst_out, sp16); }
public int size() { return Global.BYTE_SIZE + Bits.size(seqno) + Global.BYTE_SIZE; // type + seqno + flush_ack }