00001 /********************************************************************** 00002 * Copyright 2002 Jeff Rush <jrush@taupro.com> 00003 * Original Copyright 1979-2002 Udanax.com 00004 * 00005 * This file is part of the Udanax xanalogical storage system. 00006 * 00007 * Udanax is free software; you can redistribute it and/or modify it 00008 * under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * Udanax is distributed in the hope that it will be useful, but 00013 * WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with Udanax; if not, write to the Free Software Foundation, 00019 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 **********************************************************************/ 00021 00030 /* Modification History: 00031 * $Log: cashedisk.cxx,v $ 00032 * Revision 1.9 2004/09/11 13:59:21 jrush 00033 * Changed all fprintf's to stderr to use the Nana library L() macro. Also 00034 * removed a 2-3 minor compiler warnings. 00035 * 00036 * Revision 1.8 2004/09/04 16:02:18 jrush 00037 * Added Doxygen headers before each and every function definition. 00038 * 00039 * Revision 1.7 2002/05/28 03:58:42 jrush 00040 * Sources modified to comply with GPL licensing. 00041 * 00042 * Revision 1.6 2002/04/12 11:48:50 jrush 00043 * Major reorganization of includes into a single base-include style. 00044 * 00045 * Revision 1.5 2002/04/06 15:01:44 jrush 00046 * Changed INT to just 'int'. 00047 * 00048 * Revision 1.4 2002/02/14 10:08:25 jrush 00049 * Cleaned up source: 00050 * 00051 * 1. ran thru the indent tool to achieve a standard look, 00052 * 2. added structured comments at top for use with DOxygen reporting 00053 * as well as CVS keywords, 00054 * 3. centralized prototypes in protos.h, removing incomplete ones, 00055 * 4. cleaned up use of bool/BOOLEAN type to suit C++ type, 00056 * 5. fixed initializer nesting in tumbler constants, 00057 * 6. converted select() int bits into ANSI fd_set type, 00058 * 7. added Makefile.am for use by automake. 00059 * 00060 */ 00061 00062 #include "udanax.h" 00063 00064 /* crude random replacement hash cashe */ 00065 #define HASHSIZE 301 00066 #define HASHMULT 754343 /* random prime */ 00067 00068 typedef struct hashfoo { 00069 int blocknumber; 00070 typeuberrawdiskloaf urdloaf; 00071 } hashtable; 00072 00073 hashtable xhashtable[HASHSIZE]; 00074 00082 void 00083 inithash() 00084 { 00085 int i; 00086 for (i = 0; i < HASHSIZE; i++) 00087 xhashtable[i].blocknumber = -1; 00088 } 00089 00097 void 00098 actuallyreadrawloaffromhash( 00099 typeuberrawdiskloaf *loafptr, 00100 int blocknumber) 00101 { 00102 int temp; 00103 void addtohash(), actuallyreadrawloaf(); 00104 00105 /* L("actuallyreadrawloaffromhash %d \n",blocknumber); */ 00106 if (temp = blockisinhash(blocknumber)) { 00107 *loafptr = xhashtable[temp].urdloaf; 00108 return; 00109 } 00110 actuallyreadrawloaf(loafptr, blocknumber); 00111 addtohash(loafptr, blocknumber); 00112 00113 } 00114 00122 void 00123 writethruhash( 00124 typeuberrawdiskloaf *loafptr, 00125 int blocknumber) 00126 { 00127 int temp; 00128 void addtohash(); 00129 00130 if (temp = blockisinhash(blocknumber)) { 00131 xhashtable[temp].urdloaf = *loafptr; 00132 } else { 00133 addtohash(loafptr, blocknumber); 00134 } 00135 } 00136 00144 void 00145 hashcasheclash() 00146 { 00147 } 00148 00156 int 00157 blockisinhash( 00158 int blocknumber) 00159 { 00160 int temp = hash(blocknumber); 00161 00162 if (xhashtable[temp].blocknumber == blocknumber) 00163 return temp; 00164 else 00165 return 0; 00166 } 00167 00175 void 00176 addtohash( 00177 typeuberrawdiskloaf *loafptr, 00178 int blocknumber) 00179 { 00180 int temp = hash(blocknumber); 00181 00182 if (xhashtable[temp].blocknumber != -1) 00183 hashcasheclash(); 00184 00185 xhashtable[temp].blocknumber = blocknumber; 00186 xhashtable[temp].urdloaf = *loafptr; 00187 } 00188 00196 int 00197 hash( 00198 int blocknumber) 00199 { 00200 return abs(blocknumber * HASHMULT) % HASHSIZE; 00201 }
1.3.4