Exemple #1
0
Ret dlist_delete(DList* thiz, size_t index)
{
    Ret ret = RET_OK;
    DListNode* cursor = NULL;

    return_val_if_fail(thiz != NULL, RET_INVALID_PARAMS);

    cursor = dlist_get_node(thiz, index, 0);

    do {
        if (cursor == NULL) {
            ret = RET_INVALID_PARAMS;
            break;
        }

        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;
            }

            dlist_destroy_node(thiz, cursor);
        }

    } while (0);

    return RET_OK;
}
DListRet dlist_delete(DList* thiz, size_t index)
{
	DListNode* cursor = dlist_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;
		}

		dlist_destroy_node(thiz, cursor);
	}

	return DLIST_RET_OK;
}
Exemple #3
0
int dlist_insert(DList* thiz, int index, void* data)
{
	DListNode* node = NULL;
	DListNode* cursor = NULL;

	if((node = dlist_node_create(data)) == NULL)	return -1;

	if(thiz->first == NULL) {
		thiz->first = node;
		return 0;
	}

	cursor = dlist_get_node(thiz, index, 1);

	if(index < dlist_length(thiz)) {
		if(thiz->first == cursor) {
			thiz->first = node;
		} else {
			cursor->prev->next = node;
			node->prev = cursor->prev;
		}
		node->next = cursor;
		cursor->prev = node;
	} else {
		cursor->next = node;
		node->prev = cursor;
	}

	return 0;
}
Exemple #4
0
int dlist_set_by_index(DList* thiz, int index, void* data)
{
	DListNode* cursor = dlist_get_node(thiz, index, 0);

	if(cursor != NULL)	cursor->data = data;

	return cursor != NULL ? 0 : 1;
}
DListRet dlist_set_by_index(DList* thiz, size_t index, void* data)
{
	DListNode* cursor = dlist_get_node(thiz, index, 0);

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

	return cursor != NULL ? DLIST_RET_OK : DLIST_RET_FAIL;
}
Exemple #6
0
DListRet dlist_set_by_index(DList* thiz, size_t index, void* data)
{
    DListNode* cursor = dlist_get_node(thiz, index, 0);

    return_val_if_fail(cursor != NULL, DLIST_RET_INVALID_PARAMS);

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

    return cursor != NULL ? DLIST_RET_OK : DLIST_RET_FAIL;
}
Exemple #7
0
Ret dlist_insert(DList* thiz, size_t index, void* data)
{
	Ret ret = RET_OK;
	DListNode* node = NULL;
	DListNode* cursor = NULL;

	return_val_if_fail(thiz != NULL, RET_INVALID_PARAMS); 

	dlist_lock(thiz);

	do
	{
		if((node = dlist_create_node(thiz, data)) == NULL)
		{
			ret = RET_OOM;
			break;
		}

		if(thiz->first == NULL)
		{
			thiz->first = node;
			break;
		}

		cursor = dlist_get_node(thiz, index, 1);
		
		if(index < dlist_length(thiz))
		{
			node->next = cursor;
			if(cursor->prev != NULL)
			{
				cursor->prev->next = node;
			}
			cursor->prev = node;
			if(thiz->first == cursor)
			{
				thiz->first = node;
			}
		}
		else
		{
			cursor->next = node;
			node->prev = cursor;
		}
	}while(0);

	dlist_unlock(thiz);

	return ret;
}
Exemple #8
0
Ret dlist_get_by_index(DList* thiz, size_t index, void** data)
{
    DListNode* cursor = NULL;

    return_val_if_fail(thiz != NULL && data != NULL, RET_INVALID_PARAMS);

    cursor = dlist_get_node(thiz, index, 0);

    if (cursor != NULL) {
        *data = cursor->data;
    }

    return cursor != NULL ? RET_OK : RET_INVALID_PARAMS;
}
Exemple #9
0
int dlist_delete(DList* thiz, int index)
{
	DListNode* cursor = dlist_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;

		dlist_node_destroy(cursor);
	}

	return 0;
}
Exemple #10
0
Ret dlist_set_by_index(DList* thiz, size_t index, void* data)
{
    DListNode* cursor = NULL;

    return_val_if_fail(thiz != NULL, RET_INVALID_PARAMS);

    dlist_wrlock(thiz);

    cursor = dlist_get_node(thiz, index, 0);

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

    dlist_unlock(thiz);

    return cursor != NULL ? RET_OK : RET_INVALID_PARAMS;
}
DListRet dlist_insert(DList* thiz, size_t index, void* data)
{
	DListNode* node = NULL;
	DListNode* cursor = NULL;

	if((node = dlist_create_node(thiz, data)) == NULL)
	{
		return DLIST_RET_OOM; 
	}

	if(thiz->first == NULL)
	{
		thiz->first = node;

		return DLIST_RET_OK;
	}

	cursor = dlist_get_node(thiz, index, 1);
	
	if(index < dlist_length(thiz))
	{
		if(thiz->first == cursor)
		{
			thiz->first = node;
		}
		else
		{
			cursor->prev->next = node;
			node->prev = cursor->prev;
		}
		node->next = cursor;
		cursor->prev = node;
	}
	else
	{
		cursor->next = node;
		node->prev = cursor;
	}

	return DLIST_RET_OK;
}