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