Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

hash_method.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1999-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: hash_method.c,v 12.1 2005/06/16 20:22:53 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 #endif
00015 
00016 #include "db_int.h"
00017 #include "dbinc/db_page.h"
00018 #include "dbinc/hash.h"
00019 
00020 static int __ham_set_h_ffactor __P((DB *, u_int32_t));
00021 static int __ham_set_h_hash
00022                __P((DB *, u_int32_t(*)(DB *, const void *, u_int32_t)));
00023 static int __ham_set_h_nelem __P((DB *, u_int32_t));
00024 
00025 /*
00026  * __ham_db_create --
00027  *      Hash specific initialization of the DB structure.
00028  *
00029  * PUBLIC: int __ham_db_create __P((DB *));
00030  */
00031 int
00032 __ham_db_create(dbp)
00033         DB *dbp;
00034 {
00035         HASH *hashp;
00036         int ret;
00037 
00038         if ((ret = __os_malloc(dbp->dbenv,
00039             sizeof(HASH), &dbp->h_internal)) != 0)
00040                 return (ret);
00041 
00042         hashp = dbp->h_internal;
00043 
00044         hashp->h_nelem = 0;                     /* Defaults. */
00045         hashp->h_ffactor = 0;
00046         hashp->h_hash = NULL;
00047 
00048         dbp->get_h_ffactor = __ham_get_h_ffactor;
00049         dbp->set_h_ffactor = __ham_set_h_ffactor;
00050         dbp->set_h_hash = __ham_set_h_hash;
00051         dbp->get_h_nelem = __ham_get_h_nelem;
00052         dbp->set_h_nelem = __ham_set_h_nelem;
00053 
00054         return (0);
00055 }
00056 
00057 /*
00058  * PUBLIC: int __ham_db_close __P((DB *));
00059  */
00060 int
00061 __ham_db_close(dbp)
00062         DB *dbp;
00063 {
00064         if (dbp->h_internal == NULL)
00065                 return (0);
00066         __os_free(dbp->dbenv, dbp->h_internal);
00067         dbp->h_internal = NULL;
00068         return (0);
00069 }
00070 
00071 /*
00072  * __ham_get_h_ffactor --
00073  *
00074  * PUBLIC: int __ham_get_h_ffactor __P((DB *, u_int32_t *));
00075  */
00076 int
00077 __ham_get_h_ffactor(dbp, h_ffactorp)
00078         DB *dbp;
00079         u_int32_t *h_ffactorp;
00080 {
00081         HASH *hashp;
00082 
00083         hashp = dbp->h_internal;
00084         *h_ffactorp = hashp->h_ffactor;
00085         return (0);
00086 }
00087 
00088 /*
00089  * __ham_set_h_ffactor --
00090  *      Set the fill factor.
00091  */
00092 static int
00093 __ham_set_h_ffactor(dbp, h_ffactor)
00094         DB *dbp;
00095         u_int32_t h_ffactor;
00096 {
00097         HASH *hashp;
00098 
00099         DB_ILLEGAL_AFTER_OPEN(dbp, "DB->set_h_ffactor");
00100         DB_ILLEGAL_METHOD(dbp, DB_OK_HASH);
00101 
00102         hashp = dbp->h_internal;
00103         hashp->h_ffactor = h_ffactor;
00104         return (0);
00105 }
00106 
00107 /*
00108  * __ham_set_h_hash --
00109  *      Set the hash function.
00110  */
00111 static int
00112 __ham_set_h_hash(dbp, func)
00113         DB *dbp;
00114         u_int32_t (*func) __P((DB *, const void *, u_int32_t));
00115 {
00116         HASH *hashp;
00117 
00118         DB_ILLEGAL_AFTER_OPEN(dbp, "DB->set_h_hash");
00119         DB_ILLEGAL_METHOD(dbp, DB_OK_HASH);
00120 
00121         hashp = dbp->h_internal;
00122         hashp->h_hash = func;
00123         return (0);
00124 }
00125 
00126 /*
00127  * __db_get_h_nelem --
00128  *
00129  * PUBLIC: int __ham_get_h_nelem __P((DB *, u_int32_t *));
00130  */
00131 int
00132 __ham_get_h_nelem(dbp, h_nelemp)
00133         DB *dbp;
00134         u_int32_t *h_nelemp;
00135 {
00136         HASH *hashp;
00137 
00138         DB_ILLEGAL_METHOD(dbp, DB_OK_HASH);
00139 
00140         hashp = dbp->h_internal;
00141         *h_nelemp = hashp->h_nelem;
00142         return (0);
00143 }
00144 
00145 /*
00146  * __ham_set_h_nelem --
00147  *      Set the table size.
00148  */
00149 static int
00150 __ham_set_h_nelem(dbp, h_nelem)
00151         DB *dbp;
00152         u_int32_t h_nelem;
00153 {
00154         HASH *hashp;
00155 
00156         DB_ILLEGAL_AFTER_OPEN(dbp, "DB->set_h_nelem");
00157         DB_ILLEGAL_METHOD(dbp, DB_OK_HASH);
00158 
00159         hashp = dbp->h_internal;
00160         hashp->h_nelem = h_nelem;
00161         return (0);
00162 }

Generated on Sun Dec 25 12:14:29 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2