Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions
zend_llist.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _zend_llist_element
struct  _zend_llist

Defines

#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)

Typedefs

typedef struct _zend_llist_element zend_llist_element
typedef void(* llist_dtor_func_t )(void *)
typedef int(* llist_compare_func_t )(const zend_llist_element **, const zend_llist_element **TSRMLS_DC)
typedef void(* llist_apply_with_args_func_t )(void *data, int num_args, va_list args TSRMLS_DC)
typedef void(* llist_apply_with_arg_func_t )(void *data, void *arg TSRMLS_DC)
typedef void(* llist_apply_func_t )(void *TSRMLS_DC)
typedef struct _zend_llist zend_llist
typedef zend_llist_elementzend_llist_position

Functions

ZEND_API void zend_llist_init (zend_llist *l, size_t size, llist_dtor_func_t dtor, unsigned char persistent)
ZEND_API void zend_llist_add_element (zend_llist *l, void *element)
ZEND_API void zend_llist_prepend_element (zend_llist *l, void *element)
ZEND_API void zend_llist_del_element (zend_llist *l, void *element, int(*compare)(void *element1, void *element2))
ZEND_API void zend_llist_destroy (zend_llist *l)
ZEND_API void zend_llist_clean (zend_llist *l)
ZEND_API void * zend_llist_remove_tail (zend_llist *l)
ZEND_API void zend_llist_copy (zend_llist *dst, zend_llist *src)
ZEND_API void zend_llist_apply (zend_llist *l, llist_apply_func_t func TSRMLS_DC)
ZEND_API void zend_llist_apply_with_del (zend_llist *l, int(*func)(void *data))
ZEND_API void zend_llist_apply_with_argument (zend_llist *l, llist_apply_with_arg_func_t func, void *arg TSRMLS_DC)
ZEND_API void zend_llist_apply_with_arguments (zend_llist *l, llist_apply_with_args_func_t func TSRMLS_DC, int num_args,...)
ZEND_API int zend_llist_count (zend_llist *l)
ZEND_API void zend_llist_sort (zend_llist *l, llist_compare_func_t comp_func TSRMLS_DC)
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)

Class Documentation

struct _zend_llist_element

Definition at line 25 of file zend_llist.h.

Collaboration diagram for _zend_llist_element:
Class Members
char data
struct _zend_llist_element * next
struct _zend_llist_element * prev
struct _zend_llist

Definition at line 37 of file zend_llist.h.

Collaboration diagram for _zend_llist:
Class Members
size_t count
llist_dtor_func_t dtor
zend_llist_element * head
unsigned char persistent
size_t size
zend_llist_element * tail
zend_llist_element * traverse_ptr

Define Documentation

Definition at line 71 of file zend_llist.h.

Definition at line 72 of file zend_llist.h.

Definition at line 73 of file zend_llist.h.

Definition at line 74 of file zend_llist.h.


Typedef Documentation

typedef void(* llist_apply_func_t)(void *TSRMLS_DC)

Definition at line 35 of file zend_llist.h.

typedef void(* llist_apply_with_arg_func_t)(void *data, void *arg TSRMLS_DC)

Definition at line 34 of file zend_llist.h.

typedef void(* llist_apply_with_args_func_t)(void *data, int num_args, va_list args TSRMLS_DC)

Definition at line 33 of file zend_llist.h.

Definition at line 32 of file zend_llist.h.

typedef void(* llist_dtor_func_t)(void *)

Definition at line 31 of file zend_llist.h.

typedef struct _zend_llist zend_llist

Definition at line 47 of file zend_llist.h.


Function Documentation

ZEND_API void zend_llist_add_element ( zend_llist l,
void *  element 
)

Definition at line 37 of file zend_llist.c.

{
       zend_llist_element *tmp = pemalloc(sizeof(zend_llist_element)+l->size-1, l->persistent);

       tmp->prev = l->tail;
       tmp->next = NULL;
       if (l->tail) {
              l->tail->next = tmp;
       } else {
              l->head = tmp;
       }
       l->tail = tmp;
       memcpy(tmp->data, element, l->size);

       ++l->count;
}

Here is the caller graph for this function:

ZEND_API void zend_llist_apply ( zend_llist l,
llist_apply_func_t func  TSRMLS_DC 
)

Definition at line 188 of file zend_llist.c.

{
       zend_llist_element *element;

       for (element=l->head; element; element=element->next) {
              func(element->data TSRMLS_CC);
       }
}

Here is the caller graph for this function:

ZEND_API void zend_llist_apply_with_argument ( zend_llist l,
llist_apply_with_arg_func_t  func,
void *arg  TSRMLS_DC 
)

Definition at line 231 of file zend_llist.c.

{
       zend_llist_element *element;

       for (element=l->head; element; element=element->next) {
              func(element->data, arg TSRMLS_CC);
       }
}

Here is the caller graph for this function:

ZEND_API void zend_llist_apply_with_arguments ( zend_llist l,
llist_apply_with_args_func_t func  TSRMLS_DC,
int  num_args,
  ... 
)

Definition at line 241 of file zend_llist.c.

{
       zend_llist_element *element;
       va_list args;

       va_start(args, num_args);
       for (element=l->head; element; element=element->next) {
              func(element->data, num_args, args TSRMLS_CC);
       }
       va_end(args);
}

Here is the caller graph for this function:

