00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef _hash_h
00039 #define _hash_h
00040
00041 #include "types.h"
00042
00043 #include <iostream>
00044
00045 typedef void* HashValue;
00046 struct HashTableEntry;
00047
00048 class HashTable : public LightObject {
00049 public:
00050 HashTable();
00051 HashTable(int) {}
00052 void MakeTable();
00053 bool IsEmpty();
00054 void Dump(ostream&);
00055 int AddEntry(char* key, HashValue value, int* index = 0);
00056 int AddEntry(bool, char* key, int len, HashValue value, int* index = 0);
00057
00058 int AddEntry(char* key, int len, HashValue value, int* index = 0) {
00059 return AddEntry(TRUE, key, len, value, index);
00060 }
00061
00062
00063 int AddDupEntry(char* key, int len, HashValue value, int* index = 0) {
00064 return AddEntry(FALSE, key, len, value, index);
00065 }
00066
00067 bool Lookup(char* key, HashValue* value);
00068 bool Lookup(char* key, int len, HashValue* value);
00069 bool LookupEntries(char* key, int len, HashValue* value, int& nth);
00070 HashValue Peek(int index);
00071 bool RemoveEntry(char* key);
00072 bool RemoveEntry(char* key, int len);
00073 void ReplaceValue(int index, HashValue value);
00074
00075 protected:
00076 char* KeyString(char* key);
00077 char* KeyString(char* key, int len);
00078
00079 bool Lookup2(char* key, HashValue* val, int* index);
00080 bool Lookup2(char* key, int len, HashValue* val, int* index);
00081 static uint NextPrimeNumber(uint number);
00082 bool GrowTable(int increment);
00083 unsigned int StringToInt(char*);
00084 unsigned int StringToInt(char*, int);
00085 int HashFunc(unsigned int p, int n);
00086
00087 protected:
00088 HashTableEntry *entries;
00089 int Size;
00090
00091 int Prime2;
00092 };
00093
00094 class BigHashTable : public HashTable {
00095 public:
00096 BigHashTable();
00097 };
00098
00099 #endif