150988Sbostic /*-
2*61210Sbostic  * Copyright (c) 1991, 1993
3*61210Sbostic  *	The Regents of the University of California.  All rights reserved.
450988Sbostic  *
550988Sbostic  * This code is derived from software contributed to Berkeley by
650988Sbostic  * Margo Seltzer.
750988Sbostic  *
850988Sbostic  * %sccs.include.redist.c%
950988Sbostic  */
1050988Sbostic 
1150988Sbostic #ifndef lint
12*61210Sbostic static char copyright[] =
13*61210Sbostic "@(#) Copyright (c) 1991, 1993\n\
14*61210Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1550988Sbostic #endif /* not lint */
1650988Sbostic 
1750988Sbostic #ifndef lint
18*61210Sbostic static char sccsid[] = "@(#)driver2.c	8.1 (Berkeley) 06/04/93";
1950988Sbostic #endif /* not lint */
2050988Sbostic 
2150988Sbostic /*
2250988Sbostic  * Test driver, to try to tackle the large ugly-split problem.
2350988Sbostic  */
2450988Sbostic 
2550988Sbostic #include <sys/file.h>
2650988Sbostic #include <stdio.h>
2750988Sbostic #include "ndbm.h"
2850988Sbostic 
my_hash(key,len)2950988Sbostic int my_hash(key, len)
3050988Sbostic 	char	*key;
3150988Sbostic 	int	len;
3250988Sbostic {
3350988Sbostic 	return(17);		/* So I'm cruel... */
3450988Sbostic }
3550988Sbostic 
main(argc,argv)3650988Sbostic main(argc, argv)
3750988Sbostic 	int	argc;
3850988Sbostic {
3950988Sbostic 	DB	*db;
4050988Sbostic 	DBT	key, content;
4150988Sbostic 	char	keybuf[2049];
4250988Sbostic 	char	contentbuf[2049];
4350988Sbostic 	char	buf[256];
4450988Sbostic 	int	i;
4550988Sbostic 	HASHINFO	info;
4650988Sbostic 
4750988Sbostic 	info.bsize = 1024;
4850988Sbostic 	info.ffactor = 5;
4950988Sbostic 	info.nelem = 1;
5050988Sbostic 	info.cachesize = NULL;
5150988Sbostic #ifdef HASH_ID_PROGRAM_SPECIFIED
5250988Sbostic 	info.hash_id = HASH_ID_PROGRAM_SPECIFIED;
5350988Sbostic 	info.hash_func = my_hash;
5450988Sbostic #else
5550988Sbostic 	info.hash = my_hash;
5650988Sbostic #endif
5750988Sbostic 	info.lorder = 0;
5851075Sbostic 	if (!(db = dbopen("bigtest", O_RDWR | O_CREAT, 0644, DB_HASH, &info))) {
5951075Sbostic 		sprintf(buf, "dbopen: failed on file bigtest");
6050988Sbostic 		perror(buf);
6150988Sbostic 		exit(1);
6250988Sbostic 	}
6350988Sbostic 	srandom(17);
6450988Sbostic 	key.data = keybuf;
6550988Sbostic 	content.data = contentbuf;
6650988Sbostic 	bzero(keybuf, sizeof(keybuf));
6750988Sbostic 	bzero(contentbuf, sizeof(contentbuf));
6850988Sbostic 	for (i=1; i <= 500; i++) {
6950988Sbostic 		key.size = 128 + (random()&1023);
7050988Sbostic 		content.size = 128 + (random()&1023);
7150988Sbostic /*		printf("%d: Key size %d, data size %d\n", i, key.size,
7250988Sbostic 		       content.size); */
7350988Sbostic 		sprintf(keybuf, "Key #%d", i);
7450988Sbostic 		sprintf(contentbuf, "Contents #%d", i);
7550988Sbostic 		if ((db->put)(db, &key, &content, R_NOOVERWRITE)) {
7650988Sbostic 			sprintf(buf, "dbm_store #%d", i);
7750988Sbostic 			perror(buf);
7850988Sbostic 		}
7950988Sbostic 	}
8050988Sbostic 	if ((db->close)(db)) {
8150988Sbostic 		perror("closing hash file");
8250988Sbostic 		exit(1);
8350988Sbostic 	}
8450988Sbostic 	exit(0);
8550988Sbostic }
8650988Sbostic 
8750988Sbostic 
8850988Sbostic 
89