Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class TYPE>
- bool LPHash<TYPE>::remove(const char* key) {
- // Variable Declaration & Initialisation
- bool RC = false;
- int nCurrentEmptyPosition;
- //int nKeyExpectedPosition = HashFunction(key, this->m_nAllocatedSpace);
- int nKeyActualPosition = this->getPosition(key);
- // Function Main
- if (nKeyActualPosition > -1) {
- // Delete key
- delete this->m_pData[nKeyActualPosition];
- this->m_pData[nKeyActualPosition] = 0;
- this->m_nUsedSpace--;
- RC = true;
- nCurrentEmptyPosition = nKeyActualPosition;
- // Swap applicable nodes backwards after key
- for (int i = (nCurrentEmptyPosition + 1) % this->m_nAllocatedSpace;
- i != nKeyActualPosition && this->m_pData[i] != 0;
- i = (i + 1) % this->m_nAllocatedSpace) {
- int nIExpectedPosition = HashFunction(this->m_pData[i]->key(), this->m_nAllocatedSpace);
- if (
- /*
- (nCurrentEmptyPosition >= HashFunction(this->m_pData[i]->key(), this->m_nAllocatedSpace) && i < HashFunction(this->m_pData[i]->key(), this->m_nAllocatedSpace) && i < nCurrentEmptyPosition) ||
- (nCurrentEmptyPosition >= HashFunction(this->m_pData[i]->key(), this->m_nAllocatedSpace) && i > HashFunction(this->m_pData[i]->key(), this->m_nAllocatedSpace) && i > nCurrentEmptyPosition) ||
- (nCurrentEmptyPosition < HashFunction(this->m_pData[i]->key(), this->m_nAllocatedSpace) && i < HashFunction(this->m_pData[i]->key(), this->m_nAllocatedSpace) && i > nCurrentEmptyPosition)
- (HashFunction(this->m_pData[i]->key(), this->m_nAllocatedSpace) > nCurrentEmptyPosition && i > nCurrentEmptyPosition && HashFunction(this->m_pData[i]->key(), this->m_nAllocatedSpace) >= nCurrentEmptyPosition) ||
- (HashFunction(this->m_pData[i]->key(), this->m_nAllocatedSpace) < i && i < nCurrentEmptyPosition && HashFunction(this->m_pData[i]->key(), this->m_nAllocatedSpace) < nCurrentEmptyPosition) ||
- (HashFunction(this->m_pData[i]->key(), this->m_nAllocatedSpace) < i && i > nCurrentEmptyPosition && HashFunction(this->m_pData[i]->key(), this->m_nAllocatedSpace) <= nCurrentEmptyPosition)
- (nIExpectedPosition > nCurrentEmptyPosition && i > nCurrentEmptyPosition && nIExpectedPosition >= nCurrentEmptyPosition) ||
- (nIExpectedPosition < i && i < nCurrentEmptyPosition && nIExpectedPosition < nCurrentEmptyPosition) ||
- (nIExpectedPosition < i && i > nCurrentEmptyPosition && nIExpectedPosition <= nCurrentEmptyPosition)
- (nIExpectedPosition > i && i > nCurrentEmptyPosition && nIExpectedPosition >= nCurrentEmptyPosition) ||
- (nIExpectedPosition < i && i < nCurrentEmptyPosition && nIExpectedPosition < nCurrentEmptyPosition) ||
- (nIExpectedPosition < i && i > nCurrentEmptyPosition && nIExpectedPosition <= nCurrentEmptyPosition)
- (nCurrentEmptyPosition >= nIExpectedPosition && i < nIExpectedPosition && i < nCurrentEmptyPosition) ||
- (nCurrentEmptyPosition >= nIExpectedPosition && i > nIExpectedPosition && i > nCurrentEmptyPosition) ||
- (nCurrentEmptyPosition < nIExpectedPosition && i < nIExpectedPosition && i > nCurrentEmptyPosition)
- */
- (nCurrentEmptyPosition >= nIExpectedPosition && i < nIExpectedPosition && i < nCurrentEmptyPosition) ||
- (nCurrentEmptyPosition >= nIExpectedPosition && i > nIExpectedPosition && i > nCurrentEmptyPosition) ||
- (nCurrentEmptyPosition < nIExpectedPosition && i < nIExpectedPosition && i > nCurrentEmptyPosition)
- ) {
- this->m_pData[nCurrentEmptyPosition] = this->m_pData[i];
- nCurrentEmptyPosition = i;
- delete this->m_pData[nCurrentEmptyPosition];
- this->m_pData[nCurrentEmptyPosition] = 0;
- }
- }
- }
- return RC;
- }
Advertisement
Add Comment
Please, Sign In to add comment