xref: /csrg-svn/lib/libc/db/test/hash.tests/tdel.c (revision 61214)
146174Sbostic /*-
2*61214Sbostic  * Copyright (c) 1991, 1993
3*61214Sbostic  *	The Regents of the University of California.  All rights reserved.
446174Sbostic  *
546174Sbostic  * This code is derived from software contributed to Berkeley by
646174Sbostic  * Margo Seltzer.
746174Sbostic  *
850986Sbostic  * %sccs.include.redist.c%
946174Sbostic  */
1046174Sbostic 
1146174Sbostic #ifndef lint
12*61214Sbostic static char copyright[] =
13*61214Sbostic "@(#) Copyright (c) 1991, 1993\n\
14*61214Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1546174Sbostic #endif /* not lint */
1646174Sbostic 
1746174Sbostic #ifndef lint
18*61214Sbostic static char sccsid[] = "@(#)tdel.c	8.1 (Berkeley) 06/04/93";
1946174Sbostic #endif /* not lint */
2046174Sbostic 
2146174Sbostic #include <sys/types.h>
2246174Sbostic #include <sys/file.h>
2346174Sbostic #include <db.h>
2446174Sbostic #include <stdio.h>
2546174Sbostic 
2646174Sbostic #define INITIAL	25000
2746174Sbostic #define MAXWORDS    25000	       /* # of elements in search table */
2846174Sbostic 
2946174Sbostic /* Usage: thash pagesize fillfactor file */
3046174Sbostic char	wp1[8192];
3146174Sbostic char	wp2[8192];
main(argc,argv)3246174Sbostic main(argc, argv)
3346174Sbostic char **argv;
3446174Sbostic {
3546174Sbostic 	DBT item, key;
3646174Sbostic 	DB	*dbp;
3746174Sbostic 	HASHINFO ctl;
3846174Sbostic 	FILE *fp;
3946174Sbostic 	int	stat;
4046174Sbostic 
4146174Sbostic 	int i = 0;
4246174Sbostic 
4346174Sbostic 	argv++;
4446174Sbostic 	ctl.nelem = INITIAL;
4546174Sbostic 	ctl.hash = NULL;
4646174Sbostic 	ctl.bsize = atoi(*argv++);
4746174Sbostic 	ctl.ffactor = atoi(*argv++);
4847252Sbostic 	ctl.cachesize = 1024 * 1024;	/* 1 MEG */
4946174Sbostic 	ctl.lorder = 0;
5046174Sbostic 	argc -= 2;
5151077Sbostic 	if (!(dbp = dbopen( NULL, O_CREAT|O_RDWR, 0400, DB_HASH, &ctl))) {
5246174Sbostic 		/* create table */
5346174Sbostic 		fprintf(stderr, "cannot create: hash table size %d)\n",
5446174Sbostic 			INITIAL);
5546174Sbostic 		exit(1);
5646174Sbostic 	}
5746174Sbostic 
5846174Sbostic 	key.data = wp1;
5946174Sbostic 	item.data = wp2;
6046174Sbostic 	while ( fgets(wp1, 8192, stdin) &&
6146174Sbostic 		fgets(wp2, 8192, stdin) &&
6246174Sbostic 		i++ < MAXWORDS) {
6346174Sbostic /*
6446174Sbostic * put info in structure, and structure in the item
6546174Sbostic */
6646174Sbostic 		key.size = strlen(wp1);
6746174Sbostic 		item.size = strlen(wp2);
6846174Sbostic 
6946174Sbostic /*
7046174Sbostic  * enter key/data pair into the table
7146174Sbostic  */
7246174Sbostic 		if ((dbp->put)(dbp, &key, &item, R_NOOVERWRITE) != NULL) {
7346174Sbostic 			fprintf(stderr, "cannot enter: key %s\n",
7446174Sbostic 				item.data);
7546174Sbostic 			exit(1);
7646174Sbostic 		}
7746174Sbostic 	}
7846174Sbostic 
7946174Sbostic 	if ( --argc ) {
8046174Sbostic 		fp = fopen ( argv[0], "r");
8146174Sbostic 		i = 0;
8246174Sbostic 		while ( fgets(wp1, 8192, fp) &&
8346174Sbostic 			fgets(wp2, 8192, fp) &&
8446174Sbostic 			i++ < MAXWORDS) {
8546174Sbostic 		    key.size = strlen(wp1);
8650985Sbostic 		    stat = (dbp->del)(dbp, &key, 0);
8746174Sbostic 		    if (stat) {
8846174Sbostic 			fprintf ( stderr, "Error retrieving %s\n", key.data );
8946174Sbostic 			exit(1);
9046174Sbostic 		    }
9146174Sbostic 		}
9246174Sbostic 		fclose(fp);
9346174Sbostic 	}
9446174Sbostic 	(dbp->close)(dbp);
9546174Sbostic 	exit(0);
9646174Sbostic }
97