Class MultiBinaryLongMap.LongStorage
- java.lang.Object
-
- com.tangosol.util.MultiBinaryLongMap.LongStorage
-
- Enclosing class:
- MultiBinaryLongMap
protected static class MultiBinaryLongMap.LongStorage extends Object
An internal data structure for managing elastic storage of multi-dimensional data; basically, it is a two-dimensional array of rows and columns that can be grown in either dimension, but is optimized specifically for the addition and removal of rows.The first dimension is a sequence of "slots" (i.e. rows) that each hold one or more indexed values. The second dimension is a sequence of "indexes" (i.e. columns). A combination of a slot and an index is used to access or modify a specific long value.
-
-
Field Summary
Fields Modifier and Type Field Description protected static long[][]
EMPTY
Empty storage.protected long[][]
m_aalStorage
The internal storage for the LongStorage, divided into segments, with each segment being an array of long values.protected int
m_cFree
The number of slots that are available ("free").protected int
m_cFreeThreshold
The number of free slots at which compression becomes indicated.protected int
m_cIndexes
The total number of indexes.protected int
m_cTotal
The total number of slots.protected int
m_iFreeSlot
The index of the first free slot, or -1.
-
Constructor Summary
Constructors Constructor Description LongStorage(int cIndexes)
Construct a LongStorage that will initially hold cIndexes columns of data.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
addIndex()
Add an additional index value to each slot.protected static int
calcFirstSlotIndex(int iSegment)
Given a segment index, determine the slot index of the first slot that is stored in the segment.protected static int
calcSegmentIndex(int iSlot)
Give a slot index, determine what segment index the slot will be found in.protected static int
calcSegmentSize(int iSegment)
Given an array segment index, determine the size of the array in slots.void
clear()
Reset the LongStorage to its initial empty state.void
compressBegin()
Begin the compression of the LongStorage into the minimum number of contiguous slots.void
compressEnd()
Complete the LongStorage compression process.int
compressRelocate(int iSlot)
Relocate a reserved slot from a slot index that is at or beyondgetSlotCount()
.void
copy(int iSlotSrc, int iSlotDest)
Copy the contents of one slot to another.int
countValues(int iIndex)
For any index > 0, count the number of values in the LongStorage that are non-zero.long
get(int iSlot, int iIndex)
Load a value.int
getCapacity()
Determine the current capacity (the actual number of slots for which storage has been allocated) in the LongStorage.int
getIndexCount()
Determine the number of indexes (columns) supported by the LongStorage.int
getSlotCount()
Determine the number of slots that have been reserved in the LongStorage.protected void
grow()
Add a new segment of slot storage.boolean
isCompressionIndicated()
Determine if the LongStorage should be compressed.void
put(int iSlot, int iIndex, long lValue)
Store a value.protected void
recalculateShrinkageThreshold()
Determine at what point the LongStorage should be compressed.void
releaseSlot(int iSlot)
Release a previously-reserved slot.void
removeIndex(int iIndex)
Remove an index value from each slot.int
reserveSlot()
Reserve a slot to use for storing information.void
reset(int iSlot)
Reset all of the values in a specified slot to zero.
-
-
-
Field Detail
-
EMPTY
protected static final long[][] EMPTY
Empty storage.
-
m_aalStorage
protected long[][] m_aalStorage
The internal storage for the LongStorage, divided into segments, with each segment being an array of long values. A segment is further divided into slots, such that the first slot is found at element zero in the array, and the second slot is foundm_cIndexes
elements after that. A slot is further divided into indexed values, with the first element of the slot containing the first indexed value, the second element of the slot containing the second indexed value, and so on.For example: 16,16,16,16,32,32,32,32,64,64,64,64,128,128,128,128,256,...
-
m_cIndexes
protected int m_cIndexes
The total number of indexes. This is the number of long values that can be stored in a single slot.
-
m_cTotal
protected int m_cTotal
The total number of slots.
-
m_cFree
protected int m_cFree
The number of slots that are available ("free").
-
m_iFreeSlot
protected int m_iFreeSlot
The index of the first free slot, or -1.
-
m_cFreeThreshold
protected int m_cFreeThreshold
The number of free slots at which compression becomes indicated.
-
-
Method Detail
-
getIndexCount
public int getIndexCount()
Determine the number of indexes (columns) supported by the LongStorage. For each index, one value is stored in each slot (row).- Returns:
- the number of values stored in each slot
-
getSlotCount
public int getSlotCount()
Determine the number of slots that have been reserved in the LongStorage.- Returns:
- the number of slots that have been reserved
-
getCapacity
public int getCapacity()
Determine the current capacity (the actual number of slots for which storage has been allocated) in the LongStorage.Note: During the compression phase, the capacity is set to the number of slots in use, which is the level to which the LongStorage is compressed.
- Returns:
- the total number of slots that are currently allocated in the LongStorage
-
addIndex
public int addIndex()
Add an additional index value to each slot.It is the responsibility of the caller to ensure that no multi-threaded access to the LongStorage occurs during this process.
- Returns:
- the index identifier of the new index value
-
removeIndex
public void removeIndex(int iIndex)
Remove an index value from each slot.It is the responsibility of the caller to ensure that no multi-threaded access to the LongStorage occurs during this process.
- Parameters:
iIndex
- the index identifier of the index value to remove
-
reserveSlot
public int reserveSlot()
Reserve a slot to use for storing information.It is the responsibility of the caller to ensure that no multi-threaded access to the LongStorage occurs during this process.
- Returns:
- the slot index that was newly reserved
-
grow
protected void grow()
Add a new segment of slot storage.
-
releaseSlot
public void releaseSlot(int iSlot)
Release a previously-reserved slot.It is the responsibility of the caller to ensure that no multi-threaded access to the LongStorage occurs during this process.
- Parameters:
iSlot
- the slot index to release
-
clear
public void clear()
Reset the LongStorage to its initial empty state.It is the responsibility of the caller to ensure that no multi-threaded access to the LongStorage occurs during this process.
-
get
public long get(int iSlot, int iIndex)
Load a value.- Parameters:
iSlot
- the slot index to load the value fromiIndex
- the value index from which to load the value- Returns:
- the value from the specified index of the specified slot
-
put
public void put(int iSlot, int iIndex, long lValue)
Store a value.- Parameters:
iSlot
- the slot index to store a value iniIndex
- the value index to store a value forlValue
- the value to store in the specified index of the specified slot
-
countValues
public int countValues(int iIndex)
For any index > 0, count the number of values in the LongStorage that are non-zero.- Parameters:
iIndex
- a valid index, other than the zero index- Returns:
- the number of values in that index that are non-zero
-
reset
public void reset(int iSlot)
Reset all of the values in a specified slot to zero.- Parameters:
iSlot
- the slot index to reset
-
copy
public void copy(int iSlotSrc, int iSlotDest)
Copy the contents of one slot to another.- Parameters:
iSlotSrc
- the slot to copy fromiSlotDest
- the slot to copy to
-
recalculateShrinkageThreshold
protected void recalculateShrinkageThreshold()
Determine at what point the LongStorage should be compressed.
-
isCompressionIndicated
public boolean isCompressionIndicated()
Determine if the LongStorage should be compressed.- Returns:
- true iff the LongStorage should be compressed
- See Also:
compressBegin()
-
compressBegin
public void compressBegin()
Begin the compression of the LongStorage into the minimum number of contiguous slots.Compression is a 4-step process:
- The applicability of compression is determined using
isCompressionIndicated()
; - The process is initiated by calling
compressBegin()
; - For each slot i that has been reserved, if
(i >=
getSlotCount()
), the reservation must be relocated by callingcompressRelocate(i)
; - The process is concluded by calling
compressEnd()
.
- The applicability of compression is determined using
-
compressRelocate
public int compressRelocate(int iSlot)
Relocate a reserved slot from a slot index that is at or beyondgetSlotCount()
.- Parameters:
iSlot
- a slot index for a reserved slot whose index is at or beyondgetSlotCount()
- Returns:
- the new slot index for the specified reserved slot
- See Also:
compressBegin()
-
compressEnd
public void compressEnd()
Complete the LongStorage compression process.- See Also:
compressBegin()
-
calcSegmentSize
protected static int calcSegmentSize(int iSegment)
Given an array segment index, determine the size of the array in slots.- Parameters:
iSegment
- the segment index- Returns:
- the number of slots that the segment will hold
-
calcSegmentIndex
protected static int calcSegmentIndex(int iSlot)
Give a slot index, determine what segment index the slot will be found in.- Parameters:
iSlot
- the slot index- Returns:
- the segment index
-
calcFirstSlotIndex
protected static int calcFirstSlotIndex(int iSegment)
Given a segment index, determine the slot index of the first slot that is stored in the segment.- Parameters:
iSegment
- the segment index- Returns:
- the slot index of the first slot stored in the specified segment
-
-