Package org.roaringbitmap
Class ConstantMemoryContainerAppender<T extends BitmapDataProvider & AppendableStorage<Container>>
- java.lang.Object
-
- org.roaringbitmap.ConstantMemoryContainerAppender<T>
-
- All Implemented Interfaces:
java.util.function.Supplier<T>
,RoaringBitmapWriter<T>
public class ConstantMemoryContainerAppender<T extends BitmapDataProvider & AppendableStorage<Container>> extends java.lang.Object implements RoaringBitmapWriter<T>
This class can be used to write quickly values to a bitmap. The values are expected to be (increasing) sorted order. Values are first written to a temporary internal buffer, but the underlying bitmap can forcefully synchronize by calling "flush" (although calling flush to often would defeat the performance purpose of this class). The main use case for an ConstantMemoryContainerAppender is to get bitmaps quickly. You should benchmark your particular use case to see if it helps.//... RoaringBitmapWriter<RoaringBitmap> writer = RoaringBitmapWriter.writer().constantMemory().get(); for (int i :....) { writer.add(i); } writer.flush(); // important
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.roaringbitmap.RoaringBitmapWriter
RoaringBitmapWriter.BufferWizard, RoaringBitmapWriter.FastRankRoaringBitmapWizard, RoaringBitmapWriter.RoaringBitmapWizard, RoaringBitmapWriter.RoaringWizard<T extends RoaringBitmap>, RoaringBitmapWriter.Wizard<C extends WordStorage<C>,T extends BitmapDataProvider & AppendableStorage<C>>
-
-
Field Summary
Fields Modifier and Type Field Description private long[]
bitmap
private int
currentKey
private boolean
dirty
private boolean
doPartialSort
private java.util.function.Supplier<T>
newUnderlying
private boolean
runCompress
private T
underlying
private static int
WORD_COUNT
-
Constructor Summary
Constructors Constructor Description ConstantMemoryContainerAppender(boolean doPartialSort, boolean runCompress, java.util.function.Supplier<T> newUnderlying)
Initialize an ConstantMemoryContainerAppender with a receiving bitmap
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int value)
Adds the value to the underlying bitmap.void
add(long min, long max)
Add a range to the bitmapvoid
addMany(int... values)
Adds many values to the bitmap.private int
appendToUnderlying()
private Container
chooseBestContainer()
void
flush()
Ensures that any buffered additions are flushed to the underlying bitmap.T
getUnderlying()
Grab a reference to the underlying bitmapvoid
reset()
Resets the writer so it can be reused, must release the reference to the underlying bitmap-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.roaringbitmap.RoaringBitmapWriter
get
-
-
-
-
Field Detail
-
doPartialSort
private final boolean doPartialSort
-
runCompress
private final boolean runCompress
-
WORD_COUNT
private static final int WORD_COUNT
- See Also:
- Constant Field Values
-
bitmap
private final long[] bitmap
-
newUnderlying
private final java.util.function.Supplier<T extends BitmapDataProvider & AppendableStorage<Container>> newUnderlying
-
underlying
private T extends BitmapDataProvider & AppendableStorage<Container> underlying
-
dirty
private boolean dirty
-
currentKey
private int currentKey
-
-
Constructor Detail
-
ConstantMemoryContainerAppender
ConstantMemoryContainerAppender(boolean doPartialSort, boolean runCompress, java.util.function.Supplier<T> newUnderlying)
Initialize an ConstantMemoryContainerAppender with a receiving bitmap- Parameters:
doPartialSort
- indicates whether to sort the upper 16 bits of input data in addManyrunCompress
- whether to run compress appended containersnewUnderlying
- supplier of bitmaps where the data gets written
-
-
Method Detail
-
getUnderlying
public T getUnderlying()
Grab a reference to the underlying bitmap- Specified by:
getUnderlying
in interfaceRoaringBitmapWriter<T extends BitmapDataProvider & AppendableStorage<Container>>
- Returns:
- the underlying bitmap
-
add
public void add(int value)
Adds the value to the underlying bitmap. The data might be added to a temporary buffer. You should call "flush" when you are done.- Specified by:
add
in interfaceRoaringBitmapWriter<T extends BitmapDataProvider & AppendableStorage<Container>>
- Parameters:
value
- the value to add.
-
addMany
public void addMany(int... values)
Description copied from interface:RoaringBitmapWriter
Adds many values to the bitmap.- Specified by:
addMany
in interfaceRoaringBitmapWriter<T extends BitmapDataProvider & AppendableStorage<Container>>
- Parameters:
values
- the values to add
-
add
public void add(long min, long max)
Description copied from interface:RoaringBitmapWriter
Add a range to the bitmap- Specified by:
add
in interfaceRoaringBitmapWriter<T extends BitmapDataProvider & AppendableStorage<Container>>
- Parameters:
min
- the inclusive min valuemax
- the exclusive max value
-
flush
public void flush()
Ensures that any buffered additions are flushed to the underlying bitmap.- Specified by:
flush
in interfaceRoaringBitmapWriter<T extends BitmapDataProvider & AppendableStorage<Container>>
-
reset
public void reset()
Description copied from interface:RoaringBitmapWriter
Resets the writer so it can be reused, must release the reference to the underlying bitmap- Specified by:
reset
in interfaceRoaringBitmapWriter<T extends BitmapDataProvider & AppendableStorage<Container>>
-
chooseBestContainer
private Container chooseBestContainer()
-
appendToUnderlying
private int appendToUnderlying()
-
-