Ejemplo n.º 1
0
Archivo: list.c Proyecto: tve/esp-idf
bool list_remove(list_t *list, void *data)
{
    assert(list != NULL);
    assert(data != NULL);

    if (list_is_empty(list)) {
        return false;
    }

    if (list->head->data == data) {
        list_node_t *next = list_free_node(list, list->head);
        if (list->tail == list->head) {
            list->tail = next;
        }
        list->head = next;
        return true;
    }

    for (list_node_t *prev = list->head, *node = list->head->next; node; prev = node, node = node->next)
        if (node->data == data) {
            prev->next = list_free_node(list, node);
            if (list->tail == node) {
                list->tail = prev;
            }
            return true;
        }

    return false;
}
Ejemplo n.º 2
0
void list_free_(list_t *list, list_free_data_fn *free_data_fn)
{
	if (list != NULL) {
		list_node_t *it = list->head;
		while (it && it->next) {
			it = it->next;
			list_free_node(it->prev, free_data_fn);
		}
		list_free_node(it, free_data_fn);
		free(list);
	}
}
Ejemplo n.º 3
0
ref_t *dslink_map_removel_get(Map *map, void *key, size_t len) {
    if (!map || map->locked) {
        return NULL;
    }
    size_t index = dslink_map_index_of_key(map, key, len);
    for (MapNode *node = map->table[index]; node != NULL; node = node->next) {
        if (map->cmp(node->entry->key->data, key, len) != 0) {
            continue;
        }
        if (node->prev == NULL) {
            if (node->next) {
                MapNode *tmp = node->next;
                tmp->prev = NULL;
                map->table[index] = tmp;
            } else {
                map->table[index] = NULL;
            }
        } else {
            node->prev->next = node->next;
            if (node->next) {
                node->next->prev = node->prev;
            }
        }

        ref_t *ref = node->entry->value;
        dslink_decref(node->entry->key);
        list_free_node(node->entry);
        dslink_free(node);
        map->size--;
        return ref;
    }
    return NULL;
}
Ejemplo n.º 4
0
__s32 BSP_disp_sprite_exit(__u32 sel)
{
	__s32 i = 0;
	list_head_t *pGuard = NULL;
	list_head_t *pNext = NULL;

	gsprite[sel].status = 0;
	for (i = 0; i < MAX_SPRITE_BLOCKS; i++) {
		gsprite[sel].block_status[i] = 0;
		gsprite[sel].sprite_hid[i] = 100 + i;
	}

	pGuard = gsprite[sel].header;
	if (pGuard) {
		pGuard->prev->next = NULL;

		while (pGuard != NULL) {
			pNext = pGuard->next;
			list_free_node(pGuard);
			pGuard = pNext;
		}
	}

	return DIS_SUCCESS;
}
Ejemplo n.º 5
0
void EndSPASMErrorSession(int nSession)
{
    list_t *pList = (list_t *) g_ErrorList;

    list_t *pPrev = NULL, *old_list = NULL;
    while ((pList != NULL) && ((LPERRORINSTANCE) pList->data)->nSession == nSession)
    {
        LPERRORINSTANCE lpErr = (LPERRORINSTANCE) pList->data;

        if (pPrev == NULL)
        {
            g_ErrorList = (errorlist_t *) pList->next;
        }
        else
        {
            pPrev->next = pList->next;
        }

        FreeErrorInstance(lpErr);
        list_t *pListOld = pList;
        pList = pList->next;
        list_free_node(pListOld);

        //assert(pList != NULL);
        if (pList == NULL)
            break;
    }

    g_nErrorSession--;
}
Ejemplo n.º 6
0
/*
 *	Write a binary tree node to disk.
 */
