Package org.apache.uima.cas.impl
Class Heap
- java.lang.Object
-
- org.apache.uima.cas.impl.Heap
-
public final class Heap extends java.lang.Object
the v2 CAS heap - used in modeling some binary (de)serialization
-
-
Field Summary
Fields Modifier and Type Field Description private static int
AVST_POS
private static int
AVSZ_POS
private static boolean
debugLogShrink
static int
DEFAULT_SIZE
Default size of the heap.(package private) int[]
heap
private int
initialSize
private int
max
static int
MIN_SIZE
Minimum size of the heap.private static int
MULTIPLICATION_LIMIT
private static int
PGSZ_POS
private int
pos
private int[]
shrinkableCount
private static int
SIZE_POS
private static int
TMPM_POS
private static int
TMPP_POS
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
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
getCellsUsed()
Return the number of cells used (including slot 0 reserved for null)(package private) int
getHeapSize()
int
getInitialSize()
(package private) int[]
getMetaData()
int
getNextId()
(package private) static int
getRoundedSize(int size)
private void
grow()
void
grow(int len)
private void
initHeap()
private 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.int[]
toArray()
-
-
-
Field Detail
-
debugLogShrink
private static final boolean debugLogShrink
- See Also:
- Constant Field Values
-
MIN_SIZE
public static final int MIN_SIZE
Minimum size of the heap. Currently set to1000
.- See Also:
- Constant Field Values
-
DEFAULT_SIZE
public static final int DEFAULT_SIZE
Default size of the heap. Currently set to500000
(2 MB).- See Also:
- Constant Field Values
-
MULTIPLICATION_LIMIT
private static final int MULTIPLICATION_LIMIT
- See Also:
- Constant Field Values
-
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:
- Constant Field Values
-
TMPP_POS
private static final int TMPP_POS
- See Also:
- Constant Field Values
-
TMPM_POS
private static final int TMPM_POS
- See Also:
- Constant Field Values
-
PGSZ_POS
private static final int PGSZ_POS
- See Also:
- Constant Field Values
-
AVSZ_POS
private static final int AVSZ_POS
- See Also:
- Constant Field Values
-
AVST_POS
private static final int AVST_POS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 Detail
-
initHeap
private void initHeap()
-
initHeap
private 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 (including slot 0 reserved for null)
-
getHeapSize
int getHeapSize()
- Returns:
- The overall size of the heap (in words) (including unused space).
-
getMetaData
int[] getMetaData()
-
grow
private void grow()
-
getRoundedSize
static int getRoundedSize(int size)
-
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()
-
toArray
public int[] toArray()
-
-