Determine if the supplied key matches any found in the ISAM

Return TypeFunction nameArguments
boolhdbIsamfile::Exists(hzString&,)

Declared in file: hzDatabase.h
Defined in file : hdbIsamfile.cpp

Function Logic:

0:START 1:items m_Cond items 2:unknown 3:items 4:Return false 5:unknown 6:items 7:Return false 8:unknown 9:Return false 10:unknown 11:Return false 12:nPos 13:unknown 14:m_Index 15:nPos 16:strA 17:unknown 18:items 19:unknown 20:unknown 21:addr items 22:unknown 23:m_Cond items 24:Return false 25:items 26:unknown 27:m_Cond items 28:Return false 29:unknown 30:unknown 31:* 32:unknown 33:strA i j 34:unknown 35:strB i 36:j 37:unknown 38:items strB strA 39:Return tmp.Exists(key)

Function body:

bool hdbIsamfile::Exists (hzString& key)
{
   //  Determine if the supplied key matches any found in the ISAM
   //  
   //  Argument: key  The search key
   //  
   //  Returns: True If the key is found
   //     False Otherwise
   _hzfunc("hdbIsamfile::Exists") ;
   hzMapM<hzString,hzString>   tmp ;   //  Temp map of key/object pairs found in target data area
   char*       i ;             //  Buffer iterator
   char*       j ;             //  Buffer iterator
   hzString    strA ;          //  Key string
   hzString    strB ;          //  Object string
   uint32_t    nPos ;          //  Position of target within m_Index map
   uint32_t    addr ;          //  Address of target data block
   uint32_t    nC ;            //  Counter
   //  Check init state
   m_Error.Clear() ;
   m_Cond = E_OK ;
   m_Error.Printf("%s called\n", *_fn) ;
   if (m_nInitState < 1)   { hzwarn(E_NOINIT, "ISAM file not initialized") ; return false ; }
   if (m_nInitState < 2)   { hzwarn(E_NOTOPEN, "ISAM file not open") ; return false ; }
   if (!key)
       return false ;
   if (!m_Index.Count())
       return false ;
   //  Identify target data block
   nPos = m_Index.Target(key) ;
   if (nPos >&eq; m_Index.Count())
       nPos = m_Index.Count() -1;
   strA = m_Index.GetKey(nPos) ;
   if (strA > key)
       nPos-- ;
   for (; nPos < m_Index.Count() ; nPos++)
   {
       if (m_Index.GetKey(nPos) > key)
           break ;
       //  Read in target data block
       addr = m_Index.GetObj(nPos) ;
       m_RdD.seekg(addr * m_nBlkSize) ;
       if (m_RdD.fail())
           { m_Cond = E_READFAIL ; m_Error.Printf("%s: Failed to seek to block %d (position %d) in data block\n", *_fn, addr, addr * m_nBlkSize) ; return false ; }
       m_RdD.read(m_Buf, HZ_BLOCKSIZE) ;
       if (m_RdD.fail())
           { m_Cond = E_READFAIL ; m_Error.Printf("%s: Failed to read block %d (position %d) in data block\n", *_fn, addr, addr * m_nBlkSize) ; return false ; }
       for (i = j = m_Buf, nC = 0; nC < HZ_BLOCKSIZE ; i++, nC++)
       {
           if (m_Buf[nC] == CHAR_NL)
           {
               *i = 0;
               if (!strA)
                   { strA = j ; j = i + 1; continue ; }
               if (*j)
                   strB = j ;
               j = i + 1;
               if (!strA)
                   break ;
               tmp.Insert(strA, strB) ;
               strA = strB = (char*) 0;
           }
       }
   }
   return tmp.Exists(key) ;
}