11573Srgrimes/*-
21573Srgrimes * Copyright (c) 1991, 1993
31573Srgrimes *	The Regents of the University of California.  All rights reserved.
41573Srgrimes *
51573Srgrimes * This code is derived from software contributed to Berkeley by
61573Srgrimes * Margo Seltzer.
71573Srgrimes *
81573Srgrimes * Redistribution and use in source and binary forms, with or without
91573Srgrimes * modification, are permitted provided that the following conditions
101573Srgrimes * are met:
111573Srgrimes * 1. Redistributions of source code must retain the above copyright
121573Srgrimes *    notice, this list of conditions and the following disclaimer.
131573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141573Srgrimes *    notice, this list of conditions and the following disclaimer in the
151573Srgrimes *    documentation and/or other materials provided with the distribution.
161573Srgrimes * 4. Neither the name of the University nor the names of its contributors
171573Srgrimes *    may be used to endorse or promote products derived from this software
181573Srgrimes *    without specific prior written permission.
191573Srgrimes *
201573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231573Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301573Srgrimes * SUCH DAMAGE.
311573Srgrimes */
321573Srgrimes
331573Srgrimes#ifndef lint
341573Srgrimesstatic char copyright[] =
351573Srgrimes"@(#) Copyright (c) 1991, 1993\n\
361573Srgrimes	The Regents of the University of California.  All rights reserved.\n";
371573Srgrimes#endif /* not lint */
381573Srgrimes
3992986Sobrien#if defined(LIBC_SCCS) && !defined(lint)
401573Srgrimesstatic char sccsid[] = "@(#)driver2.c	8.1 (Berkeley) 6/4/93";
4192986Sobrien#endif /* LIBC_SCCS and not lint */
4292986Sobrien#include <sys/cdefs.h>
4392986Sobrien__FBSDID("$FreeBSD$");
441573Srgrimes
451573Srgrimes/*
461573Srgrimes * Test driver, to try to tackle the large ugly-split problem.
471573Srgrimes */
481573Srgrimes
491573Srgrimes#include <sys/file.h>
501573Srgrimes#include <stdio.h>
511573Srgrimes#include "ndbm.h"
521573Srgrimes
531573Srgrimesint my_hash(key, len)
541573Srgrimes	char	*key;
551573Srgrimes	int	len;
561573Srgrimes{
571573Srgrimes	return(17);		/* So I'm cruel... */
581573Srgrimes}
591573Srgrimes
601573Srgrimesmain(argc, argv)
611573Srgrimes	int	argc;
621573Srgrimes{
631573Srgrimes	DB	*db;
641573Srgrimes	DBT	key, content;
651573Srgrimes	char	keybuf[2049];
661573Srgrimes	char	contentbuf[2049];
671573Srgrimes	char	buf[256];
681573Srgrimes	int	i;
691573Srgrimes	HASHINFO	info;
701573Srgrimes
711573Srgrimes	info.bsize = 1024;
721573Srgrimes	info.ffactor = 5;
731573Srgrimes	info.nelem = 1;
741573Srgrimes	info.cachesize = NULL;
751573Srgrimes#ifdef HASH_ID_PROGRAM_SPECIFIED
761573Srgrimes	info.hash_id = HASH_ID_PROGRAM_SPECIFIED;
771573Srgrimes	info.hash_func = my_hash;
781573Srgrimes#else
791573Srgrimes	info.hash = my_hash;
801573Srgrimes#endif
811573Srgrimes	info.lorder = 0;
821573Srgrimes	if (!(db = dbopen("bigtest", O_RDWR | O_CREAT, 0644, DB_HASH, &info))) {
831573Srgrimes		sprintf(buf, "dbopen: failed on file bigtest");
841573Srgrimes		perror(buf);
851573Srgrimes		exit(1);
861573Srgrimes	}
871573Srgrimes	srandom(17);
881573Srgrimes	key.data = keybuf;
891573Srgrimes	content.data = contentbuf;
901573Srgrimes	bzero(keybuf, sizeof(keybuf));
911573Srgrimes	bzero(contentbuf, sizeof(contentbuf));
921573Srgrimes	for (i=1; i <= 500; i++) {
931573Srgrimes		key.size = 128 + (random()&1023);
941573Srgrimes		content.size = 128 + (random()&1023);
951573Srgrimes/*		printf("%d: Key size %d, data size %d\n", i, key.size,
961573Srgrimes		       content.size); */
971573Srgrimes		sprintf(keybuf, "Key #%d", i);
981573Srgrimes		sprintf(contentbuf, "Contents #%d", i);
991573Srgrimes		if ((db->put)(db, &key, &content, R_NOOVERWRITE)) {
1001573Srgrimes			sprintf(buf, "dbm_store #%d", i);
1011573Srgrimes			perror(buf);
1021573Srgrimes		}
1031573Srgrimes	}
1041573Srgrimes	if ((db->close)(db)) {
1051573Srgrimes		perror("closing hash file");
1061573Srgrimes		exit(1);
1071573Srgrimes	}
1081573Srgrimes	exit(0);
1091573Srgrimes}
1101573Srgrimes
1111573Srgrimes
1128870Srgrimes
113