]> granicus.if.org Git - php/commitdiff
Introduced a way to traverse hashes through external pointers.
authorAndrei Zmievski <andrei@php.net>
Mon, 13 Mar 2000 15:25:18 +0000 (15:25 +0000)
committerAndrei Zmievski <andrei@php.net>
Mon, 13 Mar 2000 15:25:18 +0000 (15:25 +0000)
Zend/zend_hash.c
Zend/zend_hash.h

index d5d5f3326b85750fab710f81896b537250569201..ded362ec722d7172a4b18e7c168dcd3619ce39c2 100644 (file)
@@ -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);
 
index fee4206f93ad405747945dfbff2ae3fadbcf7ecf..bef0f074b1cbcf2f6ac9de68bbe1e779cc85bf5d 100644 (file)
@@ -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);