mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Implemented external list traversing.
This commit is contained in:
parent
29c41fe46d
commit
26eaf668e7
2 changed files with 37 additions and 22 deletions
|
@ -208,46 +208,54 @@ ZEND_API int zend_llist_count(zend_llist *l)
|
|||
}
|
||||
|
||||
|
||||
ZEND_API void *zend_llist_get_first(zend_llist *l)
|
||||
ZEND_API void *zend_llist_get_first_ex(zend_llist *l, zend_llist_position *pos)
|
||||
{
|
||||
l->traverse_ptr = l->head;
|
||||
if (l->traverse_ptr) {
|
||||
return l->traverse_ptr->data;
|
||||
zend_llist_position *current = pos ? pos : &l->traverse_ptr;
|
||||
|
||||
*current = l->head;
|
||||
if (*current) {
|
||||
return (*current)->data;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ZEND_API void *zend_llist_get_last(zend_llist *l)
|
||||
ZEND_API void *zend_llist_get_last_ex(zend_llist *l, zend_llist_position *pos)
|
||||
{
|
||||
l->traverse_ptr = l->tail;
|
||||
if (l->traverse_ptr) {
|
||||
return l->traverse_ptr->data;
|
||||
zend_llist_position *current = pos ? pos : &l->traverse_ptr;
|
||||
|
||||
*current = l->tail;
|
||||
if (*current) {
|
||||
return (*current)->data;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ZEND_API void *zend_llist_get_next(zend_llist *l)
|
||||
ZEND_API void *zend_llist_get_next_ex(zend_llist *l, zend_llist_position *pos)
|
||||
{
|
||||
if (l->traverse_ptr) {
|
||||
l->traverse_ptr = l->traverse_ptr->next;
|
||||
if (l->traverse_ptr) {
|
||||
return l->traverse_ptr->data;
|
||||
zend_llist_position *current = pos ? pos : &l->traverse_ptr;
|
||||
|
||||
if (*current) {
|
||||
*current = (*current)->next;
|
||||
if (*current) {
|
||||
return (*current)->data;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
ZEND_API void *zend_llist_get_prev(zend_llist *l)
|
||||
ZEND_API void *zend_llist_get_prev_ex(zend_llist *l, zend_llist_position *pos)
|
||||
{
|
||||
if (l->traverse_ptr) {
|
||||
l->traverse_ptr = l->traverse_ptr->prev;
|
||||
if (l->traverse_ptr) {
|
||||
return l->traverse_ptr->data;
|
||||
zend_llist_position *current = pos ? pos : &l->traverse_ptr;
|
||||
|
||||
if (*current) {
|
||||
*current = (*current)->prev;
|
||||
if (*current) {
|
||||
return (*current)->data;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
@ -39,6 +39,7 @@ typedef struct _zend_llist {
|
|||
} zend_llist;
|
||||
|
||||
typedef int (*llist_compare_func_t) (const zend_llist_element *, const zend_llist_element *);
|
||||
typedef zend_llist_element* zend_llist_position;
|
||||
|
||||
BEGIN_EXTERN_C()
|
||||
ZEND_API void zend_llist_init(zend_llist *l, size_t size, void (*dtor)(void *data), unsigned char persistent);
|
||||
|
@ -55,10 +56,16 @@ ZEND_API int zend_llist_count(zend_llist *l);
|
|||
ZEND_API void zend_llist_sort(zend_llist *l, llist_compare_func_t comp_func);
|
||||
|
||||
/* traversal */
|
||||
ZEND_API void *zend_llist_get_first(zend_llist *l);
|
||||
ZEND_API void *zend_llist_get_last(zend_llist *l);
|
||||
ZEND_API void *zend_llist_get_next(zend_llist *l);
|
||||
ZEND_API void *zend_llist_get_prev(zend_llist *l);
|
||||
ZEND_API void *zend_llist_get_first_ex(zend_llist *l, zend_llist_position *pos);
|
||||
ZEND_API void *zend_llist_get_last_ex(zend_llist *l, zend_llist_position *pos);
|
||||
ZEND_API void *zend_llist_get_next_ex(zend_llist *l, zend_llist_position *pos);
|
||||
ZEND_API void *zend_llist_get_prev_ex(zend_llist *l, zend_llist_position *pos);
|
||||
|
||||
#define zend_llist_get_first(l) zend_llist_get_first_ex(l, NULL)
|
||||
#define zend_llist_get_last(l) zend_llist_get_last_ex(l, NULL)
|
||||
#define zend_llist_get_next(l) zend_llist_get_next_ex(l, NULL)
|
||||
#define zend_llist_get_prev(l) zend_llist_get_prev_ex(l, NULL)
|
||||
|
||||
END_EXTERN_C()
|
||||
|
||||
#endif /* _ZEND_LLIST_H */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue