Beispiel #1
0
void delete_test() {
	double start_time, end_time;
	int built = false;

	Read_Buffer(input_file);
	// B+tree initialize
	BPlusTree_Init();
	// MaxChildNumber				
	printf("input depth: ");
	int depth;
	scanf("%d", &depth);
	int maxCh = 2;
	while (1) {
		int leaves = 1, i;
		for (i = 0; i < depth; i++) {
			leaves *= maxCh;
			if (leaves > TotalRecords) break;
		}
		if (leaves > TotalRecords) break;
		maxCh++;
	}
	printf("Desired depth = %d, calculated maxChildNumber = %d\n", depth, maxCh);
	BPlusTree_SetMaxChildNumber(maxCh);
	// build
	built = true;
	start_time = clock();
	Read_Data_And_Insert();
	end_time = clock();
	printf("Valid Records inserted on B+tree = %d\n", validRecords);
	printf("Total number of B+tree nodes = %d\n", BPlusTree_GetTotalNodes());
	printf("Build B+tree costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
	// delete
	start_time = clock();
	int key, i;
	srand((unsigned)time(NULL));
	int del_num = 10;
	for (i = 0; i < del_num; i++) {
		key = keys[rand() % key_num];
		int pos = BPlusTree_Find(key);
		if (pos != -1) { // found
			File_Delete(pos);
			BPlusTree_Delete(key);
			//printf("Delete success.\n");
		} else {
			//printf("Delete failed, do not have the given key on B+tree.\n");
		}
	}
	end_time = clock();
	printf("delete %d elements, average cost is %lf s\n", del_num, (end_time - start_time) / CLOCKS_PER_SEC / del_num); 
	BPlusTree_Destroy();
}
/**
 * Handles Click event for "Clear List" button.
 *
 * @param w The widget.
 * @return True, always.
 */
bool GUI_Widget_HOF_ClearList_Click(Widget *w)
{
	/* "Are you sure you want to clear the high scores?" */
	if (GUI_YesNo(0x148)) {
		HallOfFameStruct *data = w->data;

		memset(data, 0, 128);

#ifdef __arm__
		if (File_Exists("SAVEFAME_ARM.DAT")) File_Delete("SAVEFAME_ARM.DAT");
#else
		if (File_Exists("SAVEFAME.DAT")) File_Delete("SAVEFAME.DAT");
#endif

		GUI_HallOfFame_DrawData(data, true);

		g_var_81E6 = true;
	}

	GUI_Widget_MakeNormal(w, false);

	return true;
}
Beispiel #3
0
void Mouse_SetMouseMode(uint8 mouseMode, const char *filename)
{
	switch (mouseMode) {
		default: break;

		case INPUT_MOUSE_MODE_NORMAL:
			g_mouseMode = mouseMode;
			if (g_mouseFileID != 0xFF) {
				Input_Flags_ClearBits(INPUT_FLAG_KEY_RELEASE);
				File_Close(g_mouseFileID);
			}
			g_mouseFileID = 0xFF;
			g_var_701B = true;
			break;

		case INPUT_MOUSE_MODE_RECORD:
			if (g_mouseFileID != 0xFF) break;

			File_Delete(filename);
			File_Create(filename);

			Tools_RandomLCG_Seed(0x21433412);

			g_mouseFileID = File_Open(filename, 3);

			g_mouseMode = mouseMode;

			Input_Flags_SetBits(INPUT_FLAG_KEY_RELEASE);

			Input_HandleInput(0x2D);
			break;

		case INPUT_MOUSE_MODE_PLAY:
			if (g_mouseFileID == 0xFF) {
				g_mouseFileID = File_Open(filename, 1);

				Tools_RandomLCG_Seed(0x21433412);
			}

			g_var_701B = true;

			File_Read(g_mouseFileID, &g_var_7013, 2);
			if (File_Read(g_mouseFileID, &g_var_7015, 2) != 2) break;;

			if ((g_var_7013 >= 0x41 && g_var_7013 <= 0x44) || g_var_7013 == 0x2D) {
				File_Read(g_mouseFileID, &g_var_7017, 2);
				if (File_Read(g_mouseFileID, &g_var_7019, 2) == 2) {
					g_mouseX = g_var_7017;
					g_mouseY = g_var_7019;
					g_prevButtonState = 0;

					GUI_Mouse_Hide_Safe();
					GUI_Mouse_Show_Safe();

					g_var_701B = false;
					break;
				}
				g_var_701B = true;
				break;
			}
			g_var_701B = false;
			break;
	}

	g_timerInput = 0;
	g_mouseMode = mouseMode;
}
Beispiel #4
0
void MainLoop() {
	double start_time, end_time;
	int built = false;

	// Read data to buffer
	Read_Buffer(input_file);
	// B+tree initialize
	BPlusTree_Init();
	while (1) {
		ShowHelp();
		int request;
		scanf("%d", &request);
		switch (request) {
			case 0: {
				// Read data to buffer
				if (buffer != NULL) free(buffer);
				Read_Buffer(input_file);
				// B+tree initialize
				BPlusTree_Init();
				// args
				built = false;
				validRecords = 0;
				break;
			}
			case 1: {
				// Set Depth
				printf("input depth: ");
				int depth;
				scanf("%d", &depth);
				int maxCh = 2;
				while (1) {
					int leaves = 1, i;
					for (i = 0; i < depth; i++) {
						leaves *= maxCh;
						if (leaves > TotalRecords) break;
					}
					if (leaves > TotalRecords) break;
					maxCh++;
				}
				printf("Desired depth = %d, calculated maxChildNumber = %d\n", depth, maxCh);
				BPlusTree_SetMaxChildNumber(maxCh);
				break;
			}
			case 2: {
				// Set MaxChildNumber
				printf("input MaxChildNumber: ");
				int maxCh;
				scanf("%d", &maxCh);
				BPlusTree_SetMaxChildNumber(maxCh);
				break;
			}
			case 3: {
				// Build B+tree
				if (built == true) {
					printf("You have built the B+tree\n");
					break;
				}
				built = true;
				start_time = clock();
				Read_Data_And_Insert();
				end_time = clock();
				printf("Valid Records inserted on B+tree = %d\n", validRecords);
				printf("Total number of B+tree nodes = %d\n", BPlusTree_GetTotalNodes());
				printf("Build B+tree costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
				break;
			}
			case 4: {
				// Query on a key
				printf("input the key: ");
				int key;
				scanf("%d", &key);
				start_time = clock();
				BPlusTree_Query_Key(key);
				end_time = clock();
				printf("Query on a key, costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
				break;
			}
			case 5: {
				// Query on a range [l, r]
				printf("input range [l, r]: ");
				int l, r;
				scanf("%d %d", &l, &r);
				if (l > r) {
					printf("input illegal\n");
					break;
				}
				start_time = clock();
				BPlusTree_Query_Range(l, r);
				end_time = clock();
				printf("Query on a range, costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
				break;
			}
			case 6: {
				// Modify value on a key
				printf("input (key, value): ");
				scanf("%d %s", &new_key, new_st);
				char* value = (char*)malloc(sizeof(char) * strlen(new_st));
				strcpy(value, new_st);
				start_time = clock();
				int pos = BPlusTree_Find(new_key);
				if (pos != -1) { // found
					if (File_Modify(pos, new_key, new_st)) { // file modify success
						BPlusTree_Modify(new_key, value);
						printf("Modify success.\n");
					} else {
						printf("Modify failed, the new value is too long to store in file\n");
					}
				} else {
					printf("Modify failed, do not have the given key on B+tree.\n");
				}
				end_time = clock();
				printf("Modify value on a key, costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
				break;
			}
			case 7: {
				// Delete value on a key
				printf("input key: ");
				int key;
				scanf("%d", &key);
				start_time = clock();
				int pos = BPlusTree_Find(key);
				if (pos != -1) { // found
					File_Delete(pos);
					BPlusTree_Delete(key);
					printf("Delete success.\n");
				} else {
					printf("Delete failed, do not have the given key on B+tree.\n");
				}
				end_time = clock();
				printf("Delete value on a key, costs %lf s\n", (end_time - start_time) / CLOCKS_PER_SEC);
				break;
			}
			case 8: {
				printf("input (key, value): ");
				scanf("%d %s", &new_key, new_st);
				char* value = (char*)malloc(sizeof(char) * new_len);
				strcpy(value, new_st);

				int pos = BPlusTree_Find(new_key);
				if (pos == -1) {
					new_pos = File_Insert(new_key, new_st);
					keys[key_num++] = new_key;
					BPlusTree_Insert(new_key, new_pos, value);
					validRecords++;
					printf("Insert success.\n");
				} else {
					printf("Insert failed, the key already exist.\n");
				}
				break;
			}
			case 9: return;
			default: break;
		}
	}
	BPlusTree_Destroy();
}