public class BufferGrouper<KeyType> extends Object implements Grouper<KeyType>
iterator(boolean)
. This sorting is done in-place to avoid materializing the full array of pointers. The
first "size" pointers in the array of pointers are valid; everything else is potentially junk.
The table is periodically grown to accommodate more keys. Even though starting small is not necessary to control
memory use (we already have the entire buffer allocated) or iteration speed (iteration is fast due to the array
of pointers) it still helps significantly on initialization times. Otherwise, we'd need to clear the used bits of
each bucket in the entire buffer, which is a lot of writes if the buckets are small.Grouper.Entry<T>, Grouper.KeyComparator, Grouper.KeySerde<T>, Grouper.KeySerdeFactory<T>
Constructor and Description |
---|
BufferGrouper(com.google.common.base.Supplier<ByteBuffer> bufferSupplier,
Grouper.KeySerde<KeyType> keySerde,
ColumnSelectorFactory columnSelectorFactory,
AggregatorFactory[] aggregatorFactories,
int bufferGrouperMaxSize,
float maxLoadFactor,
int initialBuckets) |
Modifier and Type | Method and Description |
---|---|
boolean |
aggregate(KeyType key)
Aggregate the current row with the provided key.
|
boolean |
aggregate(KeyType key,
int keyHash)
Aggregate the current row with the provided key.
|
void |
close()
Close the grouper and release associated resources.
|
void |
init()
Initialize the grouper.
|
boolean |
isInitialized()
Check this grouper is initialized or not.
|
Iterator<Grouper.Entry<KeyType>> |
iterator(boolean sorted)
Iterate through entries.
|
void |
reset()
Reset the grouper to its initial state.
|
public BufferGrouper(com.google.common.base.Supplier<ByteBuffer> bufferSupplier, Grouper.KeySerde<KeyType> keySerde, ColumnSelectorFactory columnSelectorFactory, AggregatorFactory[] aggregatorFactories, int bufferGrouperMaxSize, float maxLoadFactor, int initialBuckets)
public void init()
Grouper
Grouper.aggregate(Object)
and Grouper.aggregate(Object, int)
.public boolean isInitialized()
Grouper
isInitialized
in interface Grouper<KeyType>
public boolean aggregate(KeyType key, int keyHash)
Grouper
aggregate
in interface Grouper<KeyType>
key
- key objectkeyHash
- result of Groupers.hash(Object)
on the keypublic boolean aggregate(KeyType key)
Grouper
public void reset()
Grouper
public Iterator<Grouper.Entry<KeyType>> iterator(boolean sorted)
Grouper
Once this method is called, writes are no longer safe. After you are done with the iterator returned by this
method, you should either call Grouper.close()
(if you are done with the Grouper), Grouper.reset()
(if you
want to reuse it), or Grouper.iterator(boolean)
again if you want another iterator.
If "sorted" is true then the iterator will return sorted results. It will use KeyType's natural ordering on
deserialized objects, and will use the KeySerde#comparator()
on serialized objects. Woe be unto you
if these comparators are not equivalent.
Copyright © 2011–2017. All rights reserved.