Skip to content

Commit

Permalink
MFZE1
Browse files Browse the repository at this point in the history
  • Loading branch information
Sterling Hughes committed Aug 31, 2001
1 parent 69c7346 commit 498f7fd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
45 changes: 21 additions & 24 deletions Zend/zend_llist.c
Expand Up @@ -23,10 +23,11 @@

ZEND_API void zend_llist_init(zend_llist *l, size_t size, llist_dtor_func_t dtor, unsigned char persistent)
{
l->head = NULL;
l->tail = NULL;
l->size = size;
l->dtor = dtor;
l->head = NULL;
l->tail = NULL;
l->count = 0;
l->size = size;
l->dtor = dtor;
l->persistent = persistent;
}

Expand All @@ -44,6 +45,8 @@ ZEND_API void zend_llist_add_element(zend_llist *l, void *element)
}
l->tail = tmp;
memcpy(tmp->data, element, l->size);

++l->count;
}


Expand All @@ -60,6 +63,8 @@ ZEND_API void zend_llist_prepend_element(zend_llist *l, void *element)
}
l->head = tmp;
memcpy(tmp->data, element, l->size);

++l->count;
}


Expand All @@ -77,7 +82,8 @@ ZEND_API void zend_llist_prepend_element(zend_llist *l, void *element)
if ((l)->dtor) {\
(l)->dtor((current)->data);\
pefree((current), (l)->persistent);\
}
}\
--l->count;


ZEND_API void zend_llist_del_element(zend_llist *l, void *element, int (*compare)(void *element1, void *element2))
Expand Down Expand Up @@ -108,6 +114,8 @@ ZEND_API void zend_llist_destroy(zend_llist *l)
pefree(current, l->persistent);
current = next;
}

l->count = 0;
}


Expand All @@ -128,14 +136,13 @@ ZEND_API void *zend_llist_remove_tail(zend_llist *l)
l->tail->prev->next = NULL;
}

/* Save the data, this doesn't get free'd,
* the pointer is just removed from the list
*/
data = old_tail->data;

l->tail = l->tail->prev;
pefree(old_tail, l->persistent);

--l->count;

return data;
}

Expand Down Expand Up @@ -182,33 +189,29 @@ ZEND_API void zend_llist_apply(zend_llist *l, llist_apply_func_t func TSRMLS_DC)

ZEND_API void zend_llist_sort(zend_llist *l, llist_compare_func_t comp_func)
{
int list_size=0, i;
int i;

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

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

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

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

ptr = &elements[0];

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

qsort(elements, list_size, sizeof(zend_llist_element *), (int (*)(const void *, const void *)) comp_func);
qsort(elements, l->count, sizeof(zend_llist_element *), (int (*)(const void *, const void *)) comp_func);

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

for (i=1; i<list_size; i++) {
for (i = 1; i < l->count; i++) {
elements[i]->prev = elements[i-1];
elements[i-1]->next = elements[i];
}
Expand Down Expand Up @@ -243,13 +246,7 @@ ZEND_API void zend_llist_apply_with_arguments(zend_llist *l, llist_apply_with_ar

ZEND_API int zend_llist_count(zend_llist *l)
{
zend_llist_element *element;
int element_count=0;

for (element=l->head; element; element=element->next) {
element_count++;
}
return element_count;
return l->count;
}


Expand Down
3 changes: 2 additions & 1 deletion Zend/zend_llist.h
Expand Up @@ -38,7 +38,8 @@ typedef void (*llist_apply_func_t)(void * TSRMLS_DC);
typedef struct _zend_llist {
zend_llist_element *head;
zend_llist_element *tail;
size_t size;
size_t count;
size_t size;
llist_dtor_func_t dtor;
unsigned char persistent;
zend_llist_element *traverse_ptr;
Expand Down

0 comments on commit 498f7fd

Please sign in to comment.