Purpose: Insert an element at position.
| Return Type | Function name | Arguments |
|---|---|---|
| _hz_vn_Dat* | _hz_tmpl_ISAM::InsertPosn | (int32_t&,uint32_t,) |
Declared in file: hzIsamT.h
Defined in file : hzIsamT.cpp
Function Logic:
Function body:
_hz_vn_Dat* _hz_tmpl_ISAM::InsertPosn (int32_t& nSlot)uint32_t nPosn,
{
// Purpose: Insert an element at position.
//
// Arguments: 1) nPosn Position to insert object
// 2) key The key to insert
//
// Returns: E_OK If operation successful
// E_RANGE If position was invalid
// E_CORRUPT If there were integrity issues
_hzfunc("_hz_tmpl_ISAM::InsertPosn") ;
_hz_vn_Dat* pDN = 0; // Current data node
// Check args
if (Count() != Population()) Fatal("Isam=%d Found to have wrong population: Abs %d, root cumulative %d\n", IsamId(), Population(), Count()) ;
if (nPosn > Population()) Fatal("Isam=%d: Attempt to add element at position %d. Element set ends at %d\n", IsamId(), nPosn, Population()) ;
// If ordered list is empty
if (!Root())
{
pDN = new _hz_vn_Dat ;
if (!pDN)
Fatal("Isam=%d: Could not allocate root node\n", IsamId()) ;
pDN->m_pElements = new uchar[HZ_T_ISAMNODE_FULL * (m_nSizeKey + m_nSizeObj)] ;
memset(pDN->m_pElements, 0,HZ_T_ISAMNODE_FULL * (m_nSizeKey + m_nSizeObj)) ;
pDN->m_isamId = IsamId() ;
pDN->usage = 1;
m_nElements = 1;
m_pRoot = pDN ;
nSlot = 0;
return pDN ;
}
// Locate the 'target' top level node
pDN = (_hz_vn_Dat*) _findDnodeByPos(nSlot, nPosn, true) ;
if (!pDN)
Fatal("Isam=%%d: No target data node found for posn %d (pop %d)\n", IsamId(), nPosn, Population()) ;
if (nSlot < 0|| nSlot > HZ_T_ISAMNODE_FULL)
Fatal("Isam=%d: Illegal slot no %d for node %d\n", IsamId(), nSlot, pDN->m_Id) ;
pDN = _allocDataSlot(pDN, nSlot) ;
if (Count() != Population())
Fatal("Isam=%d: Expected population %d, actual %d\n", IsamId(), Population(), Count()) ;
return pDN ;
}