hash.h

Go to the documentation of this file.
00001 // Copyright (C) 2006 Bryan Jacobson <bryanjacobson@users.sourceforge.net>
00002 // This program is licensed under the terms of the GNU General Public License
00003 // version 2, as published by the Free Software Foundation.
00004 // This program is distributed in the hope that it will be useful,
00005 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00006 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007 
00008 #ifndef Hash_h
00009 #define Hash_h
00010 
00014 
00015 #include <cstdio>
00016 #include "ondisk.h"
00017 
00043 class Hash
00044 {
00045   public:
00046 
00048     Hash(int sizeHint = 8);
00049 
00051     void AddItem(int key, void *value);
00052 
00054     void *GetItem(int key);
00055 
00057     void *ReplaceItem(int key, void *value);
00058 
00060     int Dump(OnDisk *pOnDisk);
00061 
00063     void CallAll(void (*f)(int key, void *value));
00064   private:
00065     class CollisionNode
00066     {
00067       public:
00068         CollisionNode(int key, void *value);
00069         int            mKey;
00070         void          *mValue;
00071         CollisionNode *mLink;
00072     };
00073 
00074     // Private methods
00075     void Allocate(int newSize);
00076     void NodeInsert(CollisionNode *p);
00077 
00078     // Private data
00079     int mSize;  // The size of this hash table.
00080     int mCount; // The number of values stored in this Hash (initially 0)
00081     CollisionNode **mTable; // The hash table
00082 };
00083 
00084 class HashDiskRecord;
00085 
00086 class HashDisk
00087 {
00088   public:
00089           HashDisk(void *pDiskData);
00090     void *GetItem(int key); 
00091   private:
00092     HashDiskRecord *mpHash;
00093 };
00094 
00095 #endif // Hash_h

Generated on Sun Oct 8 09:32:09 2006 for gabbie by  doxygen 1.4.6