コード例 #1
0
static bool bpqGetMaxSizeTest() {
	SPBPQueue source = NULL;
	SPListElement e1;

	ASSERT_TRUE(-1 == spBPQueueGetMaxSize(source)); //check edge case

	// check that max size is always maxSize
	source = quickQ(0);
	ASSERT_TRUE(maxSize == spBPQueueGetMaxSize(source));

	// insert a new element and check max size
	e1 = spListElementCreate(1, 1.0);
	spBPQueueEnqueue(source, e1);
	ASSERT_TRUE(maxSize == spBPQueueGetMaxSize(source));

	// insert another element and check max size
	spListElementSetIndex(e1, 2);
	spListElementSetValue(e1, 2.0);
	spBPQueueEnqueue(source, e1);
	ASSERT_TRUE(maxSize == spBPQueueGetMaxSize(source));

	// remove an element and check max size
	spBPQueueDequeue(source);
	ASSERT_TRUE(maxSize == spBPQueueGetMaxSize(source));

	// free memory
	spBPQueueDestroy(source);
	spListElementDestroy(e1);
	return true;
}
コード例 #2
0
ファイル: SPBPriorityQueue.c プロジェクト: orrbarkat/c
bool spBPQueueIsFull(SPBPQueue source){
	assert(source);
	if (spListGetSize(source->list) == spBPQueueGetMaxSize(source)){
		return true;
	}
	return false;
}
コード例 #3
0
SP_BPQUEUE_MSG spBPQueueInsertNotEmptyNotLast(SPBPQueue source,
		SPListElement element) {
	SP_LIST_MSG retVal;
	retVal = spListInsertBeforeCurrent(source->queue, element);

	if (retVal == SP_LIST_OUT_OF_MEMORY)
		return SP_BPQUEUE_OUT_OF_MEMORY;

	if (spBPQueueSize(source) > spBPQueueGetMaxSize(source))
		return spBPQueueHandleFullCapacity(source);

	return SP_BPQUEUE_SUCCESS;
}
コード例 #4
0
SP_BPQUEUE_MSG spBPQueueEnqueue(SPBPQueue source, SPListElement element) {
	spMinimalVerifyArguments(source != NULL && source->queue != NULL && element != NULL,
			SP_BPQUEUE_INVALID_ARGUMENT);

	if (spBPQueueGetMaxSize(source) == 0)
		return SP_BPQUEUE_FULL;


	// the list is full and the element is greater than all the current items
	if (spBPQueueIsFull(source) && spListElementCompare(element, source->maxElement) >= 0) {
		return SP_BPQUEUE_FULL;
	}

	if (spBPQueueIsEmpty(source))
		return spBPQueueInsertIfEmpty(source,element);

	//insert to a non empty queue
	return spBPQueueInsertNotEmpty(source, element);
}
コード例 #5
0
bool spBPQueueIsFull(SPBPQueue source) {
	assert(source != NULL);
	return spBPQueueSize(source) == spBPQueueGetMaxSize(source);
}