int pdb_write_tree_node_cb(struct pdb* dbptr, FILE* fptr,
	struct pdb_node_t* nptr, int tabs) {

	struct binaryTree* tptr;
	struct linkList* lptr;
	struct linkNode* lnptr;

	/*
	 *	Create a list from the tree so we can iterate through it.
	 */
	tptr = nptr->data;
	lptr = list_create();
	tree_to_list(tptr, lptr);
	lnptr = lptr->root;
	
	/*
	 *	Shuffle tree (if set).
	 */
	if (pdb_is_set(dbptr, PDB_WRITE_SHUFFLE))
		list_shuffle(lptr);
	
	/*
	 *	Set PDB_WRITE_NODE_FIRST_ID as the first in the list
	 *	if PDB_WRITE_NODE_FIRST is set.
	 *	Only if root node.
	 */
	if (!tabs) {
		if (pdb_is_set(dbptr, PDB_WRITE_NODE_FIRST)) {
			while (lnptr) {
				nptr = lnptr->data;
				if (!strcmp(nptr->id, PDB_WRITE_NODE_FIRST_ID)) {
					list_free_node(lptr, lnptr, 0, NULL);
					list_add_node_front(lptr, nptr);
					break;
				}
				lnptr = lnptr->next;
			}
		}
	}
	
	/*
	 *	Write all children to disk.
	 */
	lnptr = lptr->root;
	while (lnptr) {
		nptr = lnptr->data;
		if (!pdb_standard_write_node(dbptr, fptr, nptr, tabs)) {
			list_free(lptr, 0, NULL);
			return 0;
		}
		lnptr = lnptr->next;
	}
	
	/*
	 *	Free temp list (but not data).
	 */
	list_free(lptr, 0, NULL);
	
	return 1;
}
Ejemplo n.º 7
0
void list_delete(T head)
{
    T cur = head->next;

    while (cur != cur->next) {
        T tmp = list_delete_next(cur);
        /*printf("%d  ", tmp->entry);*/
        list_free_node(tmp);
    }

    list_free_node(cur);
    free(head);
#ifdef MEMPOOL
    free(freelist);
    has_init = 0;
#endif
}
Ejemplo n.º 8
0
int list_pop_back(List* l)
{
    ListNode *last;;
    if (list_is_empty(l))
        return 0;
    last = list_get_tail(l);
    list_free_node(last);
    return 1;
}
Ejemplo n.º 9
0
Archivo: list.c Proyecto: tve/esp-idf
void list_clear(list_t *list)
{
    assert(list != NULL);
    for (list_node_t *node = list->head; node; ) {
        node = list_free_node(list, node);
    }
    list->head = NULL;
    list->tail = NULL;
    list->length = 0;
}
Ejemplo n.º 10
0
int list_pop_front(List* l)
{
    ListNode *new_front;
    if (list_is_empty(l))
        return 0;
    new_front = list_get_head(l)->next;
    list_free_node(list_get_head(l));
    l->head = new_front;
    return 1;
}
Ejemplo n.º 11
0
/*
 * Block id, and the release of its space removed from the list and return to
 * the block id (the id may not be the original id)
 */
static __s32 List_Delete_Free_Sprite_Block(__u32 sel, list_head_t *node)
{
	__s32 ret = -1;

	if (node != NULL) {
		List_Delete_Sprite_Block(sel, node);
		ret = node->data->id;
		list_free_node(node);
	}
	return ret;
}
Ejemplo n.º 12
0
void list_clear(list *l)
{
	struct lnode *current = l->front, *next;

	while (current != NULL) {
		next = current->next;
		list_free_node(l, current);
		current = next;
	}
	l->front = NULL;
}
Ejemplo n.º 13
0
void remove_arg_set(list_t *arg_set) {
	//define_t *new_arg;
	if (arg_set == NULL)
		return;
	/*new_arg = (define_t*)arg_list->data;
	free(new_arg->name);
	free(new_arg);*/

	hash_free((hash_t *) arg_set->data);
	arg_list = list_remove (arg_list, arg_set);
	list_free_node(arg_set);
}
Ejemplo n.º 14
0
void FreeSPASMErrorSessions(void)
{
    list_t *pList = (list_t *) g_ErrorList;

    list_t *pNext = NULL;
    while (pList)
    {
        LPERRORINSTANCE lpErr = (LPERRORINSTANCE) pList->data;

        pNext = pList->next;
        FreeErrorInstance(lpErr);
        list_free_node(pList);
        pList = pNext;
    }
}
Ejemplo n.º 15
0
int list_remove_(list_t *list, list_node_t *it,
		list_free_data_fn *free_data_fn)
{
	if (list == NULL || it == NULL)
		return 1;
	if (list->head == it)
		list->head = it->next;
	if (list->tail == it)
		list->tail = it->prev;
	if (it->next)
		it->next->prev = it->prev;
	if (it->prev)
		it->prev->next = it->next;
	list_free_node(it, free_data_fn);
	return 0;
}
Ejemplo n.º 16
0
int list_delete_at(List *l, int pos)
{
    int i;
    ListNode *at = list_get_head(l);
    if (list_is_empty(l))
        return 0;

    if (pos==0)
        return list_pop_front(l);

    for (i=0; i<pos; i++) {
        at = at->next;
        if (!at && i!=pos-1)
            return 0;
    }

    list_free_node(at);
    return 1;
}
Ejemplo n.º 17
0
/*
 *	Free the Last Node in the
 *	Passed Link List
 */
int list_free_last(struct linkList* lptr, list_func_ptr free_callback) {
	return (list_free_node(lptr, lptr->last, 1, free_callback));
}