Advertisement
expired6978

NET3

Mar 10th, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. NiExtraData* NiObjectNET::GetExtraData(const NiFixedString& kKey) const
  2. {
  3.     if (!kKey.Exists())
  4.     {
  5. #ifndef __SPU__
  6.         NiOutputDebugString(
  7.             "Error:  Attempt to retrieve ExtraData with null name.");
  8. #endif
  9.         return NULL;
  10.     }
  11.  
  12.     NIASSERT(m_usExtraDataSize < SHRT_MAX);
  13.  
  14.     short sBottom = 0;
  15.     short sTop = (short)m_usExtraDataSize - 1;
  16.     short sMiddle = 0;
  17.  
  18.     while (sBottom <= sTop)
  19.     {
  20.         sMiddle = (sTop + sBottom) >> 1; // Average to get the middle.
  21.  
  22.         ptrdiff_t dtCompare = ((const char*)kKey) -
  23.             ((const char*)m_ppkExtra[sMiddle]->GetName());
  24.  
  25.         if (dtCompare == 0)  // Equal keys.  Return found extra data.
  26.         {
  27.             return m_ppkExtra[sMiddle];
  28.         }
  29.         else if (dtCompare > 0)  // Search key is > "middle" key.
  30.         {
  31.             sBottom = sMiddle + 1;
  32.         }
  33.         else    // Search key is < "middle" key.
  34.         {
  35.             sTop = sMiddle - 1;
  36.         }
  37.     }
  38.  
  39.     return NULL;    // Couldn't find Extra Data for the given search key.
  40. }
  41. //---------------------------------------------------------------------------
  42. bool NiObjectNET::RemoveExtraData(const NiFixedString& kKey)
  43. {
  44.     if (m_usExtraDataSize == 0)
  45.         return NULL;
  46.  
  47.     if (!kKey.Exists())
  48.     {
  49. #ifndef __SPU__
  50.         NiOutputDebugString(
  51.             "Error:  Attempt to remove ExtraData using a null name.");
  52. #endif
  53.         return false;
  54.     }
  55.  
  56.     NIASSERT(m_usExtraDataSize < SHRT_MAX);
  57.  
  58.     short sBottom = 0;
  59.     short sTop = (short)m_usExtraDataSize - 1;
  60.     short sMiddle = 0;
  61.  
  62.     while (sBottom <= sTop)
  63.     {
  64.         sMiddle = (sTop + sBottom) >> 1; // Average to get the middle.
  65.  
  66.         ptrdiff_t dtCompare = ((const char*)kKey) -
  67.             ((const char*) m_ppkExtra[sMiddle]->GetName());
  68.  
  69.         if (dtCompare == 0)  // Equal keys.  Return found extra data.
  70.         {
  71.             DeleteExtraData(sMiddle);
  72.  
  73.             return true;
  74.         }
  75.         else if (dtCompare > 0)  // Search key is > "middle" key.
  76.         {
  77.             sBottom = sMiddle + 1;
  78.         }
  79.         else    // Search key is < "middle" key.
  80.         {
  81.             sTop = sMiddle - 1;
  82.         }
  83.     }
  84.  
  85.     return false;    // Couldn't find Extra Data for the given search key.
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement