Beispiel #1
0
int list_delete_all(List l, ListFindF f, void *key)
{
    ListNode *pp;
    void *v;
    int n = 0;

    assert(l != NULL);
    assert(f != NULL);
    assert(key != NULL);
    list_mutex_lock(&l->mutex);
    assert(l->magic == LIST_MAGIC);
    pp = &l->head;
    while (*pp) {
        if (f((*pp)->data, key)) {
            if ((v = list_node_destroy(l, pp))) {
                if (l->fDel)
                    l->fDel(v);
                n++;
            }
        }
        else {
            pp = &(*pp)->next;
        }
    }
    list_mutex_unlock(&l->mutex);
    return(n);
}
Beispiel #2
0
/* _list_pop_locked
 *
 * Pop an item from the list assuming the
 * the list is already locked.
 */
static void *
_list_pop_locked(List l)
{
	void *v;

	v = list_node_destroy(l, &l->head);

	return v;
}
Beispiel #3
0
void list_destroy(list_t *list) {
    list_node_t *temp;
    for (list_node_t *node = list->head; node; ) {
        temp = node->next;
        list_node_destroy(node);
        node = temp;
    }
    list_atcache_destroy(list);
    free(list);
}
Beispiel #4
0
void * list_dequeue(List l)
{
    void *v;

    assert(l != NULL);
    list_mutex_lock(&l->mutex);
    assert(l->magic == LIST_MAGIC);
    v = list_node_destroy(l, &l->head);
    list_mutex_unlock(&l->mutex);
    return(v);
}
void *list_pop(llist *l)
{
	void *data = NULL;
	list_node *tmp_node = NULL;
	if (l) {
		tmp_node = l->node;
		data = tmp_node->data;
		l->node = tmp_node->next;
		list_node_destroy(tmp_node);
	}
	return data;
}
/* Removes a node from the list
 * Arguments: The list and the node that will be removed
 */
void list_remove(llist *l, list_node *node)
{
	if (!l || !node) return;
	list_node *tmp = l->node;

	while (tmp->next && tmp->next != node) tmp = tmp->next;
	if (tmp->next) {
		tmp->next = node->next;
		list_node_destroy(node);
		node = NULL;
	}
}
Beispiel #7
0
void * list_remove(ListIterator i)
{
    void *v = NULL;

    assert(i != NULL);
    assert(i->magic == LIST_MAGIC);
    list_mutex_lock(&i->list->mutex);
    assert(i->list->magic == LIST_MAGIC);
    if (*i->prev != i->pos)
        v = list_node_destroy(i->list, i->prev);
    list_mutex_unlock(&i->list->mutex);
    return(v);
}
Beispiel #8
0
void
list_destroy(TinyList *thiz) {
		TinyListNode *iter = thiz->first;
		TinyListNode *next = NULL;
		while(iter != NULL) {
			next = iter->next;
			list_node_destroy(iter);
			iter = next;
		}
		thiz->first = NULL;
		free(thiz);
		return;
}
Beispiel #9
0
void list_destroy(list *ls)
{
    node *curr, *next;

    curr = ls->head;
    while (curr)
    {
        next = curr->next;
        list_node_destroy(curr, ls->free_func);
        curr = next;
    }

    free(ls);
}
Beispiel #10
0
void				list_clear(t_list *list)
{
	t_list_node	*it;
	t_list_node	*next;

	it = list->first;
	next = NULL;
	while (it)
	{
		next = it->next;
		list_node_destroy(it, list->dfunc);
		free(it);
		it = next;
	}
	list->first = NULL;
	list->last = NULL;
}
Beispiel #11
0
ListRet
list_delete(TinyList *thiz, size_t index) {
		TinyListNode *cursor = list_get_node(thiz, index, 0);
		if(cursor != NULL) {
			if(cursor == thiz->first) {
				thiz->first = cursor->next;
			}

			if(cursor->next != NULL) {
				cursor->next->prev = cursor->prev;
			}

			if(cursor->prev != NULL) {
				cursor->prev->next = cursor->next;
			}
			list_node_destroy(cursor);
		}
		return LIST_RET_OK;
}
Beispiel #12
0
void list_remove(list *ls, int index)
{
    int count = 0;
    node *curr, *next;

    curr = ls->head;
    next = curr->next;
    while (count < index)
    {
        if (count++ > ls->length) return; // End function
        curr = next;
        next = curr->next;
    }

    // Update pointer and delete orphan
    curr->next = next->next;
    list_node_destroy(next, ls->free_func);

}
Beispiel #13
0
t_list_node			*list_erase(t_list *list, t_list_node *node)
{
	t_list_node	*next;
	t_list_node	*prev;

	if (node == NULL)
		return (NULL);
	next = node->next;
	prev = node->prev;
	if (next)
		next->prev = prev;
	if (prev)
		prev->next = next;
	if (node == list->first)
		list->first = next;
	if (node == list->first)
		list->last = prev;
	list_node_destroy(node, list->dfunc);
	free(node);
	return (next);
}
Beispiel #14
0
bool list_erase(list_t *list, void *element) {
    for (list_node_t *curr = list->head; curr; curr = curr->next) {
        if (curr->element != element)
            continue;

        if (curr == list->head)
            list->head = list->head->next;
        if (curr == list->tail)
            list->tail = list->tail->prev;
        if (curr->next)
            curr->next->prev = curr->prev;
        if (curr->prev)
            curr->prev->next = curr->next;

        list_node_destroy(curr);
        list->length--;
        list_atcache_thrash(list);
        return true;
    }
    return false;
}
Beispiel #15
0
/* list_flush()
 */
int
list_flush (List l)
{
	ListNode *pp;
	void *v;
	int n = 0;

	assert(l != NULL);
	slurm_mutex_lock(&l->mutex);
	assert(l->magic == LIST_MAGIC);

	pp = &l->head;
	while (*pp) {
		if ((v = list_node_destroy(l, pp))) {
			if (l->fDel)
				l->fDel(v);
			n++;
		}
	}
	slurm_mutex_unlock(&l->mutex);

	return n;
}
Beispiel #16
0
static void list_node_scrub(list_node_t **node) {
    list_node_destroy(*node);
    *node = NULL;
}