int InitHashMap(SimpleHashMap *oHashMap, unsigned long iNumOfElements, unsigned int iKeyLength)
{
    srand( time(NULL) );
    oHashMap->numberOfBuckets = iNumOfElements * 2 - 1;
    oHashMap->elements = calloc(sizeof(SimpleLinkedList), oHashMap->numberOfBuckets);
    if (!oHashMap->elements) return -1;
    oHashMap->count = 0;
    _initCoeffs(oHashMap, iKeyLength);
    InitLinkedList(&oHashMap->IDs);
    return 0;
}
Exemplo n.º 2
0
JobsManager *GetJobsManager (void)
{
	if (!s_manager_p)
		{
			s_manager_p = (ServicesListManager *) AllocMemory (sizeof (ServicesListManager));

			InitJobsManager (& (s_manager_p -> slm_base_manager), AddServiceJobToServicesListManager, GetServiceJobFromServicesListManager, RemoveServiceJobFromServicesListManager);
			InitLinkedList (& (s_manager_p -> slm_running_services));
		}

	return (& (s_manager_p -> slm_base_manager));
}
Exemplo n.º 3
0
/*******************************************
 test main
 *******************************************/
int main(int argc, char *argv[]){
	PersonalInfo *personInfo;

	Node *head;
	Node *tail;
	Node *result;
	char *name;

	Boolean resultOfDelete;

	printf("Test - Init\n\n");
	InitLinkedList(&head, &tail);

	printf("Test - Append\n");
	personInfo = setPersonInfo("lee", "111", "busan", FALSE);
	result = Append(head, tail, personInfo);
	printPersonInfo(result);

	printf("Test - Find\n");
	name = "lee";
	result = Find(tail, head, name);
	printPersonInfo(result);

	printf("Test - Insert\n");
	personInfo = setPersonInfo("kim", "000", "seoul", FALSE);
	result = Insert(tail, result, personInfo);
	printPersonInfo(result);

	printf("Test - Delete\n");
	printf("\tTest - Find\n");
	name = "kim";
	result = Find(tail, head, name);
	printPersonInfo(result);

	resultOfDelete = Delete(head, tail, result);
	printf("resultOfDelete : %d\n", resultOfDelete);

	free(head);
	free(tail);

	printf("Test - Finish\n");
	return 0;
}
int main()
{
    SimpleLinkedList linkedList;
    long input;
    long *element, i;
    InitLinkedList(&linkedList);
    while (1) {
        printf("Enter new element to add, 0 to exit:\n");
        scanf("%ld", &input);
        if (!input)
            break;
        element = (long*)malloc(sizeof(long));
        *element = input;
        if (!AddElementToLinkedList(&linkedList, element))
        {
            printf("Current list elements are:\n");
            TraverseLinkedListElementsUsingFunc(&linkedList, &printFunc);
        }
        else { printf("Failed to add element, probably memory problems..."); break; }
    }
    DisposeLinkedListAndElements(&linkedList);
}
Exemplo n.º 5
0
assets_s* AllocateAssets(memoryBlock_s* memoryBlock)
{
	assets_s* assets = PushStruct(memoryBlock, assets_s);
    assets->assetUseQueue = InitLinkedList(memoryBlock, Kilobytes(2));
    assets->dyMemoryBlock = InitDynamicMemoryBlock(memoryBlock, Megabytes(64), Kilobytes(10));
    assets->tagCount = 1;
    assets->assetCount = 1;

    platformFileGroup_s* fileGroup = Platform.getAllFilesOfTypeBegin("wa");
    assets->fileCount = fileGroup->fileCount;
    assets->files = PushArray(memoryBlock, assets->fileCount, assetFile_s);
    for(uint32_t index = 0; index < assets->fileCount; index++)
    {
        assetFile_s* file = assets->files + index;
        file->tagBase = assets->tagCount;
        file->handle = Platform.openNextFile(fileGroup);
        file->header = {};

        Platform.readDataFromFile(file->handle, 0, sizeof(file->header), &file->header);

        uint32_t assetTypeArraySize = file->header.assetTypesCount*sizeof(waAssetType_s);
        file->assetTypeArray = (waAssetType_s*) PushSize(memoryBlock, assetTypeArraySize);
        Platform.readDataFromFile(file->handle, file->header.assetTypes, assetTypeArraySize, 
            file->assetTypeArray);
        if(PlatformNoFileErrors(file->handle))
        {
            if(file->header.magicValue != MAGIC_VALUE)
            {
                Platform.fileError(file->handle, "wa file has an invalid magic value");
            }
            if(file->header.version > WALLACE_ASSET_VERSION)
            {
                Platform.fileError(file->handle, "wa file has a version which exceeds game version");
            } 

            if(PlatformNoFileErrors(file->handle))
            {
                // NOTE: The first asset and tag slot in every
                // .wa is a null (reserved) so we don't count it as
                // something we will need space for!
                assets->tagCount += (file->header.tagCount - 1);
                assets->assetCount += (file->header.assetCount - 1);
            }
        }
        else
        {
            InvalidCodePath;
        }
    }
    Platform.getAllFilesOfTypeEnd(fileGroup);
    assets->assets = PushArray(memoryBlock, assets->assetCount, assetFileData_s);
    assets->slots = PushArray(memoryBlock, assets->assetCount, assetData_s);
    assets->tags = PushArray(memoryBlock, assets->tagCount, waTag_s);

    assets->tags[0] = {};

    for(uint32_t fileIndex = 0; fileIndex < assets->fileCount; fileIndex++)
    {
        assetFile_s* file = assets->files + fileIndex;
        if(PlatformNoFileErrors(file->handle))
        {
            uint32_t tagArraySize = sizeof(waTag_s) * (file->header.tagCount - 1);
            Platform.readDataFromFile(file->handle, file->header.tags + sizeof(waTag_s), tagArraySize, 
                assets->tags + file->tagBase);
        }
    }

    // NOTE: Reserve one null asset at the beginning
    uint32_t assetCount = 0;
    assets->assets[assetCount] = {};
    assetCount++;
    for(uint32_t destTypeId = 0; destTypeId < assetType_last; destTypeId++)
    {
        waAssetType_s* destType = assets->assetTypes + destTypeId;
        destType->firstAssetIndex = assetCount;
        for(uint32_t fileIndex = 0; fileIndex < assets->fileCount; fileIndex++)
        {
            assetFile_s* file = assets->files + fileIndex;
            if(PlatformNoFileErrors(file->handle))
            {
                for(uint32_t sourceIndex = 0; sourceIndex < file->header.assetTypesCount; sourceIndex++)
                {
                    waAssetType_s* sourceType = file->assetTypeArray + sourceIndex;
                    if(sourceType->typeId == destTypeId)
                    {
                        uint32_t assetCountForType = sourceType->onePastLastAssetIndex - 
                            sourceType->firstAssetIndex;
                        temporaryMemory_s tempMem = BeginTemporaryMemory(memoryBlock);
                        waAssetFileData_s* waAssetArray = PushArray(memoryBlock, assetCountForType, waAssetFileData_s);
                        Platform.readDataFromFile(file->handle, file->header.assets +
                                                  sourceType->firstAssetIndex * sizeof(waAssetFileData_s),
                                                  assetCountForType * sizeof(waAssetFileData_s), waAssetArray);
                        for(uint32_t assetIndex = 0; assetIndex < assetCountForType; assetIndex++)
                        {
                            waAssetFileData_s* waAsset = waAssetArray + assetIndex;

                            // Assert(assetCount < assets->assetCount);
                            assetFileData_s* asset = assets->assets + assetCount++;
                            
                            asset->fileIndex = fileIndex;
                            asset->wa = *waAsset;
                            if(asset->wa.firstTagIndex == 0)
                            {
                                asset->wa.firstTagIndex = 0;
                                asset->wa.onePastLastTagIndex = 0;
                            }
                            else
                            {
                                asset->wa.firstTagIndex += (file->tagBase - 1);
                                asset->wa.onePastLastTagIndex += (file->tagBase - 1);
                            }
                        }

                        EndTemporaryMemory(tempMem);
                    }
                }
            }
        }
        destType->onePastLastAssetIndex = assetCount;
    }

    // Assert(assetCount == assets->assetCount);
	return assets;
}
Exemplo n.º 6
0
int main(int argc, char** argv){
	FILE *input;
	int c = 0, searchIndex, i;
	char *searchWord;
	LinkedListNodes *listNode;
	
	LinkedLists *list = malloc(sizeof(LinkedLists));
	InitLinkedList(list);
	if(argc ==  2){
		/* Correct number of arguments */
		
		input = fopen(argv[1],"r+");
		if(input != NULL){
			do{
				ElementStructs *element;
				char *word = malloc(80);
				if(!feof(input)){
					fscanf(input, "%s", word);
					element = malloc(sizeof(ElementStructs));
					element->word = word;
					element->index = c;
					AddToBackOfLinkedList(list, element);
					c++;
				}else{
					free(word);
				}
			}while(!feof(input));
			
			printf("Words: %d\n",c);
			
			/* First 6 elements */
			listNode = list->FrontPtr;
			for(i = 0;i < 6;i++){
				printf("%s\n", listNode->ElementPtr->word);
				listNode = listNode->Next;
			}
			
			/* Last 6 elements */
			listNode = list->BackPtr;
			for(i = 0;i < 6;i++){
				printf("%s\n", listNode->ElementPtr->word);
				listNode = listNode->Previous;
			}

			printf("\n-------------------------------------------------------------------\n");		
			searchWord = malloc(80);		
			printf("Please enter the word you would like to search for: ");
			scanf("%s",searchWord);
			
			searchIndex = searchList(list, searchWord);
			if(searchIndex < 0){
				printf("Your string was not found\n");
			}else{
				printf("The string: %s was found at index: %d\n",searchWord,searchIndex);
			}
						
			free(searchWord);			

		}else{
			printf("File: %s could not be opened\n",argv[1]);
			return 2;
		}
		fclose(input);
	}else{
		/* Usage message */
		printf("Usage: %s <input file>\n",argv[0]);
		return 1;
	}
	
	DestroyLinkedList(list);
	free(list);
	return 0;
}
Exemplo n.º 7
0
/*
	FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)

	PURPOSE: Windows procedure for the main window

	PARAMETERS:
		hWnd	- window handle
		message	- window message
		wParam	- window message parameter (depends on message)
		lParam	- window message parameter (depends on message)

	RETURN:
		If the message was processed, the return value is 0
		If the message was not processed and passed to DefWindowProc
		and the return value depends on the value of that function.

*/
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
	SCROLLINFO	si;

	switch (message) {
		case WM_CREATE: // case for when the window is created
			InitLinkedList();
			clpFormat = RegisterClipboardFormat(TEXT("DRAWING_OBJECT"));
			OpenChildWindows(hWnd);
			break;

		case WM_DESTROY: // case for when the window is closed
			PostQuitMessage(0);
			break;

		case WM_SETFOCUS: // case for when the window gains focus
			break;

		case WM_KILLFOCUS: // case for when the window focus is lost
			break;

		case WM_COMMAND: // case for menu commands
			MenuDispatch(LOWORD(wParam), hWnd, lParam);
			break;

		case WM_SIZE: // case for when the window is resized
			
			// Set vertical scrollbar range and page size
			si.cbSize	= sizeof(si);
			si.fMask	= SIF_RANGE | SIF_PAGE;
			si.nMin		= 0;
			si.nMax		= 1200;
			si.nPage	= Y_SIZE;
			SetScrollInfo(hWnd, SB_VERT, &si, TRUE);

			// Set horizontal scrollbar range and page size
			si.cbSize	= sizeof(si);
			si.fMask	= SIF_RANGE | SIF_PAGE;
			si.nMin		= 0;
			si.nMax		= 1600;
			si.nPage	= X_SIZE;
			SetScrollInfo(hWnd, SB_HORZ, &si, TRUE);
			break;

		case WM_VSCROLL: // when the vertical scrollbar is moved
			ScrollVert(ghWndCanvas, LOWORD(wParam), HIWORD(wParam));
			break;

		case WM_HSCROLL: // when the horizontal scrollbar is moved
			ScrollHorz(ghWndCanvas, LOWORD(wParam), HIWORD(wParam));
			break;

		case WM_PAINT:
			PaintWindow(hWnd);
			break;

		case WM_CLOSE:
			ClearLinkedList();
			DestroyWindow(hWnd);
			break;

		default:
			return (int)DefWindowProc(hWnd, message, wParam, lParam);
	}

	return 0;
}
Exemplo n.º 8
0
Arquivo: lists.c Projeto: askin/KLib
int main( void ) {
	LinkedList *ll;
	int e;

	aa *d;
	aa *f;
	aa *g;
	aa *d1;

	d = malloc(sizeof(aa));
	f = malloc(sizeof(aa));
	g = malloc(sizeof(aa));
	d->a = 8;
	f->a = 15;
	g->a = 9;

	ll = InitLinkedList(sizeof(aa));
	e = LinkedListIsEmpty(ll);
	printf("is empty? : %d\n",e);

	AddLinkedList(ll, d);
	printf("added\n");
	e = LinkedListIsEmpty(ll);
	printf("is empty? : %d\n",e);

	d1 = GetFirstLinkedList(ll);
	printf("First %d\n", d1->a);

	d1 = GetLastLinkedList(ll);
	printf("Last %d\n", d1->a);
	printf("----------------------\n");

	AddLinkedList(ll, f);
	e = LinkedListIsEmpty(ll);
	printf("is empty? : %d\n",e);

	d1 = GetFirstLinkedList(ll);
	printf("First %d\n", d1->a);

	d1 = GetLastLinkedList(ll);
	printf("Last %d\n", d1->a);

	printf("//////////////////////\n");

	AddFirstLinkedList(ll, g);
	e = LinkedListIsEmpty(ll);
	printf("is empty? : %d\n",e);

	d1 = GetFirstLinkedList(ll);
	printf("First %d\n", d1->a);

	d1 = GetLastLinkedList(ll);
	printf("Last %d\n", d1->a);

	RemoveFirstLinkedList(ll);
	printf("----------------------\n");
	printf("is empty? : %d\n",e);

	d1 = GetFirstLinkedList(ll);
	printf("First %d\n", d1->a);

	d1 = GetLastLinkedList(ll);
	printf("Last %d\n", d1->a);

	RemoveLastLinkedList(ll);
	printf("++++++++++++++++++++++\n");
	d1 = GetLastLinkedList(ll);
	printf("Last %d\n", d1->a);

	return 0;
}