hash_method.c

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1999, 2000
00005  *      Sleepycat Software.  All rights reserved.
00006  */
00007 
00008 #include "config.h"
00009 
00010 #ifndef lint
00011 static const char revid[] = "$Id: hash__method_8c-source.html,v 1.1 2008/06/08 10:19:33 sebdiaz Exp $";
00012 #endif /* not lint */
00013 
00014 #ifndef NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016 #endif
00017 
00018 #include "db_int.h"
00019 #include "db_page.h"
00020 #include "hash.h"
00021 
00022 static int __ham_set_h_ffactor __P((DB *, u_int32_t));
00023 static int __ham_set_h_hash __P((DB *, u_int32_t(*)(const void *, u_int32_t)));
00024 static int __ham_set_h_nelem __P((DB *, u_int32_t));
00025 
00026 /*
00027  * CDB___ham_db_create --
00028  *      Hash specific initialization of the DB structure.
00029  *
00030  * PUBLIC: int CDB___ham_db_create __P((DB *));
00031  */
00032 int
00033 CDB___ham_db_create(dbp)
00034         DB *dbp;
00035 {
00036         HASH *hashp;
00037         int ret;
00038 
00039         if ((ret = CDB___os_malloc(dbp->dbenv,
00040             sizeof(HASH), NULL, &dbp->h_internal)) != 0)
00041                 return (ret);
00042 
00043         hashp = dbp->h_internal;
00044 
00045         hashp->h_nelem = 0;                     /* Defaults. */
00046         hashp->h_ffactor = 0;
00047         hashp->h_hash = NULL;
00048 
00049         dbp->set_h_ffactor = __ham_set_h_ffactor;
00050         dbp->set_h_hash = __ham_set_h_hash;
00051         dbp->set_h_nelem = __ham_set_h_nelem;
00052 
00053         return (0);
00054 }
00055 
00056 /*
00057  * PUBLIC: int CDB___ham_db_close __P((DB *));
00058  */
00059 int
00060 CDB___ham_db_close(dbp)
00061         DB *dbp;
00062 {
00063         if (dbp->h_internal == NULL)
00064                 return (0);
00065         CDB___os_free(dbp->h_internal, sizeof(HASH));
00066         dbp->h_internal = NULL;
00067         return (0);
00068 }
00069 
00070 /*
00071  * __ham_set_h_ffactor --
00072  *      Set the fill factor.
00073  */
00074 static int
00075 __ham_set_h_ffactor(dbp, h_ffactor)
00076         DB *dbp;
00077         u_int32_t h_ffactor;
00078 {
00079         HASH *hashp;
00080 
00081         DB_ILLEGAL_AFTER_OPEN(dbp, "set_h_ffactor");
00082         DB_ILLEGAL_METHOD(dbp, DB_OK_HASH);
00083 
00084         hashp = dbp->h_internal;
00085         hashp->h_ffactor = h_ffactor;
00086         return (0);
00087 }
00088 
00089 /*
00090  * __ham_set_h_hash --
00091  *      Set the hash function.
00092  */
00093 static int
00094 __ham_set_h_hash(dbp, func)
00095         DB *dbp;
00096         u_int32_t (*func) __P((const void *, u_int32_t));
00097 {
00098         HASH *hashp;
00099 
00100         DB_ILLEGAL_AFTER_OPEN(dbp, "set_h_hash");
00101         DB_ILLEGAL_METHOD(dbp, DB_OK_HASH);
00102 
00103         hashp = dbp->h_internal;
00104         hashp->h_hash = func;
00105         return (0);
00106 }
00107 
00108 /*
00109  * __ham_set_h_nelem --
00110  *      Set the table size.
00111  */
00112 static int
00113 __ham_set_h_nelem(dbp, h_nelem)
00114         DB *dbp;
00115         u_int32_t h_nelem;
00116 {
00117         HASH *hashp;
00118 
00119         DB_ILLEGAL_AFTER_OPEN(dbp, "set_h_nelem");
00120         DB_ILLEGAL_METHOD(dbp, DB_OK_HASH);
00121 
00122         hashp = dbp->h_internal;
00123         hashp->h_nelem = h_nelem;
00124         return (0);
00125 }

Generated on Sun Jun 8 10:56:37 2008 for GNUmifluz by  doxygen 1.5.5