ZEND_API void zend_llist_apply_with_del ( zend_llist l,
int(*)(void *data)  func 
)

Definition at line 173 of file zend_llist.c.

{
       zend_llist_element *element, *next;

       element=l->head;
       while (element) {
              next = element->next;
              if (func(element->data)) {
                     DEL_LLIST_ELEMENT(element, l);
              }
              element = next;
       }
}

Here is the caller graph for this function:

Definition at line 124 of file zend_llist.c.

{
       zend_llist_destroy(l);
       l->head = l->tail = NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ZEND_API void zend_llist_copy ( zend_llist dst,
zend_llist src 
)

Definition at line 160 of file zend_llist.c.

{
       zend_llist_element *ptr;

       zend_llist_init(dst, src->size, src->dtor, src->persistent);
       ptr = src->head;
       while (ptr) {
              zend_llist_add_element(dst, ptr->data);
              ptr = ptr->next;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 254 of file zend_llist.c.

{
       return l->count;
}

Here is the caller graph for this function:

ZEND_API void zend_llist_del_element ( zend_llist l,
void *  element,
int(*)(void *element1, void *element2)  compare 
)

Definition at line 91 of file zend_llist.c.

{
       zend_llist_element *current=l->head;
       zend_llist_element *next;

       while (current) {
              next = current->next;
              if (compare(current->data, element)) {
                     DEL_LLIST_ELEMENT(current, l);
                     break;
              }
              current = next;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 107 of file zend_llist.c.

{
       zend_llist_element *current=l->head, *next;
       
       while (current) {
              next = current->next;
              if (l->dtor) {
                     l->dtor(current->data);
              }
              pefree(current, l->persistent);
              current = next;
       }

       l->count = 0;
}

Here is the caller graph for this function:

Definition at line 260 of file zend_llist.c.

{
       zend_llist_position *current = pos ? pos : &l->traverse_ptr;

       *current = l->head;
       if (*current) {
              return (*current)->data;
       } else {
              return NULL;
       }
}

Here is the caller graph for this function:

Definition at line 273 of file zend_llist.c.

{
       zend_llist_position *current = pos ? pos : &l->traverse_ptr;

       *current = l->tail;
       if (*current) {
              return (*current)->data;
       } else {
              return NULL;
       }
}

Definition at line 286 of file zend_llist.c.

{
       zend_llist_position *current = pos ? pos : &l->traverse_ptr;

       if (*current) {
              *current = (*current)->next;
              if (*current) {
                     return (*current)->data;
              }
       }
       return NULL;
}

Here is the caller graph for this function:

Definition at line 300 of file zend_llist.c.

{
       zend_llist_position *current = pos ? pos : &l->traverse_ptr;

       if (*current) {
              *current = (*current)->prev;
              if (*current) {
                     return (*current)->data;
              }
       }
       return NULL;
}
ZEND_API void zend_llist_init ( zend_llist l,
size_t  size,
llist_dtor_func_t  dtor,
unsigned char  persistent 
)

Definition at line 26 of file zend_llist.c.

{
       l->head  = NULL;
       l->tail  = NULL;
       l->count = 0;
       l->size  = size;
       l->dtor  = dtor;
       l->persistent = persistent;
}

Here is the caller graph for this function:

ZEND_API void zend_llist_prepend_element ( zend_llist l,
void *  element 
)

Definition at line 55 of file zend_llist.c.

{
       zend_llist_element *tmp = pemalloc(sizeof(zend_llist_element)+l->size-1, l->persistent);

       tmp->next = l->head;
       tmp->prev = NULL;
       if (l->head) {
              l->head->prev = tmp;
       } else {
              l->tail = tmp;
       }
       l->head = tmp;
       memcpy(tmp->data, element, l->size);

       ++l->count;
}

Here is the caller graph for this function:

Definition at line 131 of file zend_llist.c.

{
       zend_llist_element *old_tail;
       void *data;

       if ((old_tail = l->tail)) {
              if (old_tail->prev) {
                     old_tail->prev->next = NULL;
              } else {
                     l->head = NULL;
              }
        
              data = old_tail->data;

              l->tail = old_tail->prev;
              if (l->dtor) {
                     l->dtor(data);
              }
              pefree(old_tail, l->persistent);

              --l->count;

              return data;
       }

       return NULL;
}

Here is the caller graph for this function:

ZEND_API void zend_llist_sort ( zend_llist l,
llist_compare_func_t comp_func  TSRMLS_DC 
)

Definition at line 197 of file zend_llist.c.

{
       size_t i;

       zend_llist_element **elements;
       zend_llist_element *element, **ptr;

       if (l->count <= 0) {
              return;
       }

       elements = (zend_llist_element **) emalloc(l->count * sizeof(zend_llist_element *));

       ptr = &elements[0];

       for (element=l->head; element; element=element->next) {
              *ptr++ = element;
       }

       zend_qsort(elements, l->count, sizeof(zend_llist_element *), (compare_func_t) comp_func TSRMLS_CC);

       l->head = elements[0];
       elements[0]->prev = NULL;

       for (i = 1; i < l->count; i++) {
              elements[i]->prev = elements[i-1];
              elements[i-1]->next = elements[i];
       }
       elements[i-1]->next = NULL;
       l->tail = elements[i-1];
       efree(elements);
}

Here is the call graph for this function:

Here is the caller graph for this function: