Permalink
Browse files

- Add hash_apply_with_arguments()

  • Loading branch information...
1 parent 3b408ce commit 746ce67b66cafbbf971b00d0ad34e2dd4487065a @andigutmans andigutmans committed Aug 25, 1999
Showing with 44 additions and 2 deletions.
  1. +29 −0 Zend/zend_hash.c
  2. +15 −2 Zend/zend_hash.h
View
@@ -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
@@ -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, ...);
+

0 comments on commit 746ce67

Please sign in to comment.