List of usage examples for java.lang Integer numberOfLeadingZeros
@HotSpotIntrinsicCandidate public static int numberOfLeadingZeros(int i)
From source file:haven.Utils.java
public static float hfdec(short bits) { int b = ((int) bits) & 0xffff; int e = (b & 0x7c00) >> 10; int m = b & 0x03ff; int ee;//from w w w. j a va 2s . c o m if (e == 0) { if (m == 0) { ee = 0; } else { int n = Integer.numberOfLeadingZeros(m) - 22; ee = (-15 - n) + 127; m = (m << (n + 1)) & 0x03ff; } } else if (e == 0x1f) { ee = 0xff; } else { ee = e - 15 + 127; } int f32 = ((b & 0x8000) << 16) | (ee << 23) | (m << 13); return (Float.intBitsToFloat(f32)); }
From source file:org.apache.hadoop.hive.llap.cache.LowLevelLrfuCachePolicy.java
public String debugDumpHeap() { StringBuilder result = new StringBuilder("List: "); dumpList(result, listHead, listTail); result.append("\nHeap:"); if (heapSize == 0) { result.append(" <empty>\n"); return result.toString(); }// w w w . j a v a 2 s. c om result.append("\n"); int levels = 32 - Integer.numberOfLeadingZeros(heapSize); int ix = 0; int spacesCount = heap[0].toStringForCache().length() + 3; String full = StringUtils.repeat(" ", spacesCount), half = StringUtils.repeat(" ", spacesCount / 2); int maxWidth = 1 << (levels - 1); for (int i = 0; i < levels; ++i) { int width = 1 << i; int middleGap = (maxWidth - width) / width; for (int j = 0; j < (middleGap >>> 1); ++j) { result.append(full); } if ((middleGap & 1) == 1) { result.append(half); } for (int j = 0; j < width && ix < heapSize; ++j, ++ix) { if (j != 0) { for (int k = 0; k < middleGap; ++k) { result.append(full); } if (middleGap == 0) { result.append(" "); } } if ((j & 1) == 0) { result.append("("); } result.append(heap[ix].toStringForCache()); if ((j & 1) == 1) { result.append(")"); } } result.append("\n"); } return result.toString(); }
From source file:com.datatorrent.apps.logstream.DimensionOperator.java
/** * <b>Note:</b> This partitioner does not support parallel partitioning.<br/><br/> * {@inheritDoc}// w w w .ja v a 2 s.co m */ @Override public Collection<Partition<DimensionOperator>> definePartitions( Collection<Partition<DimensionOperator>> partitions, PartitioningContext context) { ArrayList<Partition<DimensionOperator>> newPartitions = new ArrayList<Partition<DimensionOperator>>(); String[] filters = registry.list(LogstreamUtil.FILTER); int partitionSize; if (partitions.size() == 1) { // initial partitions; functional partitioning partitionSize = filters.length; } else { // redo partitions; double the partitions partitionSize = partitions.size() * 2; } for (int i = 0; i < partitionSize; i++) { try { DimensionOperator dimensionOperator = new DimensionOperator(); dimensionOperator.registry = registry; dimensionOperator.timeBucketFlags = timeBucketFlags; dimensionOperator.valueOperations = new HashMap<Integer, HashMap<String, HashSet<AggregateOperation>>>( valueOperations); dimensionOperator.dimensionCombinationList = new HashMap<Integer, ArrayList<Integer>>( dimensionCombinationList); Partition<DimensionOperator> partition = new DefaultPartition<DimensionOperator>(dimensionOperator); newPartitions.add(partition); } catch (Throwable ex) { DTThrowable.rethrow(ex); } } int partitionBits = (Integer.numberOfLeadingZeros(0) - Integer.numberOfLeadingZeros(partitionSize / filters.length - 1)); int partitionMask = 0; if (partitionBits > 0) { partitionMask = -1 >>> (Integer.numberOfLeadingZeros(-1)) - partitionBits; } partitionMask = (partitionMask << 16) | 0xffff; // right most 16 bits used for functional partitioning for (int i = 0; i < newPartitions.size(); i++) { Partition<DimensionOperator> partition = newPartitions.get(i); String partitionVal = filters[i % filters.length]; int bits = i / filters.length; int filterId = registry.getIndex(LogstreamUtil.FILTER, partitionVal); filterId = 0xffff & filterId; // clear out first 16 bits int partitionKey = (bits << 16) | filterId; // first 16 bits for dynamic partitioning, last 16 bits for functional partitioning logger.debug("partitionKey = {} partitionMask = {}", Integer.toBinaryString(partitionKey), Integer.toBinaryString(partitionMask)); partition.getPartitionKeys().put(in, new PartitionKeys(partitionMask, Sets.newHashSet(partitionKey))); } return newPartitions; }
From source file:org.apache.solr.handler.admin.LukeRequestHandler.java
public static SimpleOrderedMap<Object> getIndexInfo(IndexReader reader, int numTerms, Map<String, TopTermQueue> topTerms, Set<String> fields) throws IOException { Directory dir = reader.directory();/*from www.j ava2 s. c o m*/ SimpleOrderedMap<Object> indexInfo = new SimpleOrderedMap<Object>(); indexInfo.add("numDocs", reader.numDocs()); indexInfo.add("maxDoc", reader.maxDoc()); if (numTerms > 0) { TermEnum terms = null; try { terms = reader.terms(); int totalUniqueTerms = 0; String lastField = ""; int[] buckets = new int[HIST_ARRAY_SIZE]; TopTermQueue tiq = null; String field = ""; while (terms.next()) { totalUniqueTerms++; field = terms.term().field(); if (!field.equals(lastField)) { // We're switching fields, wrap up the one we've just accumulated // stats for and get ready for the next one. if (tiq != null) { // Histogram from last time through is the one to use tiq.histogram.add(buckets); topTerms.put(lastField, tiq); tiq = null; } lastField = field; // Skip fields not in fl list (if specified) if (fields != null && !fields.contains(field) && !fields.contains("*")) { continue; } tiq = new TopTermQueue(numTerms + 1); for (int idx = 0; idx < buckets.length; ++idx) { buckets[idx] = 0; } } // When we're on a field we don't care about, tiq is null if (tiq == null) { continue; } int freq = terms.docFreq(); int slot = 32 - Integer.numberOfLeadingZeros(Math.max(0, freq - 1)); buckets[slot] = buckets[slot] + 1; // Compute distinct terms for every field tiq.distinctTerms++; if (terms.docFreq() > tiq.minFreq) { tiq.add(new TopTermQueue.TermInfo(terms.term(), terms.docFreq())); if (tiq.size() > numTerms) { // if tiq full tiq.pop(); // remove lowest in tiq tiq.minFreq = ((TopTermQueue.TermInfo) tiq.top()).docFreq; // reset minFreq } } } // We fall off the end and have to add the last field! if (tiq != null) { tiq.histogram.add(buckets); topTerms.put(field, tiq); } indexInfo.add("numTerms", totalUniqueTerms); } finally { if (terms != null) terms.close(); } } indexInfo.add("version", reader.getVersion()); // TODO? Is this different then: IndexReader.getCurrentVersion( dir )? indexInfo.add("segmentCount", reader.getSequentialSubReaders().length); indexInfo.add("current", reader.isCurrent()); indexInfo.add("hasDeletions", reader.hasDeletions()); indexInfo.add("directory", dir); indexInfo.add("lastModified", new Date(IndexReader.lastModified(dir))); return indexInfo; }
From source file:org.mathIT.gui.GraphViewer.java
/** * /* w ww . j a va 2 s . c o m*/ * @param args command line input (is ignored in this method) */ public static void main(String[] args) { //double inf = WeightedGraph.INFINITY; boolean binary = false; // whether vertex number should be shown in binary format boolean undirected = true; //int s; /* Haus-vom-Nikolaus example: --- undirected = false; double[][] w = { //1 2 3 4 5 { 0, 1, 1, 0, 0}, // 1 { 0, 0, 1, 1, 0}, // 2 { 0, 0, 0, 1, 0}, // 3 { 1, 0, 0, 0, 1}, // 4 { 0, 1, 0, 0, 0}, // 5 }; // */ /* Easley-Kleinberg example: --- undirected = true; double[][] w = { //0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 0 { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 1 { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 2 { 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, // 3 { 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0}, // 4 { 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0}, // 5 { 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0}, // 6 { 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0}, // 7 { 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0}, // 8 { 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}, // 9 { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0}, // 10 { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0}, // 11 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1}, // 12 { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1}, // 13 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0}, // 14 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1}, // 15 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0}, // 16 }; // */ /* Permutation matrix: --- undirected = false; double[][] w = { //0 1 2 3 4 { 0, 0, 1, 0, 0}, // 0 { 0, 1, 0, 0, 0}, // 1 { 0, 0, 0, 0, 1}, // 2 { 1, 0, 0, 0, 0}, // 3 { 0, 0, 0, 1, 0}, // 4 }; // */ /* Permutation matrix 2: --- undirected = false; double[][] w = { //0 1 2 3 4 { 0, 1, 0, 0, 0}, // 0 { 0, 0, 1, 0, 0}, // 1 { 0, 0, 0, 1, 0}, // 2 { 0, 0, 0, 0, 1}, // 3 { 1, 0, 0, 0, 0}, // 4 }; // */ // /* Morone-Makse (2015), Fig. 1.A: --- undirected = true; double[][] w = { //0 1 2 3 4 5 { 0, 1, 0, 0, 0, 0 }, // 0 { 1, 0, 1, 0, 1, 0 }, // 1 { 0, 1, 0, 1, 1, 0 }, // 2 { 0, 0, 1, 0, 0, 0 }, // 3 { 0, 1, 1, 0, 0, 1 }, // 4 { 0, 0, 0, 0, 1, 0 }, // 5 }; // */ /* 3 cycles: --- undirected = false; double[][] w = { //1 2 3 4 5 6 7 8 9 10 11 12 { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 1 { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 2 { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, // 3 { 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0}, // 4 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // 5 { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, // 6 { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0}, // 7 { 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, // 8 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}, // 9 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, // 10 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, // 11 { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0}, // 12 }; // */ /* shear mapping: --- undirected = false; double[][] w = { //1 2 { 1, 1}, // 1 { 0, 1}, // 2 }; // */ /* Adder gate: --- undirected = false; double[][] w = { //1 2 3 4 5 6 7 8 { 1, 0, 0, 0, 0, 0, 0, 0}, // 1 { 0, 1, 0, 0, 0, 0, 0, 0}, // 2 { 0, 0, 1, 0, 0, 0, 0, 0}, // 3 { 0, 0, 0, 1, 0, 0, 0, 0}, // 4 { 0, 0, 0, 0, 0, 0, 1, 0}, // 5 { 0, 0, 0, 0, 0, 0, 0, 1}, // 6 { 0, 0, 0, 0, 0, 1, 0, 0}, // 7 { 0, 0, 0, 0, 1, 0, 0, 0}, // 8 }; binary = true; // */ /* 2-bit adder gate: --- undirected = false; double[][] w = { //1 2 3 4 { 1, 0, 0, 0}, // 1 { 0, 1, 0, 0}, // 2 { 0, 1, 0, 0}, // 3 { 0, 0, 1, 0}, // 4 }; binary = true; // */ /* Easley-Kleinberg toy web: --- undirected = false; double[][] w = { //1 2 3 4 { 0, 1, 0, 1}, // 1 { 0, 0, 1, 1}, // 2 { 1, 0, 0, 0}, // 3 { 0, 0, 1, 0}, // 4 }; // */ /* Easley-Kleinberg toy web variation: --- undirected = false; double[][] w = { //1 2 3 4 { 0, 1, 0, 1}, // 1 { 0, 0, 1, 1}, // 2 { 1, 0, 0, 0}, // 3 { 0, 0, 0, 0}, // 4 }; // */ /* Krumke-Noltemeier 3.4: --- undirected = false; double[][] w = { //1 2 3 4 5 6 7 { 0, 1, 0, 0, 0, 0, 0}, // 1 { 0, 0, 1, 1, 0, 0, 0}, // 2 { 0, 0, 0, 0, 0, 0, 0}, // 3 { 0, 0, 0, 0, 1, 0, 0}, // 4 { 0, 1, 0, 1, 0, 0, 0}, // 5 { 0, 0, 0, 0, 0, 0, 0}, // 6 { 0, 0, 0, 0, 0, 1, 0}, // 7 }; // */ /* OR gate: --- double[][] w = { //1 2 3 4 5 6 7 8 { 0, 1, 0, 0, 0, 0, 0, 0}, // 1 { 1, 0, 0, 0, 0, 0, 0, 0}, // 2 { 0, 0, 1, 0, 0, 0, 0, 0}, // 3 { 0, 0, 0, 1, 0, 0, 0, 0}, // 4 { 0, 0, 0, 0, 1, 0, 0, 0}, // 5 { 0, 0, 0, 0, 0, 1, 0, 0}, // 6 { 0, 0, 0, 0, 0, 0, 1, 0}, // 7 { 0, 0, 0, 0, 0, 0, 0, 1}, // 8 }; binary = true; // */ /* cOR gate: --- undirected = false; double[][] w = { //1 2 3 4 5 6 7 8 { 0, 1, 0, 0, 0, 0, 0, 0}, // 1 { 0, 0, 0, 0, 0, 0, 1, 0}, // 2 { 0, 0, 0, 0, 1, 0, 0, 0}, // 3 { 0, 0, 0, 1, 0, 0, 0, 0}, // 4 { 0, 0, 1, 0, 0, 0, 0, 0}, // 5 { 0, 0, 0, 0, 0, 1, 0, 0}, // 6 { 1, 0, 0, 0, 0, 0, 0, 0}, // 7 { 0, 0, 0, 0, 0, 0, 0, 1}, // 8 }; binary = true; // */ /* Brandes et al 2008, Fig. 1a: --- double[][] w = { //1 2 3 4 5 6 { 0, 1, 1, 0, 0, 0}, // 1 { 1, 0, 1, 0, 1, 0}, // 2 { 1, 1, 0, 1, 0, 0}, // 3 { 0, 0, 1, 0, 0, 0}, // 4 { 0, 1, 0, 0, 0, 1}, // 5 { 0, 0, 0, 0, 1, 0}, // 6 }; // maximum modularity: C_0=[{0, 1, 2}, {3}, {4}, {5}], Q=0.013888888888888895 // */ Actor[] x = new Actor[w.length]; for (int i = 0; i < x.length; i++) { String name = ""; if (binary) { int jMax = Integer.numberOfLeadingZeros(i) - Integer.numberOfLeadingZeros(x.length) - 1; //System.out.println("i=" + i + ", jMax=" + jMax); for (int j = 0; j < jMax; j++) { name += "0"; } if (i != 0) name += Integer.toBinaryString(i); } else { //name += i; name += (i + 1); } //if (!binary && i < 10) name = " " + name; x[i] = new Actor(i, name, .5); } SocialNetwork graph = new SocialNetwork(undirected, x, w); //graph.activate(x[6], x[9]); visualize(graph); //new GraphViewer(graph); }
From source file:org.apache.hadoop.hive.llap.cache.BuddyAllocator.java
private int freeListFromAllocSize(int allocSize) { return (31 - Integer.numberOfLeadingZeros(allocSize)) - minAllocLog2; }
From source file:org.apache.hadoop.hive.llap.cache.BuddyAllocator.java
private int determineFreeListForAllocation(int size) { int freeListIx = 31 - Integer.numberOfLeadingZeros(size); if (size != (1 << freeListIx)) ++freeListIx; // not a power of two, add one more return Math.max(freeListIx - minAllocLog2, 0); }
From source file:org.neo4j.io.pagecache.PageCacheTest.java
private int nextPowerOf2(int i) { return 1 << (32 - Integer.numberOfLeadingZeros(i)); }