/* This initializes DSUI itself. A call is made every time an application * tries to register its instrumentation points, from dsui_register_ip() */ static void dsui_init_check() { km_rdwr_wlock(&dsui_rwlock); if (!dsui_initialized) { int retval; global_buffer_pool = malloc(sizeof(struct dstrm_pool)); dstrm_pool_init(global_buffer_pool, 128, 32768); logging_threads = create_dictionary(); ip_names = create_dictionary(); dsui_initialized = 1; sigemptyset(&signals); sigaddset(&signals, SIGINT); retval = pthread_sigmask(SIG_BLOCK, &signals, NULL); if (retval) { kusp_errno("pthread_sigmask", retval); } retval = pthread_create(&sigint_thread, NULL, &sigint_thread_run, NULL); if (retval) { kusp_errno("pthread_create", retval); } //printf("Signal Thread ....%d\n",sigint_thread); __dsui_register_ip(&__datastream_ip_DSTREAM_ADMIN_FAMPRINTF); } km_rdwr_wunlock(&dsui_rwlock); }
int main(int argc, char* argv[]) { if(argc < 2) { printf("%s\n", "Invalid arguments: <filename>"); exit(1); } Boggle boggle; clock_t timer, stop_timer; vector<string> wordlist, found_list; timer = clock(); wordlist = create_dictionary(argv[1]); stop_timer = clock(); cout << "Execution Time for Dictionary Creation: " << (double)(stop_timer - timer)/(CLOCKS_PER_SEC)<< endl; timer = clock(); found_list = word_search(SIZE, SIZE, boggle.board, wordlist); stop_timer = clock(); cout << "Execution Time for Word Search Func: " << (double)(stop_timer - timer)/(CLOCKS_PER_SEC)<< endl; print_list(found_list); return 0; }
int main(int argc, char **argv) { if (argc != 3) { fprintf(stderr, "usage: %s [type] [input]\n", appname); fprintf(stderr, "type: specifies the dictionary type:\n"); fprintf(stderr, " h: height-balanced tree\n"); fprintf(stderr, " p: path-reduction tree\n"); fprintf(stderr, " r: red-black tree\n"); fprintf(stderr, " t: treap\n"); fprintf(stderr, " s: splay tree\n"); fprintf(stderr, " w: weight-balanced tree\n"); fprintf(stderr, " S: skiplist\n"); fprintf(stderr, " H: hashtable\n"); fprintf(stderr, " 2: hashtable 2\n"); fprintf(stderr, "input: text file consisting of newline-separated keys\n"); exit(EXIT_FAILURE); } srand(0xdeadbeef); dict_malloc_func = xmalloc; const char type = argv[1][0]; const char *container_name = NULL; dict *dct = create_dictionary(type, &container_name); if (!dct) quit("can't create container"); ASSERT(dict_verify(dct)); const size_t malloced_save = malloced; FILE *fp = fopen(argv[2], "r"); if (fp == NULL) quit("cant open file '%s': %s", argv[2], strerror(errno)); unsigned nwords = 0; char buf[512]; while (fgets(buf, sizeof(buf), fp)) ++nwords; if (!nwords) quit("nothing read from file"); char **words = xmalloc(sizeof(*words) * nwords); rewind(fp); for (unsigned i = 0; i < nwords && fgets(buf, sizeof(buf), fp); i++) { strtok(buf, "\n"); words[i] = xstrdup(buf); } fclose(fp); malloced = malloced_save; size_t total_comp = 0, total_hash = 0, total_rotations = 0; struct rusage start, end; struct timeval total = { 0, 0 }; timer_start(&start); for (unsigned i = 0; i < nwords; i++) { bool inserted = false; void **datum_location = dict_insert(dct, words[i], &inserted); if (!inserted) quit("insert #%d failed for '%s'", i, words[i]); ASSERT(datum_location != NULL); ASSERT(*datum_location == NULL); *datum_location = words[i]; } timer_end(&start, &end, &total); printf(" %s container: %.02fkB\n", container_name, malloced_save * 1e-3); printf(" %s memory: %.02fkB\n", container_name, malloced * 1e-3); printf(" %s insert: %6.03f s (%9zu cmp, %9zu hash)\n", container_name, (end.ru_utime.tv_sec * 1000000 + end.ru_utime.tv_usec) * 1e-6, comp_count, hash_count); total_comp += comp_count; comp_count = 0; total_hash += hash_count; hash_count = 0; if (type != 'H' && type != '2' && type != 'S') { tree_base *tree = dict_private(dct); printf("insert rotations: %zu\n", tree->rotation_count); total_rotations += tree->rotation_count; tree->rotation_count = 0; } ASSERT(dict_verify(dct)); unsigned n = dict_count(dct); if (n != nwords) quit("bad count (%u - should be %u)!", n, nwords); dict_itor *itor = dict_itor_new(dct); timer_start(&start); n = 0; ASSERT(dict_itor_first(itor)); do { ASSERT(dict_itor_valid(itor)); ASSERT(dict_itor_key(itor) == *dict_itor_data(itor)); ++n; } while (dict_itor_next(itor)); timer_end(&start, &end, &total); printf(" %s fwd iterate: %6.03f s\n", container_name, (end.ru_utime.tv_sec * 1000000 + end.ru_utime.tv_usec) * 1e-6); if (n != nwords) warn("Fwd iteration returned %u items - should be %u", n, nwords); timer_start(&start); n = 0; ASSERT(dict_itor_last(itor)); do { ASSERT(dict_itor_valid(itor)); ASSERT(dict_itor_key(itor) == *dict_itor_data(itor)); ++n; } while (dict_itor_prev(itor)); timer_end(&start, &end, &total); printf(" %s rev iterate: %6.03f s\n", container_name, (end.ru_utime.tv_sec * 1000000 + end.ru_utime.tv_usec) * 1e-6); if (n != nwords) warn("Rev iteration returned %u items - should be %u", n, nwords); dict_itor_free(itor); /* shuffle(words, nwords); */ timer_start(&start); for (unsigned i = 0; i < nwords; i++) { char *p = dict_search(dct, words[i]); if (!p) quit("lookup failed for '%s'", buf); if (p != words[i]) quit("bad data for '%s', got '%s' instead", words[i], p); } timer_end(&start, &end, &total); printf(" %s good search: %6.03f s (%9zu cmp, %9zu hash)\n", container_name, (end.ru_utime.tv_sec * 1000000 + end.ru_utime.tv_usec) * 1e-6, comp_count, hash_count); total_comp += comp_count; comp_count = 0; total_hash += hash_count; hash_count = 0; if (type != 'H' && type != '2' && type != 'S') { tree_base *tree = dict_private(dct); printf("search rotations: %zu\n", tree->rotation_count); total_rotations += tree->rotation_count; tree->rotation_count = 0; } timer_start(&start); for (unsigned i = 0; i < nwords; i++) { int rv = rand() % strlen(words[i]); words[i][rv]++; dict_search(dct, words[i]); words[i][rv]--; } timer_end(&start, &end, &total); printf(" %s bad search: %6.03f s (%9zu cmp, %9zu hash)\n", container_name, (end.ru_utime.tv_sec * 1000000 + end.ru_utime.tv_usec) * 1e-6, comp_count, hash_count); total_comp += comp_count; comp_count = 0; total_hash += hash_count; hash_count = 0; /* shuffle(words, nwords); */ timer_start(&start); for (unsigned i = 0; i < nwords; i++) { if (!dict_remove(dct, words[i])) quit("removing #%d '%s' failed!\n", i, words[i]); } timer_end(&start, &end, &total); printf(" %s remove: %6.03f s (%9zu cmp, %9zu hash)\n", container_name, (end.ru_utime.tv_sec * 1000000 + end.ru_utime.tv_usec) * 1e-6, comp_count, hash_count); total_comp += comp_count; comp_count = 0; total_hash += hash_count; hash_count = 0; if (type != 'H' && type != '2' && type != 'S') { tree_base *tree = dict_private(dct); printf("remove rotations: %zu\n", tree->rotation_count); total_rotations += tree->rotation_count; tree->rotation_count = 0; } ASSERT(dict_verify(dct)); if ((n = dict_count(dct)) != 0) quit("error - count not zero (%u)!", n); dict_free(dct); printf(" %s total: %6.03f s (%9zu cmp, %9zu hash)\n", container_name, (total.tv_sec * 1000000 + total.tv_usec) * 1e-6, total_comp, total_hash); if (type != 'H' && type != '2' && type != 'S') { printf(" total rotations: %zu\n", total_rotations); } FREE(words); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { bool shuffle_keys = true; if (argc != 3) { fprintf(stderr, "usage: %s [type] [input]\n", appname); fprintf(stderr, "type: specifies the dictionary type:\n"); fprintf(stderr, " h: height-balanced tree\n"); fprintf(stderr, " p: path-reduction tree\n"); fprintf(stderr, " r: red-black tree\n"); fprintf(stderr, " t: treap\n"); fprintf(stderr, " s: splay tree\n"); fprintf(stderr, " w: weight-balanced tree\n"); fprintf(stderr, " S: skiplist\n"); fprintf(stderr, " H: hashtable\n"); fprintf(stderr, " 2: hashtable 2\n"); fprintf(stderr, "input: text file consisting of newline-separated keys\n"); exit(EXIT_FAILURE); } srand(0xdeadbeef); dict_malloc_func = xmalloc; const char type = argv[1][0]; const char *container_name = NULL; dict *dct = create_dictionary(type, &container_name); if (!dct) quit("can't create container"); ASSERT(dict_verify(dct)); ASSERT(comp_count == 0); ASSERT(hash_count == 0); const size_t malloced_save = malloced; FILE *fp = fopen(argv[2], "r"); if (fp == NULL) quit("cant open file '%s': %s", argv[2], strerror(errno)); size_t nwords = 0; char buf[512]; while (fgets(buf, sizeof(buf), fp)) ++nwords; if (!nwords) quit("nothing read from file"); char **words = xmalloc(sizeof(*words) * nwords); rewind(fp); size_t words_read = 0; while (words_read < nwords && fgets(buf, sizeof(buf), fp)) { strtok(buf, "\n"); words[words_read++] = xstrdup(buf); } fclose(fp); if (words_read < nwords) quit("Only read %zu/%zu words!", words_read, nwords); printf("Loaded %zu keys from %s.\n", nwords, argv[2]); malloced = malloced_save; size_t total_comp = 0, total_hash = 0, total_rotations = 0; struct rusage start, end; struct timeval total = { 0, 0 }; timer_start(&start); for (unsigned i = 0; i < nwords; i++) { dict_insert_result result = dict_insert(dct, words[i]); if (!result.inserted) quit("insert #%d failed for '%s'", i, words[i]); ASSERT(result.datum_ptr != NULL); ASSERT(*result.datum_ptr == NULL); *result.datum_ptr = words[i]; } timer_end(&start, &end, &total); printf(" %s container: %.02fkB\n", container_name, malloced_save * 1e-3); printf(" %s memory: %.02fkB\n", container_name, malloced * 1e-3); printf(" %s insert: %6.03fs %9zu cmp (%.02f/insert)", container_name, (end.ru_utime.tv_sec * 1000000 + end.ru_utime.tv_usec) * 1e-6, comp_count, comp_count / (double) nwords); if (hash_count) printf(" %9zu hash", hash_count); printf("\n"); total_comp += comp_count; comp_count = 0; total_hash += hash_count; hash_count = 0; if (dict_is_sorted(dct) && type != 'S') { tree_base *tree = dict_private(dct); printf(" min path length: %zu\n", tree_min_path_length(tree)); printf(" max path length: %zu\n", tree_max_path_length(tree)); printf(" tot path length: %zu\n", tree_total_path_length(tree)); printf("insert rotations: %zu\n", tree->rotation_count); total_rotations += tree->rotation_count; tree->rotation_count = 0; } else if (type == 'S') { size_t counts[16] = { 0 }; size_t num_counts = skiplist_link_count_histogram(dict_private(dct), counts, sizeof(counts) / sizeof(counts[0])); size_t count_sum = 0; for (size_t i = 0; i <= num_counts; ++i) { printf("skiplist %zu-node(s): %zu\n", i, counts[i]); count_sum += counts[i]; } ASSERT(count_sum == nwords); } ASSERT(dict_verify(dct)); comp_count = hash_count = 0; /* Ignore comparisons/hashes incurred by dict_verify() */ size_t n = dict_count(dct); if (n != nwords) quit("bad count (%u - should be %u)!", n, nwords); dict_itor *itor = dict_itor_new(dct); timer_start(&start); n = 0; ASSERT(dict_itor_first(itor)); do { ASSERT(dict_itor_valid(itor)); ASSERT(dict_itor_key(itor) == *dict_itor_datum(itor)); ++n; } while (dict_itor_next(itor)); timer_end(&start, &end, &total); printf(" %s fwd iterate: %6.03fs\n", container_name, (end.ru_utime.tv_sec * 1000000 + end.ru_utime.tv_usec) * 1e-6); if (n != nwords) warn("Fwd iteration returned %u items - should be %u", n, nwords); ASSERT(dict_verify(dct)); comp_count = hash_count = 0; /* Ignore comparisons/hashes incurred by dict_verify() */ timer_start(&start); n = 0; ASSERT(dict_itor_last(itor)); do { ASSERT(dict_itor_valid(itor)); ASSERT(dict_itor_key(itor) == *dict_itor_datum(itor)); ++n; } while (dict_itor_prev(itor)); timer_end(&start, &end, &total); printf(" %s rev iterate: %6.03fs\n", container_name, (end.ru_utime.tv_sec * 1000000 + end.ru_utime.tv_usec) * 1e-6); if (n != nwords) warn("Rev iteration returned %u items - should be %u", n, nwords); dict_itor_free(itor); if (shuffle_keys) shuffle(words, nwords); ASSERT(dict_verify(dct)); comp_count = hash_count = 0; /* Ignore comparisons/hashes incurred by dict_verify() */ timer_start(&start); for (unsigned i = 0; i < nwords; i++) { void **p = dict_search(dct, words[i]); if (!p) quit("lookup failed for '%s'", buf); if (*p != words[i]) quit("bad data for '%s', got '%s' instead", words[i], *(char **)p); } timer_end(&start, &end, &total); printf(" %s good search: %6.03fs %9zu cmp (%.02f/search)", container_name, (end.ru_utime.tv_sec * 1000000 + end.ru_utime.tv_usec) * 1e-6, comp_count, comp_count / (double) nwords); if (hash_count) printf(" %9zu hash", hash_count); printf("\n"); total_comp += comp_count; comp_count = 0; total_hash += hash_count; hash_count = 0; if (type != 'H' && type != '2' && type != 'S') { tree_base *tree = dict_private(dct); printf("search rotations: %zu\n", tree->rotation_count); total_rotations += tree->rotation_count; tree->rotation_count = 0; } ASSERT(dict_verify(dct)); comp_count = hash_count = 0; /* Ignore comparisons/hashes incurred by dict_verify() */ timer_start(&start); for (unsigned i = 0; i < nwords; i++) { unsigned rv = dict_rand() % strlen(words[i]); words[i][rv]++; dict_search(dct, words[i]); words[i][rv]--; } timer_end(&start, &end, &total); printf(" %s bad search: %6.03fs %9zu cmp (%.02f/search)", container_name, (end.ru_utime.tv_sec * 1000000 + end.ru_utime.tv_usec) * 1e-6, comp_count, comp_count / (double) nwords); if (hash_count) printf(" %9zu hash", hash_count); printf("\n"); total_comp += comp_count; comp_count = 0; total_hash += hash_count; hash_count = 0; ASSERT(dict_verify(dct)); comp_count = hash_count = 0; /* Ignore comparisons/hashes incurred by dict_verify() */ if (shuffle_keys) shuffle(words, nwords); timer_start(&start); for (unsigned i = 0; i < nwords; i++) { dict_remove_result result = dict_remove(dct, words[i]); if (!result.removed) quit("removing #%d '%s' failed!\n", i, words[i]); ASSERT(result.key == words[i]); ASSERT(result.datum == words[i]); } timer_end(&start, &end, &total); printf(" %s remove: %6.03fs %9zu cmp (%.2f/remove)", container_name, (end.ru_utime.tv_sec * 1000000 + end.ru_utime.tv_usec) * 1e-6, comp_count, comp_count / (double)nwords); if (hash_count) printf(" %9zu hash", hash_count); printf("\n"); total_comp += comp_count; comp_count = 0; total_hash += hash_count; hash_count = 0; if (type != 'H' && type != '2' && type != 'S') { tree_base *tree = dict_private(dct); printf("remove rotations: %zu\n", tree->rotation_count); total_rotations += tree->rotation_count; tree->rotation_count = 0; } ASSERT(dict_verify(dct)); comp_count = hash_count = 0; /* Ignore comparisons/hashes incurred by dict_verify() */ if ((n = dict_count(dct)) != 0) quit("error - count not zero (%u)!", n); dict_free(dct, key_str_free); printf(" %s total: %6.03fs %9zu cmp", container_name, (total.tv_sec * 1000000 + total.tv_usec) * 1e-6, total_comp); if (total_hash) printf(" %9zu hash", total_hash); printf("\n"); if (type != 'H' && type != '2' && type != 'S') { printf(" total rotations: %zu\n", total_rotations); } FREE(words); exit(EXIT_SUCCESS); }