List of usage examples for java.util BitSet BitSet
private BitSet(long[] words)
From source file:stats.MessageLengthFactorialComputer.java
public MessageLengthFactorialComputer(int nbInstances, Lattice lattice) { this.lookup = new HashMap<BitSet, Double>(); this.lattice = lattice; this.nbInstances = nbInstances; int nbFactorials = this.nbInstances + 2; int nbVariables = lattice.getNbVariables(); int nbMaxEdges = nbVariables * (nbVariables - 1) / 2; if (nbMaxEdges + 2 > nbFactorials) { nbFactorials = nbMaxEdges + 3;/*from w ww.j a v a2s . c o m*/ } this.logs = new double[nbFactorials]; for (int i = 0; i < logs.length; i++) { logs[i] = FastMath.log(i); } lnN = logs[nbInstances]; this.logFactorials = new double[nbFactorials]; logFactorials[0] = logs[1]; logFactorials[1] = logs[1]; for (int i = 2; i < logFactorials.length; i++) { logFactorials[i] = logFactorials[i - 1] + logs[i]; } nbCellsEverParsed = 0; lookup.put(new BitSet(lattice.getNbVariables()), 0.0); }
From source file:org.rifidi.edge.adapter.alien.AlienGPIOService.java
@Override public void flashGPO(String readerID, int flashTime, Set<Integer> ports) throws CannotExecuteException { Alien9800ReaderSession session = getSession(readerID); BitSet bits = new BitSet(8); for (Integer port : ports) { bits.set(port);/*from w w w . ja va2s . com*/ } logger.info("Flashing GPO on " + readerID + " Ports: " + ports + " for " + flashTime + " seconds"); session.flashOutput(bits, new BitSet(), flashTime, 0, 1); }
From source file:org.apache.hadoop.mapred.ShuffleExceptionTracker.java
/** * Constructor/*from ww w. ja v a 2 s .c om*/ * * @param numberRequests * the tailing number of requests to track * @param exceptionStackRegex * the exception stack regular expression to look for * @param exceptionMsgRegex * the exception message regular expression to look for * @param shuffleExceptionLimit * the exception limit (0-1.0) representing a percent. 0 disables the * abort check. */ ShuffleExceptionTracker(int numberRequests, String exceptionStackRegex, String exceptionMsgRegex, float shuffleExceptionLimit) { this.exceptionStackRegex = exceptionStackRegex; this.exceptionMsgRegex = exceptionMsgRegex; this.shuffleExceptionLimit = shuffleExceptionLimit; this.size = numberRequests; this.index = 0; this.requests = new BitSet(size); }
From source file:com.eclecticlogic.pedal.TestPedalDialect.java
@Test @Transactional//from w w w. j av a 2s . com public void insertTestForCustomTypes() { ExoticTypes et = new ExoticTypes(); et.setLogin("inserter"); BitSet bs = new BitSet(7); bs.set(1); bs.set(3); bs.set(4); et.setCountries(bs); et.setAuthorizations(Sets.newHashSet("a", "b", "b", "c")); et.setScores(Lists.newArrayList(1L, 2L, 3L)); et.setGpa(Lists.<Long>newArrayList()); et.setStatus(Status.ACTIVE); et.setCustom("abc"); entityManager.persist(et); entityManager.flush(); ExoticTypes loaded = entityManager.find(ExoticTypes.class, "inserter"); Assert.assertNotNull(loaded); Assert.assertEquals(loaded.getLogin(), "inserter"); Assert.assertEquals(loaded.getAuthorizations(), Sets.newHashSet("b", "a", "c")); Assert.assertEquals(loaded.getCountries().toString(), "{1, 3, 4}"); Assert.assertEquals(loaded.getGpa(), Lists.newArrayList()); Assert.assertEquals(loaded.getScores(), Lists.newArrayList(1L, 2L, 3L)); Assert.assertEquals(loaded.getStatus(), Status.ACTIVE); }
From source file:inflor.core.singlets.SingletsModel.java
public BitSet scoreModel(double[] ratio) { final BitSet mask = new BitSet(ratio.length); for (int i = 0; i < mask.size(); i++) { if (ratio[i] <= ratioThreshold) { mask.set(i);/*from www .j av a 2s.com*/ } } return mask; }
From source file:com.turn.griffin.data.GriffinUploadTask.java
private BitSet getAvailableBitmap(FileInfo fileInfo) { String filename = fileInfo.getFilename(); long fileVersion = fileInfo.getVersion(); long blockCount = fileInfo.getBlockCount(); Optional<GriffinConsumer> consumer = Optional.absent(); BitSet availableBlockBitmap = new BitSet((int) blockCount); try {//ww w . jav a 2 s . co m BlockingQueue<byte[]> dataQueue = new ArrayBlockingQueue<>( GriffinDownloadTask.DOWNLOAD_CONSUMER_QUEUE_SIZE); Properties properties = new Properties(); properties.put("auto.offset.reset", "smallest"); /* The groupId should be unique to avoid conflict with other consumers running on this machine */ String consumerGroupId = GriffinKafkaTopicNameUtil.getDataTopicConsumerGroupId(filename, fileVersion, new String[] { dataManager.getMyServerId(), this.getClass().getSimpleName(), UUID.randomUUID().toString() }); String dataTopicNameForConsumer = GriffinKafkaTopicNameUtil.getDataTopicNameForConsumer(filename, fileVersion); consumer = Optional.fromNullable(new GriffinConsumer(GriffinModule.ZOOKEEPER, consumerGroupId, dataTopicNameForConsumer, GriffinDownloadTask.DOWNLOAD_THREAD_COUNT, properties, dataQueue)); /* TODO: Change this to a better bitmap (Check out RoaringBitmap) */ while (availableBlockBitmap.nextClearBit(0) != blockCount) { Optional<byte[]> message = Optional.fromNullable(dataQueue .poll(GriffinLeaderSelectionTask.LEADER_SELECTION_PERIOD_MS, TimeUnit.MILLISECONDS)); if (!message.isPresent()) { /* We know how much of the file is available in Kafka */ break; } DataMessage dataMessage = DataMessage.parseFrom(message.get()); availableBlockBitmap.set((int) dataMessage.getBlockSeqNo()); } } catch (Exception e) { logger.warn(String.format("Unable to download file %s to get available bitmap ", filename), e); /* Work with whatever information we have gathered till now */ } finally { if (consumer.isPresent()) { consumer.get().shutdown(true); } } return availableBlockBitmap; }
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 w w w . jav a 2 s .c om*/ } return bitSet; }
From source file:org.apache.hadoop.mapred.TestSequenceFileAsTextInputFormat.java
public void testFormat() throws Exception { JobConf job = new JobConf(conf); FileSystem fs = FileSystem.getLocal(conf); Path dir = new Path(System.getProperty("test.build.data", ".") + "/mapred"); Path file = new Path(dir, "test.seq"); Reporter reporter = Reporter.NULL;/* w w w .j av a 2 s.c o m*/ int seed = new Random().nextInt(); //LOG.info("seed = "+seed); Random random = new Random(seed); fs.delete(dir, true); FileInputFormat.setInputPaths(job, dir); // for a variety of lengths for (int length = 0; length < MAX_LENGTH; length += random.nextInt(MAX_LENGTH / 10) + 1) { //LOG.info("creating; entries = " + length); // create a file with length entries SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, file, IntWritable.class, LongWritable.class); try { for (int i = 0; i < length; i++) { IntWritable key = new IntWritable(i); LongWritable value = new LongWritable(10 * i); writer.append(key, value); } } finally { writer.close(); } // try splitting the file in a variety of sizes InputFormat<Text, Text> format = new SequenceFileAsTextInputFormat(); for (int i = 0; i < 3; i++) { int numSplits = random.nextInt(MAX_LENGTH / (SequenceFile.SYNC_INTERVAL / 20)) + 1; //LOG.info("splitting: requesting = " + numSplits); InputSplit[] splits = format.getSplits(job, numSplits); //LOG.info("splitting: got = " + splits.length); // check each split BitSet bits = new BitSet(length); for (int j = 0; j < splits.length; j++) { RecordReader<Text, Text> reader = format.getRecordReader(splits[j], job, reporter); Class readerClass = reader.getClass(); assertEquals("reader class is SequenceFileAsTextRecordReader.", SequenceFileAsTextRecordReader.class, readerClass); Text value = reader.createValue(); Text key = reader.createKey(); try { int count = 0; while (reader.next(key, value)) { // if (bits.get(key.get())) { // LOG.info("splits["+j+"]="+splits[j]+" : " + key.get()); // LOG.info("@"+reader.getPos()); // } int keyInt = Integer.parseInt(key.toString()); assertFalse("Key in multiple partitions.", bits.get(keyInt)); bits.set(keyInt); count++; } //LOG.info("splits["+j+"]="+splits[j]+" count=" + count); } finally { reader.close(); } } assertEquals("Some keys in no partition.", length, bits.cardinality()); } } }
From source file:org.moeaframework.TestUtils.java
/** * Returns {@code true} if the two populations are equal; otherwise * {@code false}. Two populations are equal if all solutions contained * in one population are contained in the other population. * //www .j a v a 2 s. co m * @param p1 the first population * @param p2 the second population * @return {@code true} if the two populations are equal; otherwise * {@code false} */ public static boolean equals(Population p1, Population p2) { if (p1.size() != p2.size()) { return false; } BitSet matched1 = new BitSet(p1.size()); BitSet matched2 = new BitSet(p2.size()); for (int i = 0; i < p1.size(); i++) { for (int j = 0; j < p2.size(); j++) { if (equals(p1.get(i), p2.get(j))) { matched1.set(i); matched2.set(j); } } } return (matched1.cardinality() == p1.size()) && (matched2.cardinality() == p2.size()); }
From source file:org.apache.openjpa.kernel.DetachManager.java
/** * Used to prepare a detachable instance that does not externalize * detached state./*from w w w . java2s.co m*/ */ static boolean preSerialize(StateManagerImpl sm) { if (!sm.isPersistent()) return false; if (sm.getBroker().getConfiguration().getCompatibilityInstance().getFlushBeforeDetach()) { flushDirty(sm); } ClassMetaData meta = sm.getMetaData(); boolean setState = meta.getDetachedState() != null && !ClassMetaData.SYNTHETIC.equals(meta.getDetachedState()); BitSet idxs = (setState) ? new BitSet(meta.getFields().length) : null; preDetach(sm.getBroker(), sm, idxs, false, true); if (setState) { sm.getPersistenceCapable().pcSetDetachedState(getDetachedState(sm, idxs)); return false; // don't null state } return true; }