I am trying to implement the insert function, which inserts a new value into a hash table.
I am getting a compile error though which doesn't make sense to me.
To outline my data structure, I have a hash_set which includes a vector<HashNode*> m_table. Each HashNode is constructed like a node in a doubly linked list, so each HashNode has a 'next' and 'prev' where the end node points to 0.
My compilation error is this.
Code:hash_set.h: In member function ‘std::pair<hash_set<KeyType, HashFunc>::iterator, bool> hash_set<KeyType, HashFunc>::insert(const KeyType&)’: hash_set.h:185: error: name lookup of ‘pt’ changed for new ISO ‘for’ scoping hash_set.h:181: error: using obsolete binding at ‘pt’
And here is my code.
Code:// Insert the key if it is not already there. std::pair< iterator, bool > insert( KeyType const& key ) { const float LOAD_FRACTION_FOR_RESIZE = 1.25; // Resize if necessary. if ( m_size >= LOAD_FRACTION_FOR_RESIZE * m_table.size() ) this->resize_table( 2*m_table.size()+1 ); // making the new and old sizes relatively prime breaks up clusters if (find(key)==end()) return std::make_pair(end(),false); else { unsigned int hash_value = m_hash(key); unsigned int index = hash_value%m_table.size(); for (HashNode* pt = m_table[index];pt->next;pt=pt->next) { if (pt->key == key) return std::make_pair(iterator(this,index,pt),false); } pt->key=key; return std::make_pair(iterator(this,index,pt),true); } }



LinkBack URL
About LinkBacks


