1*46173Sbostic /*-
2*46173Sbostic  * Copyright (c) 1990 The Regents of the University of California.
3*46173Sbostic  * All rights reserved.
4*46173Sbostic  *
5*46173Sbostic  * This code is derived from software contributed to Berkeley by
6*46173Sbostic  * Margo Seltzer.
7*46173Sbostic  *
8*46173Sbostic  * %sccs.include.redist.c%
9*46173Sbostic  */
10*46173Sbostic 
11*46173Sbostic #ifndef lint
12*46173Sbostic char copyright[] =
13*46173Sbostic "@(#) Copyright (c) 1990 The Regents of the University of California.\n\
14*46173Sbostic  All rights reserved.\n";
15*46173Sbostic #endif /* not lint */
16*46173Sbostic 
17*46173Sbostic #ifndef lint
18*46173Sbostic static char sccsid[] = "@(#)tcreat3.c	5.1 (Berkeley) 01/31/91";
19*46173Sbostic #endif /* not lint */
20*46173Sbostic 
21*46173Sbostic #include <sys/types.h>
22*46173Sbostic #include <stdio.h>
23*46173Sbostic #include <sys/file.h>
24*46173Sbostic #include <db.h>
25*46173Sbostic 
26*46173Sbostic #define INITIAL	25000
27*46173Sbostic #define MAXWORDS    25000	       /* # of elements in search table */
28*46173Sbostic 
29*46173Sbostic char	wp1[8192];
30*46173Sbostic char	wp2[8192];
31*46173Sbostic main(argc, argv)
32*46173Sbostic char **argv;
33*46173Sbostic {
34*46173Sbostic 	DBT item, key;
35*46173Sbostic 	DB	*dbp;
36*46173Sbostic 	HASHINFO ctl;
37*46173Sbostic 	FILE *fp;
38*46173Sbostic 	int	trash;
39*46173Sbostic 
40*46173Sbostic 	int i = 0;
41*46173Sbostic 
42*46173Sbostic 	argv++;
43*46173Sbostic 	ctl.hash = NULL;
44*46173Sbostic 	ctl.bsize = atoi(*argv++);
45*46173Sbostic 	ctl.ffactor = atoi(*argv++);
46*46173Sbostic 	ctl.nelem = atoi(*argv++);
47*46173Sbostic 	ctl.lorder = 0;
48*46173Sbostic 	if (!(dbp = hash_open( "hashtest", O_CREAT|O_TRUNC|O_RDWR, 0600, &ctl))){
49*46173Sbostic 		/* create table */
50*46173Sbostic 		fprintf(stderr, "cannot create: hash table (size %d)\n",
51*46173Sbostic 			INITIAL);
52*46173Sbostic 		exit(1);
53*46173Sbostic 	}
54*46173Sbostic 
55*46173Sbostic 	key.data = wp1;
56*46173Sbostic 	item.data = wp2;
57*46173Sbostic 	while ( fgets(wp1, 8192, stdin) &&
58*46173Sbostic 		fgets(wp2, 8192, stdin) &&
59*46173Sbostic 		i++ < MAXWORDS) {
60*46173Sbostic /*
61*46173Sbostic * put info in structure, and structure in the item
62*46173Sbostic */
63*46173Sbostic 		key.size = strlen(wp1);
64*46173Sbostic 		item.size = strlen(wp2);
65*46173Sbostic 
66*46173Sbostic /*
67*46173Sbostic  * enter key/data pair into the table
68*46173Sbostic  */
69*46173Sbostic 		if ((dbp->put)(dbp, &key, &item, R_NOOVERWRITE) != NULL) {
70*46173Sbostic 			fprintf(stderr, "cannot enter: key %s\n",
71*46173Sbostic 				item.data);
72*46173Sbostic 			exit(1);
73*46173Sbostic 		}
74*46173Sbostic 	}
75*46173Sbostic 
76*46173Sbostic 	(dbp->close)(dbp);
77*46173Sbostic 	exit(0);
78*46173Sbostic }
79