Guest User

Untitled

a guest
Apr 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. template <class KeyType, class DataType>
  2. void HASHTABLE<KeyType,DataType>::insert(const KeyType& key, const DataType& data)
  3. {
  4.     int insert;
  5.    
  6.     if ( find( key, insert) )
  7.         m_data[insert] = data;
  8.     else
  9.     {
  10.         if ( COLLECTION<DataType>::m_size == m_capacity )
  11.             throw std::length_error( "HASHTABLE is full, dude!" );
  12.        
  13.         insert = hash( key );
  14.         int counter = 0;
  15.         while ( m_key[insert] == CURRENTLY_FILLED && counter < m_capacity)
  16.         {
  17.             insert = ( insert + 1 ) % m_capacity;
  18.             counter++;
  19.         }
  20.         m_key_store[insert] = key;
  21.         m_key[insert] = CURRENTLY_FILLED;
  22.         m_data[insert] = data;
  23.         COLLECTION<DataType>::m_size++;
  24.     }
  25. }
Add Comment
Please, Sign In to add comment