List of usage examples for java.util BitSet BitSet
public BitSet()
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);/* w w w .j a v a2 s . co 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 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);//w ww.j a va 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);//from w w w . j a v a2 s . c o m final BitSet bs = new BitSet(); for (int i = 199991; i < 200000; ++i) bs.set(i); Assert.assertTrue(equals(bs, rb2)); }
From source file:org.apache.flink.streaming.connectors.kafka.KafkaConsumerTestBase.java
/** * Runs a job using the provided environment to read a sequence of records from a single Kafka topic. * The method allows to individually specify the expected starting offset and total read value count of each partition. * The job will be considered successful only if all partition read results match the start offset and value count criteria. *//*w w w. j a v a 2 s . c o m*/ protected void readSequence(final StreamExecutionEnvironment env, final StartupMode startupMode, final Map<KafkaTopicPartition, Long> specificStartupOffsets, final Properties cc, final String topicName, final Map<Integer, Tuple2<Integer, Integer>> partitionsToValuesCountAndStartOffset) throws Exception { final int sourceParallelism = partitionsToValuesCountAndStartOffset.keySet().size(); int finalCountTmp = 0; for (Map.Entry<Integer, Tuple2<Integer, Integer>> valuesCountAndStartOffset : partitionsToValuesCountAndStartOffset .entrySet()) { finalCountTmp += valuesCountAndStartOffset.getValue().f0; } final int finalCount = finalCountTmp; final TypeInformation<Tuple2<Integer, Integer>> intIntTupleType = TypeInfoParser .parse("Tuple2<Integer, Integer>"); final TypeInformationSerializationSchema<Tuple2<Integer, Integer>> deser = new TypeInformationSerializationSchema<>( intIntTupleType, env.getConfig()); // create the consumer cc.putAll(secureProps); FlinkKafkaConsumerBase<Tuple2<Integer, Integer>> consumer = kafkaServer.getConsumer(topicName, deser, cc); switch (startupMode) { case EARLIEST: consumer.setStartFromEarliest(); break; case LATEST: consumer.setStartFromLatest(); break; case SPECIFIC_OFFSETS: consumer.setStartFromSpecificOffsets(specificStartupOffsets); break; case GROUP_OFFSETS: consumer.setStartFromGroupOffsets(); break; } DataStream<Tuple2<Integer, Integer>> source = env.addSource(consumer).setParallelism(sourceParallelism) .map(new ThrottledMapper<Tuple2<Integer, Integer>>(20)).setParallelism(sourceParallelism); // verify data source.flatMap(new RichFlatMapFunction<Tuple2<Integer, Integer>, Integer>() { private HashMap<Integer, BitSet> partitionsToValueCheck; private int count = 0; @Override public void open(Configuration parameters) throws Exception { partitionsToValueCheck = new HashMap<>(); for (Integer partition : partitionsToValuesCountAndStartOffset.keySet()) { partitionsToValueCheck.put(partition, new BitSet()); } } @Override public void flatMap(Tuple2<Integer, Integer> value, Collector<Integer> out) throws Exception { int partition = value.f0; int val = value.f1; BitSet bitSet = partitionsToValueCheck.get(partition); if (bitSet == null) { throw new RuntimeException("Got a record from an unknown partition"); } else { bitSet.set(val - partitionsToValuesCountAndStartOffset.get(partition).f1); } count++; LOG.info("Received message {}, total {} messages", value, count); // verify if we've seen everything if (count == finalCount) { for (Map.Entry<Integer, BitSet> partitionsToValueCheck : this.partitionsToValueCheck .entrySet()) { BitSet check = partitionsToValueCheck.getValue(); int expectedValueCount = partitionsToValuesCountAndStartOffset .get(partitionsToValueCheck.getKey()).f0; if (check.cardinality() != expectedValueCount) { throw new RuntimeException("Expected cardinality to be " + expectedValueCount + ", but was " + check.cardinality()); } else if (check.nextClearBit(0) != expectedValueCount) { throw new RuntimeException("Expected next clear bit to be " + expectedValueCount + ", but was " + check.cardinality()); } } // test has passed throw new SuccessException(); } } }).setParallelism(1); tryExecute(env, "Read data from Kafka"); LOG.info("Successfully read sequence for verification"); }
From source file:org.roaringbitmap.TestRoaringBitmap.java
@Test public void flipTest4() { // fits evenly on both ends System.out.println("FlipTest4"); final RoaringBitmap rb = new RoaringBitmap(); rb.flip(100000, 200000); // got 100k-199999 rb.flip(65536, 4 * 65536);//from ww w.j a v a 2s. c o m final int rbcard = rb.getCardinality(); // 65536 to 99999 are 1s // 200000 to 262143 are 1s: total card Assert.assertEquals(96608, rbcard); final BitSet bs = new BitSet(); for (int i = 65536; i < 100000; ++i) bs.set(i); for (int i = 200000; i < 262144; ++i) bs.set(i); Assert.assertTrue(equals(bs, rb)); }
From source file:org.roaringbitmap.TestRoaringBitmap.java
@Test public void flipTest4A() { System.out.println("FlipTest4A"); final RoaringBitmap rb = new RoaringBitmap(); final RoaringBitmap rb1 = RoaringBitmap.flip(rb, 100000, 200000); final RoaringBitmap rb2 = RoaringBitmap.flip(rb1, 65536, 4 * 65536); final int rbcard = rb2.getCardinality(); Assert.assertEquals(96608, rbcard);//from www. j av a 2 s . com final BitSet bs = new BitSet(); for (int i = 65536; i < 100000; ++i) bs.set(i); for (int i = 200000; i < 262144; ++i) bs.set(i); Assert.assertTrue(equals(bs, rb2)); }
From source file:org.roaringbitmap.TestRoaringBitmap.java
@Test public void flipTest5() { // fits evenly on small end, multiple // containers System.out.println("FlipTest5"); final RoaringBitmap rb = new RoaringBitmap(); rb.flip(100000, 132000);/* ww w .j a v a 2 s. c o m*/ rb.flip(65536, 120000); final int rbcard = rb.getCardinality(); // 65536 to 99999 are 1s // 120000 to 131999 Assert.assertEquals(46464, rbcard); 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, rb)); }
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);/*from ww w . j a 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)); }
From source file:org.roaringbitmap.TestRoaringBitmap.java
@Test public void flipTest6() { // fits evenly on big end, multiple containers System.out.println("FlipTest6"); final RoaringBitmap rb = new RoaringBitmap(); rb.flip(100000, 132000);/* w w w . ja va 2 s .c o m*/ rb.flip(99000, 2 * 65536); final int rbcard = rb.getCardinality(); // 99000 to 99999 are 1000 1s // 131072 to 131999 are 928 1s Assert.assertEquals(1928, rbcard); final BitSet bs = new BitSet(); for (int i = 99000; i < 100000; ++i) bs.set(i); for (int i = 2 * 65536; i < 132000; ++i) bs.set(i); Assert.assertTrue(equals(bs, rb)); }
From source file:org.roaringbitmap.TestRoaringBitmap.java
@Test public void flipTest6A() { System.out.println("FlipTest6A"); final RoaringBitmap rb = new RoaringBitmap(); final RoaringBitmap rb1 = RoaringBitmap.flip(rb, 100000, 132000); final RoaringBitmap rb2 = RoaringBitmap.flip(rb1, 99000, 2 * 65536); final int rbcard = rb2.getCardinality(); Assert.assertEquals(1928, rbcard);// w ww .j a va 2 s . c o m final BitSet bs = new BitSet(); for (int i = 99000; i < 100000; ++i) bs.set(i); for (int i = 2 * 65536; i < 132000; ++i) bs.set(i); Assert.assertTrue(equals(bs, rb2)); }