Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

hash.h

Go to the documentation of this file.
00001 
00002 /*
00003 ** Copyright (C) 2005 Russell Leighton
00004 **
00005 ** This program is free software; you can redistribute it and/or modify
00006 ** it under the terms of the GNU General Public License as published by
00007 ** the Free Software Foundation; either version 2 of the License, or
00008 ** (at your option) any later version.
00009 **
00010 ** This program is distributed in the hope that it will be useful,
00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ** GNU General Public License for more details.
00014 **
00015 ** You should have received a copy of the GNU General Public License
00016 ** along with this program; if not, write to the Free Software
00017 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 /*
00021 
00022 Changes:
00023 
00024 03/30/02 Russ Leighton
00025 Made the aw_xxx_uinr function take a signed in for 'incr' so I can decriment
00026 
00027 */
00028 
00029 #ifndef __AW_HASH__
00030 #define __AW_HASH__
00031 
00041 #include "errors.h"
00042 #include "util.h"
00043 
00044 /* ------------------------- hash.c */
00045 
00046 /* macros */
00047 #define AW_HASH_NULL_KEY 0
00048 
00049 /* -------- 32bit keys */
00050 
00051 typedef struct {
00052 
00053   u_int32_t key;
00054 
00055   void *user_pointer;
00056 
00057   u_int32_t n_collisions; /* number of collisions at this point, always <= max_collisions */
00058 
00059 } aw_hash32_entry_t;
00060 
00061 
00062 typedef struct {
00063   
00064   u_int32_t nvalid_entries;
00065 
00066   u_int32_t nentries;
00067 
00068   u_int32_t modmask;      /* used if nentries is power of 2 to avoid modulo operation */
00069 
00070   u_int32_t max_collisions;
00071 
00072   aw_hash32_entry_t *entries;
00073 
00074 } aw_hash32_t;
00075 
00076 
00082 aw_hash32_t *aw_hash32_make(u_int32_t nentries);
00083 
00089 void aw_hash32_clear(aw_hash32_t *ht);
00090 
00096 void aw_hash32_destroy(aw_hash32_t *ht);
00097 
00106 int aw_hash32_insert(u_int32_t key, void *user_pointer, aw_hash32_t *ht);
00107 
00108 
00115 void aw_hash32_delete(u_int32_t key, aw_hash32_t *ht);
00116 
00124 void  *aw_hash32_fetch(u_int32_t key, const aw_hash32_t *ht);
00125 
00134 int32_t aw_hash32_incr(u_int32_t key, int32_t incr, aw_hash32_t *ht);
00135 
00136 
00144 void aw_hash32_thin(aw_hash32_t *ht, void *user_pointer, u_int32_t (*eval)(void *user_pointer, void *valuer_ptr) );
00145 
00153 void aw_hash32_map(aw_hash32_t *ht, void *user_pointer, void (*eval)(void *user_pointer, u_int32_t key, void *valuer_ptr) );
00154 
00155 /* -------- 64bit keys */
00156 
00157 typedef struct {
00158 
00159   u_int64_t key;
00160 
00161   void *user_pointer;
00162 
00163   u_int32_t n_collisions; /* number of collisions at this point, always <= max_collisions */
00164 
00165 } aw_hash64_entry_t;
00166 
00167 
00168 typedef struct {
00169   
00170   u_int32_t nvalid_entries;
00171 
00172   u_int32_t nentries;
00173 
00174   u_int32_t modmask;      /* used if nentries is power of 2 to avoid modulo operation */
00175 
00176   u_int32_t max_collisions;
00177 
00178   aw_hash64_entry_t *entries;
00179 
00180 } aw_hash64_t;
00181 
00187 aw_hash64_t *aw_hash64_make(u_int32_t nentries);
00188 
00194 void aw_hash64_clear(aw_hash64_t *ht);
00195 
00201 void aw_hash64_destroy(aw_hash64_t *ht);
00202 
00211 int aw_hash64_insert(u_int64_t key, void *user_pointer, aw_hash64_t *ht);
00212 
00219 void aw_hash64_delete(u_int64_t key, aw_hash64_t *ht);
00220 
00228 void  *aw_hash64_fetch(u_int64_t key, const aw_hash64_t *ht);
00229 
00238 int32_t aw_hash64_incr(u_int64_t key, int32_t incr, aw_hash64_t *ht);
00239 
00240 
00248 void aw_hash64_thin(aw_hash64_t *ht, void *user_pointer, u_int32_t (*eval)(void *user_pointer, void *valuer_ptr) );
00249 
00257 void aw_hash64_map(aw_hash64_t *ht, void *user_pointer, void (*eval)(void *user_pointer, u_int64_t key, void *valuer_ptr) );
00258 
00259 /* -------- String keys */
00260 
00261 typedef struct {
00262 
00263   byte_t *key;
00264 
00265   void *user_pointer;
00266 
00267   u_int32_t n_collisions; /* number of collisions at this point , always <= max_collisions */
00268 
00269 } aw_hashString_entry_t;
00270 
00271 
00272 typedef struct {
00273   
00274   u_int32_t nvalid_entries;
00275 
00276   u_int32_t nentries;
00277 
00278   u_int32_t modmask;      /* used if nentries is power of 2 to avoid modulo operation */
00279 
00280   u_int32_t max_collisions;
00281 
00282   aw_hashString_entry_t *entries;
00283 
00284 } aw_hashString_t;
00285 
00291 aw_hashString_t *aw_hashString_make(u_int32_t nentries);
00292 
00298 void aw_hashString_clear(aw_hashString_t *ht);
00299 
00305 void aw_hashString_destroy(aw_hashString_t *ht);
00306 
00315 int aw_hashString_insert(const byte_t *key, void *user_pointer, aw_hashString_t *ht);
00316 
00323 void aw_hashString_delete(const byte_t *key, aw_hashString_t *ht);
00324 
00332 void  *aw_hashString_fetch(const byte_t *key, const aw_hashString_t *ht);
00333 
00334 
00342 void aw_hashString_thin(aw_hashString_t *ht, void *user_pointer, u_int32_t (*eval)(void *user_pointer, void *valuer_ptr) );
00343 
00351 void aw_hashString_map(aw_hashString_t *ht, void *user_pointer, void (*eval)(void *user_pointer, byte_t *key, void *valuer_ptr) );
00352 
00353 #endif
Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)