From: Andrei Zmievski Date: Mon, 13 Mar 2000 15:25:18 +0000 (+0000) Subject: Introduced a way to traverse hashes through external pointers. X-Git-Tag: PHP-4.0-RC1~155 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a32c54bdbb68f4f9126217893fca51c62c02c702;p=php Introduced a way to traverse hashes through external pointers. --- diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index d5d5f3326b..ded362ec72 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -893,48 +893,60 @@ ZEND_API int zend_hash_num_elements(HashTable *ht) } -ZEND_API void zend_hash_internal_pointer_reset(HashTable *ht) +ZEND_API void zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos) { IS_CONSISTENT(ht); - ht->pInternalPointer = ht->pListHead; + if (pos) + *pos = ht->pListHead; + else + ht->pInternalPointer = ht->pListHead; } /* This function will be extremely optimized by remembering * the end of the list */ -ZEND_API void zend_hash_internal_pointer_end(HashTable *ht) +ZEND_API void zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos) { IS_CONSISTENT(ht); - ht->pInternalPointer = ht->pListTail; + if (pos) + *pos = ht->pListTail; + else + ht->pInternalPointer = ht->pListTail; } -ZEND_API void zend_hash_move_forward(HashTable *ht) +ZEND_API void zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos) { IS_CONSISTENT(ht); - if (ht->pInternalPointer) { + if (pos) { + *pos = (*pos)->pListNext; + } else if (ht->pInternalPointer) { ht->pInternalPointer = ht->pInternalPointer->pListNext; } } -ZEND_API void zend_hash_move_backwards(HashTable *ht) +ZEND_API void zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos) { IS_CONSISTENT(ht); - if (ht->pInternalPointer) { + if (pos) { + *pos = (*pos)->pListLast; + } else if (ht->pInternalPointer) { ht->pInternalPointer = ht->pInternalPointer->pListLast; } } /* This function should be made binary safe */ -ZEND_API int zend_hash_get_current_key(HashTable *ht, char **str_index, ulong *num_index) +ZEND_API int zend_hash_get_current_key_ex(HashTable *ht, char **str_index, ulong *num_index, HashPosition *pos) { - Bucket *p = ht->pInternalPointer; + Bucket *p; + + p = pos ? (*pos) : ht->pInternalPointer; IS_CONSISTENT(ht); @@ -952,9 +964,11 @@ ZEND_API int zend_hash_get_current_key(HashTable *ht, char **str_index, ulong *n } -ZEND_API int zend_hash_get_current_key_type(HashTable *ht) +ZEND_API int zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos) { - Bucket *p = ht->pInternalPointer; + Bucket *p; + + p = pos ? (*pos) : ht->pInternalPointer; IS_CONSISTENT(ht); @@ -969,9 +983,11 @@ ZEND_API int zend_hash_get_current_key_type(HashTable *ht) } -ZEND_API int zend_hash_get_current_data(HashTable *ht, void **pData) +ZEND_API int zend_hash_get_current_data_ex(HashTable *ht, void **pData, HashPosition *pos) { - Bucket *p = ht->pInternalPointer; + Bucket *p; + + p = pos ? (*pos) : ht->pInternalPointer; IS_CONSISTENT(ht); diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index fee4206f93..bef0f074b1 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -73,6 +73,8 @@ typedef struct hashtable { #endif } HashTable; +typedef Bucket* HashPosition; + BEGIN_EXTERN_C() /* startup/shutdown */ @@ -146,13 +148,28 @@ ZEND_API int zend_hash_index_exists(HashTable *ht, ulong h); ZEND_API ulong zend_hash_next_free_element(HashTable *ht); /* traversing */ -ZEND_API void zend_hash_move_forward(HashTable *ht); -ZEND_API void zend_hash_move_backwards(HashTable *ht); -ZEND_API int zend_hash_get_current_key(HashTable *ht, char **str_index, ulong *num_index); -ZEND_API int zend_hash_get_current_key_type(HashTable *ht); -ZEND_API int zend_hash_get_current_data(HashTable *ht, void **pData); -ZEND_API void zend_hash_internal_pointer_reset(HashTable *ht); -ZEND_API void zend_hash_internal_pointer_end(HashTable *ht); +ZEND_API void zend_hash_move_forward_ex(HashTable *ht, HashPosition *pos); +ZEND_API void zend_hash_move_backwards_ex(HashTable *ht, HashPosition *pos); +ZEND_API int zend_hash_get_current_key_ex(HashTable *ht, char **str_index, ulong *num_index, HashPosition *pos); +ZEND_API int zend_hash_get_current_key_type_ex(HashTable *ht, HashPosition *pos); +ZEND_API int zend_hash_get_current_data_ex(HashTable *ht, void **pData, HashPosition *pos); +ZEND_API void zend_hash_internal_pointer_reset_ex(HashTable *ht, HashPosition *pos); +ZEND_API void zend_hash_internal_pointer_end_ex(HashTable *ht, HashPosition *pos); + +#define zend_hash_move_forward(ht) \ + zend_hash_move_forward_ex(ht, NULL) +#define zend_hash_move_backwards(ht) \ + zend_hash_move_backwards_ex(ht, NULL) +#define zend_hash_get_current_key(ht, str_index, num_index) \ + zend_hash_get_current_key_ex(ht, str_index, num_index, NULL) +#define zend_hash_get_current_key_type(ht) \ + zend_hash_get_current_key_type_ex(ht, NULL) +#define zend_hash_get_current_data(ht, pData) \ + zend_hash_get_current_data_ex(ht, pData, NULL) +#define zend_hash_internal_pointer_reset(ht) \ + zend_hash_internal_pointer_reset_ex(ht, NULL) +#define zend_hash_internal_pointer_end(ht) \ + zend_hash_internal_pointer_end_ex(ht, NULL) /* Copying, merging and sorting */ ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size);