Class ByteBufferHashTable
- java.lang.Object
-
- org.apache.druid.query.groupby.epinephelinae.ByteBufferHashTable
-
public class ByteBufferHashTable extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ByteBufferHashTable.BucketUpdateHandler
-
Field Summary
Fields Modifier and Type Field Description protected int
bucketSizeWithHash
protected ByteBufferHashTable.BucketUpdateHandler
bucketUpdateHandler
protected ByteBuffer
buffer
protected int
growthCount
protected static int
HASH_SIZE
protected int
initialBuckets
protected int
keySize
protected int
maxBuckets
protected float
maxLoadFactor
protected int
maxSizeForTesting
protected int
regrowthThreshold
protected int
size
protected int
tableArenaSize
protected ByteBuffer
tableBuffer
protected int
tableStart
-
Constructor Summary
Constructors Constructor Description ByteBufferHashTable(float maxLoadFactor, int initialBuckets, int bucketSizeWithHash, ByteBuffer buffer, int keySize, int maxSizeForTesting, ByteBufferHashTable.BucketUpdateHandler bucketUpdateHandler)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
adjustTableWhenFull()
static int
calculateTableArenaSizeWithFixedAdditionalSize(int bufferCapacity, int bucketSize, int fixedAdditionalSize)
static int
calculateTableArenaSizeWithPerBucketAdditionalSize(int bufferCapacity, int bucketSize, int perBucketAdditionalSize)
protected boolean
canAllowNewBucket()
protected int
findBucket(boolean allowNewBucket, int buckets, ByteBuffer targetTableBuffer, ByteBuffer keyBuffer, int keyHash)
Finds the bucket into which we should insert a key.protected int
findBucketWithAutoGrowth(ByteBuffer keyBuffer, int keyHash, Runnable preTableGrowthRunnable)
Find a bucket for a key, attempting to grow the table with adjustTableWhenFull() if possible.int
getGrowthCount()
int
getMaxBuckets()
protected int
getOffsetForBucket(int bucket)
int
getRegrowthThreshold()
int
getSize()
ByteBuffer
getTableBuffer()
protected void
initializeNewBucketKey(int bucket, ByteBuffer keyBuffer, int keyHash)
protected boolean
isBucketUsed(int bucket)
protected boolean
isOffsetUsed(int bucketOffset)
protected int
maxSizeForBuckets(int buckets)
void
reset()
-
-
-
Field Detail
-
maxSizeForTesting
protected final int maxSizeForTesting
-
HASH_SIZE
protected static final int HASH_SIZE
- See Also:
- Constant Field Values
-
maxLoadFactor
protected final float maxLoadFactor
-
initialBuckets
protected final int initialBuckets
-
buffer
protected final ByteBuffer buffer
-
bucketSizeWithHash
protected final int bucketSizeWithHash
-
tableArenaSize
protected final int tableArenaSize
-
keySize
protected final int keySize
-
tableStart
protected int tableStart
-
tableBuffer
protected ByteBuffer tableBuffer
-
size
protected int size
-
regrowthThreshold
protected int regrowthThreshold
-
maxBuckets
protected int maxBuckets
-
growthCount
protected int growthCount
-
bucketUpdateHandler
@Nullable protected ByteBufferHashTable.BucketUpdateHandler bucketUpdateHandler
-
-
Constructor Detail
-
ByteBufferHashTable
public ByteBufferHashTable(float maxLoadFactor, int initialBuckets, int bucketSizeWithHash, ByteBuffer buffer, int keySize, int maxSizeForTesting, @Nullable ByteBufferHashTable.BucketUpdateHandler bucketUpdateHandler)
-
-
Method Detail
-
calculateTableArenaSizeWithPerBucketAdditionalSize
public static int calculateTableArenaSizeWithPerBucketAdditionalSize(int bufferCapacity, int bucketSize, int perBucketAdditionalSize)
-
calculateTableArenaSizeWithFixedAdditionalSize
public static int calculateTableArenaSizeWithFixedAdditionalSize(int bufferCapacity, int bucketSize, int fixedAdditionalSize)
-
reset
public void reset()
-
adjustTableWhenFull
public void adjustTableWhenFull()
-
initializeNewBucketKey
protected void initializeNewBucketKey(int bucket, ByteBuffer keyBuffer, int keyHash)
-
findBucketWithAutoGrowth
protected int findBucketWithAutoGrowth(ByteBuffer keyBuffer, int keyHash, Runnable preTableGrowthRunnable)
Find a bucket for a key, attempting to grow the table with adjustTableWhenFull() if possible.- Parameters:
keyBuffer
- buffer containing the keykeyHash
- hash of the keypreTableGrowthRunnable
- runnable that executes before the table grows- Returns:
- bucket number of the found bucket or -1 if a bucket could not be allocated after resizing.
-
findBucket
protected int findBucket(boolean allowNewBucket, int buckets, ByteBuffer targetTableBuffer, ByteBuffer keyBuffer, int keyHash)
Finds the bucket into which we should insert a key.- Parameters:
keyBuffer
- key, must have exactly keySize bytes remaining. Will not be modified.targetTableBuffer
- Need selectable buffer, since when resizing hash table, findBucket() is used on the newly allocated table buffer- Returns:
- bucket index for this key, or -1 if no bucket is available due to being full
-
canAllowNewBucket
protected boolean canAllowNewBucket()
-
getOffsetForBucket
protected int getOffsetForBucket(int bucket)
-
maxSizeForBuckets
protected int maxSizeForBuckets(int buckets)
-
isBucketUsed
protected boolean isBucketUsed(int bucket)
-
isOffsetUsed
protected boolean isOffsetUsed(int bucketOffset)
-
getTableBuffer
public ByteBuffer getTableBuffer()
-
getSize
public int getSize()
-
getRegrowthThreshold
public int getRegrowthThreshold()
-
getMaxBuckets
public int getMaxBuckets()
-
getGrowthCount
public int getGrowthCount()
-
-