void test_kdTree_rbal(kdTree * tree, int show) { pTimer tmr; ptimer_init(&tmr, CLOCK_PROCESS_CPUTIME_ID); ptimer_tic(&tmr); kdTree_rbal(tree); ptimer_toc(&tmr); printf("- Balance: "); ptimer_print_sec_usec9(tmr); printf("[s]"); if (show_bars) { int x = (int)rint(ptimer_get_sec(&tmr) * fac); mputchar(stdout, x, '#'); } endline(); }
void test_kdTree_find_shape(kdTree * tree, vis_t ** grid, size_t m, size_t n, int show) { size_t k; pTimer tmr; ptimer_init(&tmr, CLOCK_PROCESS_CPUTIME_ID); ptimer_tic(&tmr); kdTree_reset_fbs(tree); size_t hitnum = 0; for (k = 0; k < m * n; k++) { const vis_t * elm = grid[k]; if (show) { printf("finding "); vis_fprint(stdout, elm); printf(" nr:%zd/%zd...", k, m * n); } int hit = kdTree_find_shape(tree, elm); if (hit) { hitnum++; } if (show) { printf("%s", hit ? "HIT: " : "MISS"); endline(); } } ptimer_toc(&tmr); printf("- Find: "); ptimer_print_sec_usec9(tmr); printf("[s]"); printf(" (%zd) %s ", hitnum, (hitnum == m * n) ? "SUCCESS" : "FAILURE"); if (show_bars) { int x = (int)rint(ptimer_get_sec(&tmr) * fac); mputchar(stdout, x, '#'); } endline(); }
void test_kdTree_ins_shape(kdTree * tree, vis_t ** grid, size_t m, size_t n, int show) { size_t k; pTimer tmr; ptimer_init(&tmr, CLOCK_PROCESS_CPUTIME_ID); ptimer_tic(&tmr); for (k = 0; k < m * n; k++) { vis_t * elm = grid[k]; if (show) { printf("inserting "); vis_fprint(stdout, elm); printf(" nr:%zd/%zd...", k, m * n); } kdTree_ins_shape(tree, elm); if (show) { kdTree_fprint(stdout, tree, TRUE); putsep(stdout); } if (show) { endline(); } } ptimer_toc(&tmr); printf("- Insertion: "); ptimer_print_sec_usec9(tmr); printf("[s]"); if (show_bars) { int x = (int)rint(ptimer_get_sec(&tmr) * fac); putchar(' '); mputchar(stdout, x, '#'); } endline(); }
void test_kdTree_rm_shape(kdTree * tree, vis_t ** grid, size_t m, size_t n, int show) { pTimer tmr; ptimer_init(&tmr, CLOCK_PROCESS_CPUTIME_ID); ptimer_tic(&tmr); size_t k, rmnum = 0; for (k = 0; k < m * n; k++) { vis_t * elm = grid[k]; if (show) { printf("removing "); vis_fprint(stdout, elm); printf(" nr:%zd/%zd...", k, m * n); } uint ok = kdTree_rm_shape(tree, elm); if (ok) { rmnum++; } if (show) { printf("%s\n", ok ? "HIT" : "MISS"); } } ptimer_toc(&tmr); printf("- Remove: "); ptimer_print_sec_usec9(tmr); printf("[s]"); printf(" (%zd) %s ", rmnum, (rmnum == m * n) ? "SUCCESS" : "FAILURE"); if (show_bars) { int x = (int)rint(ptimer_get_sec(&tmr) * fac); mputchar(stdout, x, '#'); } endline(); }
void pollInput() { if (mchready()) { char ch = mgetch(); if (ch == '\r') { mputs(NL); *inputBufferEnd = 0; handleInputLine(); resetInputBuffer(); } else { *inputBufferEnd = ch; inputBufferEnd++; mputchar(ch); if (inputBufferEnd == inputBuffer + INPUT_BUFFER_SIZE -1) { mprintf(PSTR("ERROR: linebuffer overflow\n")); resetInputBuffer(); } } } }
void execute(int x) { int op = disk[x]; char *s; switch (op) { case DOCOL: w = ++IP; RPUSH ++IP; IP = disk[w]; break; case KEY: PUSH getchar(); NEXT; break; case WORD: w = *dict; enter(0); int slen = scant((char) TOS, (char *)(disk + (*dict))); DROP; disk[w] = slen; PUSH w; *dict += slen/PACK + 1; NEXT; break; case FIND: w = *link; while (!(streql(disk+TOS, (disk+w+1))) && w) { w = disk[w]; } if (!w) { PUSH 1; } else { TOS = w + 2 + ((disk[w+1])/PACK + 2); w = disk[TOS-1]; PUSH w; } NEXT; break; case EXIT: RDROP; NEXT; break; case PEEK: TOS = disk[TOS]; NEXT; break; case POKE: disk[TOS] = NTOS; DROP; DROP; NEXT; break; case LIT: PUSH disk[TORS++]; NEXT; break; case PUSNXT: PUSH disk[NTORS++]; NEXT; break; case BRANCH: TORS += disk[TORS] + 1; //was off by one NEXT; break; case PDROP: DROP; NEXT; break; case TOR: w = TORS; TORS = TOS; RPUSH w; DROP; NEXT; break; case FROMR: PUSH NTORS; w = TORS; RDROP; TORS = w; NEXT; break; case DUP: w = TOS; PUSH w; NEXT; break; case SWAP: w = TOS; TOS = NTOS; NTOS = w; NEXT; break; case ROT: w = TOS; TOS = disk[(*tosp)+2]; disk[(*tosp)+2] = NTOS; NTOS = w; NEXT; break; case PLUS: TWOLEVEL(TOS + NTOS); break; case MINUS: TWOLEVEL(NTOS - TOS); break; case MULT: TWOLEVEL(TOS * NTOS); break; case DIV: TWOLEVEL(NTOS / TOS); break; case RSHIFT: NTOS >>= TOS; DROP; NEXT; break; case LSHIFT: NTOS <<= TOS; DROP; NEXT; break; case LESS: TWOLEVEL(NTOS < TOS ? -1 : 0); break; case GREAT: TWOLEVEL(NTOS > TOS ? -1 : 0); break; case EQL: NTOS = NTOS == TOS ? -1 : 0; DROP; NEXT; break; case EMIT: mputchar(TOS); DROP; NEXT; break; case PUTS: putnumstr(disk+TOS); DROP; NEXT; break; case ATOI: w = TOS+1; TOS = (int) strtol((char *)(disk+w),&s, 10); if(s == (char *)(disk+w)){ DROP; mputs("NO NUMBER FOUND: "); putnumstr(disk+w-1); puts(""); } NEXT; break; case PNUM: puts(itoa(TOS)); DROP; NEXT; break; case AND: NTOS &= TOS; DROP; NEXT; break; case OR: NTOS |= TOS; DROP; NEXT; break; case XOR: NTOS ^= TOS; DROP; NEXT; break; case NOT: TOS = ~TOS; NEXT; break; default: //this should be unreachable mputs("execute fallthrough: "); puts(itoa(op)); dumpstack(3,tosp); dumpstack(5,rsp); dumpstack(15, disk+(*link)); mputs("IP = "); puts(itoa(IP)); stat(); *rsp = DSIZE-(RSSIZE+STSIZE+1); IP = cs; } }
void mputs(char *c) { while (*c) { mputchar(*(c++)); } }