Exemplo n.º 1
0
static bool testElementCopy() {
	ASSERT_TRUE(spListElementCopy(NULL) == NULL);
	SPListElement element = spListElementCreate(1, 0.0);
	SPListElement elementCopy = spListElementCopy(element);
	ASSERT_TRUE(elementCopy!=NULL);
	ASSERT_TRUE(spListElementCompare(element, elementCopy) == 0);
	ASSERT_TRUE(spListElementSetIndex(elementCopy, 2) == SP_ELEMENT_SUCCESS);
	ASSERT_TRUE(spListElementCompare(element, elementCopy) < 0);
	ASSERT_TRUE(spListElementGetIndex(elementCopy) == 2);
	ASSERT_TRUE(spListElementGetIndex(element) == 1);
	ASSERT_TRUE(spListElementSetValue(element, 1.0) == SP_ELEMENT_SUCCESS);
	ASSERT_TRUE(spListElementCompare(element, elementCopy) > 0);
	spListElementDestroy(element);
	spListElementDestroy(elementCopy);
	return true;
}
Exemplo n.º 2
0
SPListElement spBPQueuePeek(SPBPQueue source) {
	SPListElement first;
	spMinimalVerifyArgumentsRn(source != NULL);

	first = spListGetFirst(source->queue);

	return spListElementCopy(first);
}
Exemplo n.º 3
0
SPListElement spBPQueuePeekLast(SPBPQueue source){
	assert(source);
		if(spBPQueueIsEmpty(source)){
			return NULL;
		}
		SPListElement ret = spListGetLast(source->list);
		if (!ret){ return NULL;}
		return spListElementCopy(ret);
}
Exemplo n.º 4
0
SP_BPQUEUE_MSG spBPQueueInsertIfEmpty(SPBPQueue source, SPListElement newElement) {
	SP_LIST_MSG retVal;
	retVal = spListInsertFirst(source->queue, newElement);
	if (retVal == SP_LIST_OUT_OF_MEMORY)
		return SP_BPQUEUE_OUT_OF_MEMORY;

	source->maxElement = spListElementCopy(newElement);

	if (source->maxElement == NULL)
		return SP_BPQUEUE_OUT_OF_MEMORY;

	return SP_BPQUEUE_SUCCESS;
}
Exemplo n.º 5
0
Node createNode(Node previous, Node next, SPListElement element) {
	SPListElement newElement = spListElementCopy(element);
	if (newElement == NULL) {
		return NULL;
	}
	Node newNode = (Node) malloc(sizeof(*newNode));
	if (newNode == NULL) {
		spListElementDestroy(newElement);
		return NULL;
	}
	newNode->data = newElement;
	newNode->previous = previous;
	newNode->next = next;
	return newNode;
}
Exemplo n.º 6
0
SP_BPQUEUE_MSG spBPQueueInsertNotEmptyButLast(SPBPQueue source, SPListElement element) {
	SP_LIST_MSG retVal;
	retVal = spListInsertLast(source->queue, element);

	if (retVal == SP_LIST_OUT_OF_MEMORY)
		return SP_BPQUEUE_OUT_OF_MEMORY;

	spListElementDestroy(source->maxElement);
	source->maxElement = spListElementCopy(element);

	if (source->maxElement == NULL)
		return SP_BPQUEUE_OUT_OF_MEMORY;

	return SP_BPQUEUE_SUCCESS;
}
Exemplo n.º 7
0
SP_BPQUEUE_MSG spBPQueueHandleFullCapacity(SPBPQueue source) {
	int i;
	SPListElement currElemInQueue, prevElemInQueue;
	currElemInQueue = spListGetFirst(source->queue);
	prevElemInQueue = currElemInQueue;

	for (i=1;i<spBPQueueSize(source);i++) {
		prevElemInQueue = currElemInQueue;
		currElemInQueue = spListGetNext(source->queue);
	}

	// if we get here we assume we never reached the end of the list (meaning null)
	// because we assume spBPQueueSize is valid
	spListRemoveCurrent(source->queue);

	spListElementDestroy(source->maxElement);
	source->maxElement = spListElementCopy(prevElemInQueue);
	if (source->maxElement == NULL)
		return SP_BPQUEUE_OUT_OF_MEMORY;

	return SP_BPQUEUE_SUCCESS;

}
Exemplo n.º 8
0
SPBPQueue spBPQueueCreateWrapper(int maxSize, SPBPQueue source_queue, bool createNewList) {
	SPBPQueue newQueue;
	spMinimalVerifyArgumentsRn(maxSize > 0);

	spCalloc(newQueue, sp_bp_queue_t, 1);

	newQueue->capacity = maxSize;


	if (createNewList) {
		newQueue->queue = spListCreate();
		newQueue->maxElement = NULL;
	}
	else {
		newQueue->queue = spListCopy(source_queue->queue);
		newQueue->maxElement = spListElementCopy(source_queue->maxElement);
	}

	//allocation error, or given source queue is NULL and createNewList if false
	if (newQueue->queue == NULL)
		return NULL;

	return newQueue;
}
Exemplo n.º 9
0
SPListElement spBPQueuePeekLast(SPBPQueue source) {
	return spListElementCopy(spBPQueueLastElement(source));
}
Exemplo n.º 10
0
SPListElement spBPQueuePeek(SPBPQueue source) {
	return spListElementCopy(spBPQueueFirstElement(source));
}
Exemplo n.º 11
0
SPListElement spBPQueuePeekLast(SPBPQueue source) {
	spMinimalVerifyArgumentsRn(source != NULL);
	return spListElementCopy(source->maxElement);
}
Exemplo n.º 12
0
SPListElement spBPQueuePeekLast(SPBPQueue source){
    if (!source) return NULL;
    if (source->size==0) return NULL;
    return spListElementCopy(source->last->element);
}