fixed OpenHashTable::Iterator, it wasn't working for a single item.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20862 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Hugo Santos
2007-04-27 14:47:34 +00:00
parent 87ac9f1d46
commit 01a10fc527
+6 -14
View File
@@ -169,7 +169,7 @@ public:
class Iterator { class Iterator {
public: public:
Iterator(const HashTable *table) Iterator(const HashTable *table)
: fTable(table), fIndex(0), fCurrent(NULL), fNext(NULL) : fTable(table)
{ {
Rewind(); Rewind();
} }
@@ -178,8 +178,7 @@ public:
ValueType *Next() ValueType *Next()
{ {
ValueType *current = fCurrent; ValueType *current = fNext;
fCurrent = fNext;
_GetNext(); _GetNext();
return current; return current;
} }
@@ -188,22 +187,15 @@ public:
{ {
// get the first one // get the first one
fIndex = 0; fIndex = 0;
fCurrent = NULL; fNext = NULL;
_GetNext(); _GetNext();
fCurrent = fNext;
// get the proper next one
if (fCurrent)
_GetNext();
} }
private: private:
void _GetNext() void _GetNext()
{ {
if (fCurrent) { if (fNext)
fNext = fTable->_Link(fCurrent)->fNext; fNext = fTable->_Link(fNext)->fNext;
} else {
fNext = NULL;
}
while (fNext == NULL && fIndex < fTable->fTableSize) while (fNext == NULL && fIndex < fTable->fTableSize)
fNext = fTable->fTable[fIndex++]; fNext = fTable->fTable[fIndex++];
@@ -211,7 +203,7 @@ public:
const HashTable *fTable; const HashTable *fTable;
size_t fIndex; size_t fIndex;
ValueType *fCurrent, *fNext; ValueType *fNext;
}; };
Iterator GetIterator() const { return Iterator(this); } Iterator GetIterator() const { return Iterator(this); }