private static int computeBlockSizeBitsFor(long bytes) { long powerOfTwo = BitUtil.nextHighestPowerOfTwo(bytes / MAX_BLOCKS_BEFORE_BLOCK_EXPANSION); if (powerOfTwo == 0) { return DEFAULT_MIN_BITS_PER_BLOCK; } int blockBits = Long.numberOfTrailingZeros(powerOfTwo); blockBits = Math.min(blockBits, DEFAULT_MAX_BITS_PER_BLOCK); blockBits = Math.max(blockBits, DEFAULT_MIN_BITS_PER_BLOCK); return blockBits; }
/** * * @param size The minimum number of elements this set should be able to hold without rehashing * (i.e. the slots are guaranteed not to change) * @param emptyVal The integer value to use for EMPTY */ public SentinelIntSet(int size, int emptyVal) { this.emptyVal = emptyVal; int tsize = Math.max(org.apache.lucene.util.BitUtil.nextHighestPowerOfTwo(size), 1); rehashCount = tsize - (tsize>>2); if (size >= rehashCount) { // should be able to hold "size" w/o re-hashing tsize <<= 1; rehashCount = tsize - (tsize>>2); } keys = new int[tsize]; if (emptyVal != 0) clear(); }
private static int computeBlockSizeBitsFor(long bytes) { long powerOfTwo = BitUtil.nextHighestPowerOfTwo(bytes / MAX_BLOCKS_BEFORE_BLOCK_EXPANSION); if (powerOfTwo == 0) { return DEFAULT_MIN_BITS_PER_BLOCK; } int blockBits = Long.numberOfTrailingZeros(powerOfTwo); blockBits = Math.min(blockBits, DEFAULT_MAX_BITS_PER_BLOCK); blockBits = Math.max(blockBits, DEFAULT_MIN_BITS_PER_BLOCK); return blockBits; }
/** Create a HashDocSet from a list of *unique* ids */ public HashDocSet(int[] docs, int offset, int len, float inverseLoadFactor) { int tsize = Math.max(BitUtil.nextHighestPowerOfTwo(len), 1); if (tsize < len * inverseLoadFactor) { tsize <<= 1; } mask=tsize-1; table = new int[tsize]; // (for now) better then: Arrays.fill(table, EMPTY); // https://issues.apache.org/jira/browse/SOLR-390 for (int i=tsize-1; i>=0; i--) table[i]=EMPTY; int end = offset + len; for (int i=offset; i<end; i++) { put(docs[i]); } size = len; }
/** * * @param size The minimum number of elements this set should be able to hold without rehashing * (i.e. the slots are guaranteed not to change) * @param emptyVal The integer value to use for EMPTY */ public SentinelIntSet(int size, int emptyVal) { this.emptyVal = emptyVal; int tsize = Math.max(org.apache.lucene.util.BitUtil.nextHighestPowerOfTwo(size), 1); rehashCount = tsize - (tsize>>2); if (size >= rehashCount) { // should be able to hold "size" w/o re-hashing tsize <<= 1; rehashCount = tsize - (tsize>>2); } keys = new int[tsize]; if (emptyVal != 0) clear(); }
/** * * @param size The minimum number of elements this set should be able to hold without rehashing * (i.e. the slots are guaranteed not to change) * @param emptyVal The integer value to use for EMPTY */ public SentinelIntSet(int size, int emptyVal) { this.emptyVal = emptyVal; int tsize = Math.max(org.apache.lucene.util.BitUtil.nextHighestPowerOfTwo(size), 1); rehashCount = tsize - (tsize>>2); if (size >= rehashCount) { // should be able to hold "size" w/o re-hashing tsize <<= 1; rehashCount = tsize - (tsize>>2); } keys = new int[tsize]; if (emptyVal != 0) clear(); }
/** * * @param size The minimum number of elements this set should be able to hold without rehashing * (i.e. the slots are guaranteed not to change) * @param emptyVal The integer value to use for EMPTY */ public SentinelIntSet(int size, int emptyVal) { this.emptyVal = emptyVal; int tsize = Math.max(org.apache.lucene.util.BitUtil.nextHighestPowerOfTwo(size), 1); rehashCount = tsize - (tsize>>2); if (size >= rehashCount) { // should be able to hold "size" w/o re-hashing tsize <<= 1; rehashCount = tsize - (tsize>>2); } keys = new int[tsize]; if (emptyVal != 0) clear(); }