コード例 #1
0
ファイル: list.c プロジェクト: YorkTsai2011/libds
void list_remove(list_p list, char end){
	void * data;
	if(end == FRONT)
		data = list_poll(list);
	else if (end == BACK)
		data = list_pop(list);
	else return;
	list->destructor(data);
}
コード例 #2
0
ファイル: list.c プロジェクト: YorkTsai2011/libds
void destroy_list(list_p list){
	lnode_p cur = list->first;
	lnode_p next;
	while(cur!=NULL){
		next = cur->next;
		list->destructor(cur->data);
		free(cur);
		cur = next;
	}
	free(list);
}
コード例 #3
0
void destroy_list(list_p list){
	lnode_p cur = list->first;
	lnode_p next;
	while(cur!=NULL){
		next = cur->next;
		if(list->destructor != NULL) { // only destroy data if there is a destructor set
			list->destructor(cur->data);
		}
		free(cur);
		cur = next;
	}
	free(list);
}
コード例 #4
0
ファイル: list.c プロジェクト: gitter-badger/rpgxEF
/**
 * Function for completely destroying an item in the list at a given index.
 *
 *	\param list pointer to a list
 *	\param idx index of the element to remove
 */
static void list_remove_at(list_p list, int idx) {
	container_p cont;
	list_iter_p iter;
	lnode_p target = NULL;
	int i;

	if(idx < 0 || idx >= list->length || list->length == 0) {
		return;
	}

	iter = list_iterator(list, LIST_FRONT);
	for(cont = list_next(iter), i = 0; cont != NULL; cont = list_next(iter), i++) {
		if(i == idx) {
			target = iter->current;
			break;
		}
	}
	destroy_iterator(iter);

	if(target == NULL) {
		return;
	}

	if(list->length == 1) {
		list->first = list->last = NULL;
		list->length--;

		free(target);
	} else {
		target->prev->next = target->next;
		target->next->prev = target->prev;

		if(target == list->first) {
			list->first = target->next;
		}
		if(target == list->last) {
			list->last = target->prev;
		}
		list->length--;

		free(target);
	}

	if(cont != NULL) {
		if(cont->pointer == 0 && cont->data != NULL) {
			list->destructor(cont->data);
		}

		free(cont);
	}
}
コード例 #5
0
ファイル: list.c プロジェクト: gitter-badger/rpgxEF
/**
 * Convenience function for completely destroying an item in the list. If the end
 * flag is LIST_FRONT, an item will be polled from the front of the list and its data
 * freed. If the end flag is set to LIST_BACK, an item will be popped off the end of
 * the list and the data freed. 
 *
 *	\param list pointer to a list
 *	\param end indicator where to remove
 */
static void list_remove(list_p list, char end) {
	container_p cont;

	if(end == LIST_FRONT) {
		cont = list_poll(list);
	} else if (end == LIST_BACK) {
		cont = list_pop(list);
	} else {
		return;
	}

	if(cont != NULL) {
		if(cont->pointer == 0 && cont->data != NULL) {
			list->destructor(cont->data);
		}

		free(cont);
	}
}