OzZy_M

Linear Probing Hashtable Constructor

Nov 26th, 2011
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. /*
  2. This single-argument constructor instantiates an LPHash object.
  3. The amount of allocated space for the object's data is set to
  4. 140% of maxExpected.
  5.  
  6.   maxExpected: Maximum allowable pieces of data.
  7. */
  8. template <class TYPE>
  9. LPHash<TYPE>::LPHash(int maxExpected) {
  10.   this->m_nUsableSpace = maxExpected;
  11.   this->m_nAllocatedSpace = this->m_nUsableSpace * 1.4;
  12.   this->m_nUsedSpace = 0;
  13.   /*
  14.   ***NOTE***
  15.   Future reference:
  16.   Allocating memory for an array of pointers with ()
  17.   at the end will initialise them all to 0.
  18.   Alternatively, you can call them like a constructor;
  19.   however, they need to have been allocated memory already:
  20.   LPHash(int maxExpected) : m_pData() { ... }
  21.   */
  22.   this->m_pData = new TYPE*[m_nAllocatedSpace]();
  23. }
  24.  
  25.  
Advertisement
Add Comment
Please, Sign In to add comment