C
Christian Christmann
Hi,
I've some problems with iterators on hashtbales.
My hashtable.h
class HashTable
{
map<int, void*> nhash;
map<int, void*> getNhash();
....
}
----------
My hashtable.cpp:
map<int, void*> HashTable::getNhash() {
return nhash;
}
}
void HashTable::Insert(int ky,void* entr) {
nhash.insert(pair<int, void*>(ky, entr));
}
....
----------
In another class I use this hashtable:
HashTable lNodes;
const std::map<int, void*>::const_iterator begin =
lNodes.getNhash().begin(); const std::map<int, void*>::const_iterator end
= lNodes.getNhash().end(); std::map<int, void*>::const_iterator iter =
begin;
cout << "Size: " << lNodes.getNhash().size() << endl;
while (iter != end)
{
cout << "Key: " << iter->first << endl; ++iter;
}
}
The output:
Size: 3
Key: 0x80a2de0
or
Size: 12
Key: 0x80b8ae8
Key: 0x80b8ee8
Key: 0x80b9170
Key: 0x80b9af0
Key: 0x80bbb68
Key: 0x80bbf68
Key: 0x80bc1f0
Key: 0x80bcb70
There are always some elements missing. Even if the size is 3 just 1
element is printed.
Only with hashtables of size 1 I get the correct output.
What's wrong?
Thank you for your help
Chris
I've some problems with iterators on hashtbales.
My hashtable.h
class HashTable
{
map<int, void*> nhash;
map<int, void*> getNhash();
....
}
----------
My hashtable.cpp:
map<int, void*> HashTable::getNhash() {
return nhash;
}
}
void HashTable::Insert(int ky,void* entr) {
nhash.insert(pair<int, void*>(ky, entr));
}
....
----------
In another class I use this hashtable:
HashTable lNodes;
const std::map<int, void*>::const_iterator begin =
lNodes.getNhash().begin(); const std::map<int, void*>::const_iterator end
= lNodes.getNhash().end(); std::map<int, void*>::const_iterator iter =
begin;
cout << "Size: " << lNodes.getNhash().size() << endl;
while (iter != end)
{
cout << "Key: " << iter->first << endl; ++iter;
}
}
The output:
Size: 3
Key: 0x80a2de0
or
Size: 12
Key: 0x80b8ae8
Key: 0x80b8ee8
Key: 0x80b9170
Key: 0x80b9af0
Key: 0x80bbb68
Key: 0x80bbf68
Key: 0x80bc1f0
Key: 0x80bcb70
There are always some elements missing. Even if the size is 3 just 1
element is printed.
Only with hashtables of size 1 I get the correct output.
What's wrong?
Thank you for your help
Chris