public class MemoryOpenHashTable extends Object
WritableMemory. Does not offer a similar
interface to Map because this is meant to be useful to lower-level, high-performance callers.
There is no copying or serde of keys and values: callers access the backing memory of the table directly.
This table will not grow itself. Callers must handle growing if required; the copyTo(org.apache.druid.query.groupby.epinephelinae.collection.MemoryOpenHashTable, org.apache.druid.query.groupby.epinephelinae.collection.MemoryOpenHashTable.BucketCopyHandler) method is provided
to assist.| Modifier and Type | Class and Description |
|---|---|
static interface |
MemoryOpenHashTable.BucketCopyHandler
|
| Constructor and Description |
|---|
MemoryOpenHashTable(org.apache.datasketches.memory.WritableMemory tableMemory,
int numBuckets,
int maxSize,
int keySize,
int valueSize)
Create a new table.
|
| Modifier and Type | Method and Description |
|---|---|
it.unimi.dsi.fastutil.ints.IntIterator |
bucketIterator()
Iterates over all used buckets, returning bucket numbers for each one.
|
int |
bucketKeyOffset()
Returns the offset within each bucket where the key starts.
|
int |
bucketMemoryPosition(int bucket)
Returns the position within
memory() where a particular bucket starts. |
int |
bucketSize()
Returns the size in bytes of each bucket.
|
static int |
bucketSize(int keySize,
int valueSize)
Returns the size of each bucket in a table.
|
int |
bucketValueOffset()
Returns the offset within each bucket where the value starts.
|
boolean |
canInsertNewBucket()
Returns whether this table can accept a new bucket.
|
void |
clear()
Clear the table, resetting size to zero.
|
void |
copyTo(MemoryOpenHashTable other,
MemoryOpenHashTable.BucketCopyHandler copyHandler)
Copy this table into another one.
|
int |
findBucket(int keyHash,
org.apache.datasketches.memory.Memory keySpace,
int keySpacePosition)
Finds the bucket for a particular key.
|
void |
initBucket(int bucket,
org.apache.datasketches.memory.Memory keySpace,
int keySpacePosition)
Initialize a bucket with a particular key.
|
int |
keySize()
Returns the size of keys, in bytes.
|
org.apache.datasketches.memory.WritableMemory |
memory()
Returns the memory backing this table.
|
static int |
memoryNeeded(int numBuckets,
int bucketSize)
Returns the amount of memory needed for a table.
|
int |
numBuckets()
Returns the number of buckets in this table.
|
int |
size()
Returns the number of elements currently in the table.
|
int |
valueSize()
Returns the size of values, in bytes.
|
public MemoryOpenHashTable(org.apache.datasketches.memory.WritableMemory tableMemory,
int numBuckets,
int maxSize,
int keySize,
int valueSize)
tableMemory - backing memory for the table; must be exactly large enough to hold "numBuckets"numBuckets - number of buckets for the tablemaxSize - maximum number of elements for the table; must be less than numBucketskeySize - key size in bytesvalueSize - value size in bytespublic static int memoryNeeded(int numBuckets,
int bucketSize)
numBuckets - number of bucketsbucketSize - size per bucket (in bytes)public static int bucketSize(int keySize,
int valueSize)
keySize - size of keys (in bytes)valueSize - size of values (in bytes)public void clear()
public void copyTo(MemoryOpenHashTable other, @Nullable MemoryOpenHashTable.BucketCopyHandler copyHandler)
other - the other tablecopyHandler - a callback that is notified for each copied bucketpublic int findBucket(int keyHash,
org.apache.datasketches.memory.Memory keySpace,
int keySpacePosition)
keyHash - result of calling HashTableUtils.hashMemory(org.apache.datasketches.memory.Memory, long, int) on this keykeySpace - memory containing the keykeySpacePosition - position of the key within keySpace-bucket - 1 if not occupied (yet)public boolean canInsertNewBucket()
public void initBucket(int bucket,
org.apache.datasketches.memory.Memory keySpace,
int keySpacePosition)
canInsertNewBucket() returns true.bucket - bucket numberkeySpace - memory containing the keykeySpacePosition - position of the key within keySpacepublic int size()
public int numBuckets()
public int keySize()
public int valueSize()
public int bucketKeyOffset()
public int bucketValueOffset()
public int bucketSize()
public int bucketMemoryPosition(int bucket)
memory() where a particular bucket starts.public org.apache.datasketches.memory.WritableMemory memory()
public it.unimi.dsi.fastutil.ints.IntIterator bucketIterator()
bucketMemoryPosition(int) and then use
bucketKeyOffset() and bucketValueOffset() to extract keys and values from the buckets as needed.Copyright © 2011–2020 The Apache Software Foundation. All rights reserved.