List of usage examples for java.util BitSet set
public void set(int bitIndex)
From source file:asterix.parser.classad.ClassAdParser.java
private void parseRecord(ARecordType recType, ClassAd pAd, DataOutput out) throws IOException, AsterixException { ArrayBackedValueStorage fieldValueBuffer = getTempBuffer(); ArrayBackedValueStorage fieldNameBuffer = getTempBuffer(); IARecordBuilder recBuilder = getRecordBuilder(); BitSet nulls = null; if (recType != null) { nulls = getBitSet();/*from w w w .ja va 2s .c om*/ recBuilder.reset(recType); } else { recBuilder.reset(null); } recBuilder.init(); Boolean openRecordField = false; int fieldId = 0; IAType fieldType = null; // new stuff Map<CaseInsensitiveString, ExprTree> attrs = pAd.getAttrList(); for (Entry<CaseInsensitiveString, ExprTree> entry : attrs.entrySet()) { // reset buffers fieldNameBuffer.reset(); fieldValueBuffer.reset(); // take care of field name String fldName = entry.getKey().get(); if (recType != null) { fieldId = recBuilder.getFieldId(fldName); if (fieldId < 0 && !recType.isOpen()) { throw new HyracksDataException("This record is closed, you can not add extra fields !!"); } else if (fieldId < 0 && recType.isOpen()) { aStringFieldName.setValue(fldName); stringSerde.serialize(aStringFieldName, fieldNameBuffer.getDataOutput()); openRecordField = true; fieldType = null; } else { // a closed field nulls.set(fieldId); fieldType = recType.getFieldTypes()[fieldId]; openRecordField = false; } } else { aStringFieldName.setValue(fldName); stringSerde.serialize(aStringFieldName, fieldNameBuffer.getDataOutput()); openRecordField = true; fieldType = null; } // add field value to value buffer writeFieldValueToBuffer(fieldType, fieldValueBuffer.getDataOutput(), fldName, entry.getValue(), pAd); if (openRecordField) { if (fieldValueBuffer.getByteArray()[0] != ATypeTag.NULL.serialize()) { recBuilder.addField(fieldNameBuffer, fieldValueBuffer); } } else if (NonTaggedFormatUtil.isOptional(fieldType)) { if (fieldValueBuffer.getByteArray()[0] != ATypeTag.NULL.serialize()) { recBuilder.addField(fieldId, fieldValueBuffer); } } else { recBuilder.addField(fieldId, fieldValueBuffer); } } if (recType != null) { int nullableFieldId = checkNullConstraints(recType, nulls); if (nullableFieldId != -1) { throw new HyracksDataException( "Field: " + recType.getFieldNames()[nullableFieldId] + " can not be null"); } } recBuilder.write(out, true); }
From source file:org.roaringbitmap.TestRoaringBitmap.java
@Test public void flipTest8() { final RoaringBitmap rb = new RoaringBitmap(); rb.add(0);//from www . j a va 2s . c om rb.add(2); final RoaringBitmap rb2 = RoaringBitmap.flip(rb, 0, 3); final BitSet bs = new BitSet(); bs.set(1); Assert.assertTrue(equals(bs, rb2)); }
From source file:org.roaringbitmap.TestRoaringBitmap.java
@Test public void flipTest7() { // within 1 word, first container System.out.println("FlipTest7"); final RoaringBitmap rb = new RoaringBitmap(); rb.flip(650, 132000);//from w ww .ja va 2s . com rb.flip(648, 651); final int rbcard = rb.getCardinality(); // 648, 649, 651-131999 Assert.assertEquals(132000 - 651 + 2, rbcard); final BitSet bs = new BitSet(); bs.set(648); bs.set(649); for (int i = 651; i < 132000; ++i) bs.set(i); Assert.assertTrue(equals(bs, rb)); }
From source file:org.roaringbitmap.TestRoaringBitmap.java
@Test public void flipTest7A() { // within 1 word, first container System.out.println("FlipTest7A"); final RoaringBitmap rb = new RoaringBitmap(); final RoaringBitmap rb1 = RoaringBitmap.flip(rb, 650, 132000); final RoaringBitmap rb2 = RoaringBitmap.flip(rb1, 648, 651); final int rbcard = rb2.getCardinality(); // 648, 649, 651-131999 Assert.assertEquals(132000 - 651 + 2, rbcard); final BitSet bs = new BitSet(); bs.set(648); bs.set(649);/*from www .ja va2 s . c o m*/ for (int i = 651; i < 132000; ++i) bs.set(i); Assert.assertTrue(equals(bs, rb2)); }
From source file:com.oltpbenchmark.benchmarks.seats.SEATSWorker.java
private boolean executeNewReservation(NewReservation proc) throws SQLException { Reservation reservation = null;/* ww w.ja v a 2 s. c o m*/ BitSet seats = null; LinkedList<Reservation> cache = CACHE_RESERVATIONS.get(CacheType.PENDING_INSERTS); assert (cache != null) : "Unexpected " + CacheType.PENDING_INSERTS; if (LOG.isDebugEnabled()) LOG.debug(String.format("Attempting to get a new pending insert Reservation [totalPendingInserts=%d]", cache.size())); while (reservation == null) { Reservation r = cache.poll(); if (r == null) { if (LOG.isDebugEnabled()) LOG.warn("Unable to execute " + proc + " - No available reservations to insert"); break; } seats = getSeatsBitSet(r.flight_id); if (isFlightFull(seats)) { if (LOG.isDebugEnabled()) LOG.debug(String.format("%s is full", r.flight_id)); continue; } // PAVLO: Not sure why this is always coming back as reserved? // else if (seats.get(r.seatnum)) { // if (LOG.isDebugEnabled()) // LOG.debug(String.format("Seat #%d on %s is already booked", r.seatnum, r.flight_id)); // continue; // } else if (isCustomerBookedOnFlight(r.customer_id, r.flight_id)) { if (LOG.isDebugEnabled()) LOG.debug(String.format("%s is already booked on %s", r.customer_id, r.flight_id)); continue; } reservation = r; } // WHILE if (reservation == null) { if (LOG.isDebugEnabled()) LOG.warn("Failed to find a valid pending insert Reservation\n" + this.toString()); return (false); } // Generate a random price for now double price = 2.0 * rng.number(SEATSConstants.RESERVATION_PRICE_MIN, SEATSConstants.RESERVATION_PRICE_MAX); // Generate random attributes long attributes[] = new long[9]; for (int i = 0; i < attributes.length; i++) { attributes[i] = rng.nextLong(); } // FOR if (LOG.isTraceEnabled()) LOG.trace("Calling " + proc); proc.run(conn, reservation.id, reservation.customer_id.encode(), reservation.flight_id.encode(), reservation.seatnum, price, attributes); conn.commit(); // Mark this seat as successfully reserved seats.set(reservation.seatnum); // Set it up so we can play with it later this.requeueReservation(reservation); return (true); }
From source file:org.roaringbitmap.TestRoaringBitmap.java
@Test public void flipTest2A() { final RoaringBitmap rb = new RoaringBitmap(); final RoaringBitmap rb1 = RoaringBitmap.flip(rb, 100000, 100000); rb.add(1); // will not affect rb1 (no shared container) final int rbcard = rb1.getCardinality(); Assert.assertEquals(0, rbcard);//from ww w . j a v a 2s . c o m Assert.assertEquals(1, rb.getCardinality()); final BitSet bs = new BitSet(); Assert.assertTrue(equals(bs, rb1)); bs.set(1); Assert.assertTrue(equals(bs, rb)); }
From source file:org.roaringbitmap.TestRoaringBitmap.java
@Test public void flipTest1() { final RoaringBitmap rb = new RoaringBitmap(); rb.flip(100000, 200000); // in-place on empty bitmap final int rbcard = rb.getCardinality(); Assert.assertEquals(100000, rbcard); final BitSet bs = new BitSet(); for (int i = 100000; i < 200000; ++i) bs.set(i); Assert.assertTrue(equals(bs, rb));// www. j av a2 s. c o m }
From source file:org.roaringbitmap.TestRoaringBitmap.java
@Test public void flipTest3() { final RoaringBitmap rb = new RoaringBitmap(); rb.flip(100000, 200000); // got 100k-199999 rb.flip(100000, 199991); // give back 100k-199990 final int rbcard = rb.getCardinality(); Assert.assertEquals(9, rbcard);/*from ww w . j a v a 2 s .c o m*/ final BitSet bs = new BitSet(); for (int i = 199991; i < 200000; ++i) bs.set(i); Assert.assertTrue(equals(bs, rb)); }
From source file:org.roaringbitmap.TestRoaringBitmap.java
@Test public void flipTest3A() { System.out.println("FlipTest3A"); final RoaringBitmap rb = new RoaringBitmap(); final RoaringBitmap rb1 = RoaringBitmap.flip(rb, 100000, 200000); final RoaringBitmap rb2 = RoaringBitmap.flip(rb1, 100000, 199991); final int rbcard = rb2.getCardinality(); Assert.assertEquals(9, rbcard);/* w ww . j a va 2 s . com*/ final BitSet bs = new BitSet(); for (int i = 199991; i < 200000; ++i) bs.set(i); Assert.assertTrue(equals(bs, rb2)); }
From source file:org.roaringbitmap.TestRoaringBitmap.java
@Test public void flipTest5A() { System.out.println("FlipTest5A"); final RoaringBitmap rb = new RoaringBitmap(); final RoaringBitmap rb1 = RoaringBitmap.flip(rb, 100000, 132000); final RoaringBitmap rb2 = RoaringBitmap.flip(rb1, 65536, 120000); final int rbcard = rb2.getCardinality(); Assert.assertEquals(46464, rbcard);/*ww w . ja v a2 s . c o m*/ final BitSet bs = new BitSet(); for (int i = 65536; i < 100000; ++i) bs.set(i); for (int i = 120000; i < 132000; ++i) bs.set(i); Assert.assertTrue(equals(bs, rb2)); }