void hsh_reorganize( hshtblptr master ) { void* *newtbl = NULL; void* *oldtbl; unsigned long newsize, oldsize; unsigned long oldentries, j; unsigned int i; oldsize = master->currentsz; oldtbl = master->htbl; oldentries = 0; if (master->hstatus.hdeleted > (master->hstatus.hentries / 4)) newsize = oldsize; else { newsize = ithprime(0); for (i = 1; newsize <= oldsize; i+=1) newsize = ithprime(i); } newtbl = maketbl(newsize); master->currentsz = newsize; master->htbl = newtbl; unsigned long hi; void *ho; int_pointer_t hsh_key; for (j = 0; j < oldsize; j++) if (oldtbl[j] && (oldtbl[j] != _DELETED)) { hsh_key = _hget_key( oldtbl[j] ); hsh_lookup( master, hsh_key, hi, ho, _hget_key); tm_assert( ho == NULL ); master->htbl[ hi ] = oldtbl[j]; oldentries++; } /* Sanity check */ tm_assert( oldentries == master->hstatus.hentries - master->hstatus.hdeleted ); master->htbl_end = master->htbl + master->currentsz; master->last_found_key = 0; master->hstatus.hentries = oldentries; master->hstatus.hdeleted = 0; free(oldtbl); }
/* initialize and return a pointer to the data base */ void hsh_init( struct hshtag *master ) { #define INITSZ 17 /* small prime, for easy testing */ if( master ) { master->htbl = maketbl(INITSZ); master->currentsz = INITSZ; master->htbl_end = master->htbl + master->currentsz; seqbuff_init( &master->seqb ); master->bloom_filter = 0; master->last_found_key = 0; master->hstatus.hentries = 0; master->hstatus.hdeleted = 0; master->hstatus.herror = hshOK; } return; } /* hshinit */
int main(int argc, char *argv[]) { struct winsize win; FILE *fp; int ch, tflag, xflag; char *p; const char *errstr; if (ioctl(1, TIOCGWINSZ, &win) == -1 || !win.ws_col) { if ((p = getenv("COLUMNS")) && *p != '\0') { termwidth = strtonum(p, 1, INT_MAX, &errstr); if (errstr != NULL) errx(1, "%s: %s", errstr, p); } } else termwidth = win.ws_col; if (pledge("stdio rpath", NULL) == -1) err(1, "pledge"); tflag = xflag = 0; while ((ch = getopt(argc, argv, "c:s:tx")) != -1) switch(ch) { case 'c': termwidth = strtonum(optarg, 1, INT_MAX, &errstr); if (errstr != NULL) errx(1, "%s: %s", errstr, optarg); break; case 's': separator = optarg; break; case 't': tflag = 1; break; case 'x': xflag = 1; break; case '?': default: usage(); } argc -= optind; argv += optind; if (!*argv) { input(stdin); } else { for (; *argv; ++argv) { if ((fp = fopen(*argv, "r"))) { input(fp); (void)fclose(fp); } else { warn("%s", *argv); eval = 1; } } } if (pledge("stdio", NULL) == -1) err(1, "pledge"); if (!entries) exit(eval); if (tflag) maketbl(); else if (maxlength >= termwidth) print(); else if (xflag) c_columnate(); else r_columnate(); exit(eval); }
int main(int argc, char **argv) { struct winsize win; FILE *fp; int ch, tflag, xflag; char *p; const char *src; wchar_t *newsep; size_t seplen; setlocale(LC_ALL, ""); if (ioctl(1, TIOCGWINSZ, &win) == -1 || !win.ws_col) { if ((p = getenv("COLUMNS"))) termwidth = atoi(p); } else termwidth = win.ws_col; tflag = xflag = 0; while ((ch = getopt(argc, argv, "c:s:tx")) != -1) switch(ch) { case 'c': termwidth = atoi(optarg); break; case 's': src = optarg; seplen = mbsrtowcs(NULL, &src, 0, NULL); if (seplen == (size_t)-1) err(1, "bad separator"); newsep = malloc((seplen + 1) * sizeof(wchar_t)); if (newsep == NULL) err(1, NULL); mbsrtowcs(newsep, &src, seplen + 1, NULL); separator = newsep; break; case 't': tflag = 1; break; case 'x': xflag = 1; break; case '?': default: usage(); } argc -= optind; argv += optind; if (!*argv) input(stdin); else for (; *argv; ++argv) if ((fp = fopen(*argv, "r"))) { input(fp); (void)fclose(fp); } else { warn("%s", *argv); eval = 1; } if (!entries) exit(eval); maxlength = roundup(maxlength + 1, TAB); if (tflag) maketbl(); else if (maxlength >= termwidth) print(); else if (xflag) c_columnate(); else r_columnate(); exit(eval); }