Package org.apache.uima.cas.impl
Class Heap
java.lang.Object
org.apache.uima.cas.impl.Heap
A heap for CAS.
This class is agnostic about what you store on the heap. It only copies values from integer arrays.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
private static final boolean
static final int
Default size of the heap.(package private) int[]
private int
private int
static final int
Minimum size of the heap.private static final int
private static final int
private int
private final int[]
private static final int
private static final int
private static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
add
(int[] fs) Add a structure to the heap.int
add
(int len, int val) Reserve space forlen
items on the heap and set the first item toval
.(package private) int
Return the number of cells used.(package private) int
int
(package private) int[]
int
private void
grow()
void
grow
(int len) private final void
initHeap()
private final void
initHeap
(int size) (package private) void
reinit
(int[] md, int[] shortHeap) private void
reinitNoMetaData
(int[] shortHeap) Re-init the heap without metadata.(package private) void
reinitSizeOnly
(int newSize) Re-create the heap for the given size.void
reset()
Reset the temporary heap.(package private) void
reset
(boolean doFullReset) Reset the temporary heap.
-
Field Details
-
debugLogShrink
private static final boolean debugLogShrink- See Also:
-
MIN_SIZE
public static final int MIN_SIZEMinimum size of the heap. Currently set to1000
.- See Also:
-
DEFAULT_SIZE
public static final int DEFAULT_SIZEDefault size of the heap. Currently set to500000
(2 MB).- See Also:
-
MULTIPLICATION_LIMIT
private static final int MULTIPLICATION_LIMIT- See Also:
-
initialSize
private int initialSize -
heap
int[] heap -
pos
private int pos -
max
private int max -
shrinkableCount
private final int[] shrinkableCount -
SIZE_POS
private static final int SIZE_POS- See Also:
-
TMPP_POS
private static final int TMPP_POS- See Also:
-
TMPM_POS
private static final int TMPM_POS- See Also:
-
PGSZ_POS
private static final int PGSZ_POS- See Also:
-
AVSZ_POS
private static final int AVSZ_POS- See Also:
-
AVST_POS
private static final int AVST_POS- See Also:
-
-
Constructor Details
-
Heap
public Heap()Default constructor. -
Heap
public Heap(int initialSize) Constructor lets you set initial heap size. Use only if you know what you're doing.- Parameters:
initialSize
- The initial heap size. If this is smaller than theMIN_SIZE
, the default will be used instead.
-
-
Method Details
-
initHeap
private final void initHeap() -
initHeap
private final void initHeap(int size) -
reinit
void reinit(int[] md, int[] shortHeap) -
reinitNoMetaData
private void reinitNoMetaData(int[] shortHeap) Re-init the heap without metadata. Use default values for metadata.- Parameters:
shortHeap
-
-
reinitSizeOnly
void reinitSizeOnly(int newSize) Re-create the heap for the given size. Just use the size of the incoming heap, unless it's smaller than our minimum. It is expected that the caller will then fill in the new heap up to newSize.- Parameters:
newSize
-
-
getCellsUsed
int getCellsUsed()Return the number of cells used. -
getHeapSize
int getHeapSize()- Returns:
- The overall size of the heap (in words) (including unused space).
-
getMetaData
int[] getMetaData() -
grow
private void grow() -
reset
public void reset()Reset the temporary heap. -
reset
void reset(boolean doFullReset) Reset the temporary heap. Logic for shrinking: Based on a short history of the sizes needed to hold the larger of the previous 2 sizes (Note: can be overridden by calling reset() multiple times in a row) Never shrink below initialSize Shrink in exact reverse sequence of growth - using the subtraction method and then (for small enough sizes) the dividing method Shrink 1/2 the distance to the size needed to hold the large of the prev 2 sizes -
add
public int add(int[] fs) Add a structure to the heap.- Parameters:
fs
- The input structure.- Returns:
- The position where the structure was added, i.e., a pointer to the first element of the structure.
-
add
public int add(int len, int val) Reserve space forlen
items on the heap and set the first item toval
. The other items are set to0
.- Parameters:
len
- The length of the new structure.val
- The value of the first cell in the new structure.- Returns:
- The position where the structure was added, i.e., a pointer to the first element of the structure.
-
getNextId
public int getNextId() -
grow
public void grow(int len) -
getInitialSize
public int getInitialSize()
-