- Add hash_apply_with_arguments()

This commit is contained in:
Andi Gutmans 1999-08-25 19:02:13 +00:00
parent 3b408ce516
commit 746ce67b66
2 changed files with 44 additions and 2 deletions

View File

@ -819,6 +819,35 @@ ZEND_API void zend_hash_apply_with_argument(HashTable *ht,int (*destruct) (void
}
ZEND_API void zend_hash_apply_with_arguments(HashTable *ht,int (*destruct)(void *, int, va_list, zend_hash_key *), int num_args, ...)
{
Bucket *p, *q;
va_list args;
zend_hash_key hash_key;
va_start(args, num_args);
p = ht->pListHead;
while (p != NULL) {
q = p;
p = p->pListNext;
hash_key.arKey = q->arKey;
hash_key.nKeyLength = q->nKeyLength;
hash_key.h = q->h;
if (destruct(q->pData, num_args, args, &hash_key)) {
if (q->nKeyLength == 0) {
zend_hash_index_del(ht, q->h);
} else {
zend_hash_del(ht,q->arKey,q->nKeyLength);
}
}
}
va_end(args);
}
ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, void (*pCopyConstructor) (void *pData), void *tmp, uint size)
{
Bucket *p;

View File

@ -98,13 +98,26 @@ ZEND_API int zend_hash_index_update_or_next_insert(HashTable *ht, ulong h, void
ZEND_API int zend_hash_pointer_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData);
typedef struct _zend_hash_key {
char *arKey;
uint nKeyLength;
ulong h;
} zend_hash_key;
#define ZEND_STD_HASH_APPLIER \
int (*)(void *element, int num_args, va_list args, zend_hash_key *hash_key)
ZEND_API int zend_hash_pointer_index_update_or_next_insert(HashTable *ht, ulong h, void *pData, int flag);
#define zend_hash_pointer_index_update(ht,h,pData) \
zend_hash_pointer_index_update_or_next_insert(ht,h,pData,HASH_UPDATE)
#define zend_hash_next_index_pointer_insert(ht,pData) \
zend_hash_pointer_index_update_or_next_insert(ht,0,pData,HASH_NEXT_INSERT)
ZEND_API void zend_hash_apply(HashTable *ht,int (*destruct) (void *));
ZEND_API void zend_hash_apply_with_argument(HashTable *ht,int (*destruct) (void *, void *), void *);
ZEND_API void zend_hash_apply(HashTable *ht,int (*destruct)(void *));
ZEND_API void zend_hash_apply_with_argument(HashTable *ht,int (*destruct)(void *, void *), void *);
ZEND_API void zend_hash_apply_with_arguments(HashTable *ht, ZEND_STD_HASH_APPLIER, int, ...);