Added the clone method. Approved by warren

This commit is contained in:
raman 1998-06-01 22:11:06 +00:00
parent 1688dff125
commit 24d011f72a
3 changed files with 29 additions and 0 deletions

View File

@ -137,6 +137,20 @@ void *nsHashtable::Remove(nsHashKey *aKey) {
return res;
}
static PR_CALLBACK PRIntn _hashEnumerateCopy(PLHashEntry *he, PRIntn i, void *arg)
{
nsHashtable *newHashtable = (nsHashtable *)arg;
newHashtable->Put((nsHashKey *) he->key, he->value);
return HT_ENUMERATE_NEXT;
}
nsHashtable * nsHashtable::Clone() {
nsHashtable *newHashTable = new nsHashtable(hashtable->nentries);
PL_HashTableEnumerateEntries(hashtable, _hashEnumerateCopy, newHashTable);
return newHashTable;
}
void nsHashtable::Enumerate(nsHashtableEnumFunc aEnumFunc) {
PL_HashTableEnumerateEntries(hashtable, _hashEnumerate, aEnumFunc);
}

View File

@ -137,6 +137,20 @@ void *nsHashtable::Remove(nsHashKey *aKey) {
return res;
}
static PR_CALLBACK PRIntn _hashEnumerateCopy(PLHashEntry *he, PRIntn i, void *arg)
{
nsHashtable *newHashtable = (nsHashtable *)arg;
newHashtable->Put((nsHashKey *) he->key, he->value);
return HT_ENUMERATE_NEXT;
}
nsHashtable * nsHashtable::Clone() {
nsHashtable *newHashTable = new nsHashtable(hashtable->nentries);
PL_HashTableEnumerateEntries(hashtable, _hashEnumerateCopy, newHashTable);
return newHashTable;
}
void nsHashtable::Enumerate(nsHashtableEnumFunc aEnumFunc) {
PL_HashTableEnumerateEntries(hashtable, _hashEnumerate, aEnumFunc);
}

View File

@ -49,6 +49,7 @@ public:
void *Put(nsHashKey *aKey, void *aData);
void *Get(nsHashKey *aKey);
void *Remove(nsHashKey *aKey);
nsHashtable *Clone();
void Enumerate(nsHashtableEnumFunc aEnumFunc);
};