18#ifndef __STRINGHASH_H__
19#define __STRINGHASH_H__
21#include "StringBasics.h"
29 inline void setCaseSensitive(
bool caseSensitive) {myCaseSensitive = caseSensitive;}
31 : myCaseSensitive(
false)
37 virtual void SetSize(
int newsize) = 0;
40 inline bool stringsEqual(
const String& string1,
const String& string2)
const
45 return(string1.FastCompare(string2) == 0);
48 return(string1.SlowCompare(string2) == 0);
51 inline unsigned int getKey(
const String&
string)
const
55 return(hash(
string.uchar(),
string.Length(), 0));
58 return(hash_no_case(
string.uchar(),
string.Length(), 0));
71 unsigned int count, size;
87 void SetSize(
int newsize);
100 void * Object(
int i)
const
104 void * Object(
const String & key)
const
106 int index = Find(key);
108 return index >= 0 ? objects[index] : NULL;
110 void * Object(
const String & key,
void *(*create_object)())
112 int index = Find(key, create_object);
114 return objects[index];
117 void SetObject(
int i,
void *
object)
121 void SetObject(
const String & key,
void *
object)
126 int Add(
const String & s,
void *
object = NULL);
127 int Find(
const String & s,
void *(*create_object)() = NULL);
128 int Find(
const String & s)
const;
132 const String & operator [](
int i)
const
134 return *(strings[i]);
136 String & operator [](
int i)
138 return *(strings[i]);
142 static void * CreateHash();
144 void Delete(
unsigned int index);
145 void Delete(
const String & key)
150 bool SlotInUse(
int index)
const
152 return strings[index] != NULL;
156 void Print(FILE * file);
157 void Print(
const char * filename);
159 String StringList(
char separator =
',');
162 void ReadLinesFromFile(FILE * file);
163 void ReadLinesFromFile(
const char * filename);
165 void ReadLinesFromFile(
IFILE & file);
171 unsigned int Iterate(
unsigned int key,
const String &
string)
const
173 unsigned int h = key & mask;
175 while (strings[h] != NULL &&
177 (!stringsEqual(*(strings[h]),
string))))
183 void Insert(
unsigned int where,
unsigned int key,
const String &
string)
185 strings[where] =
new String;
186 *(strings[where]) =
string;
199 unsigned int count, size;
215 void SetSize(
int newsize);
228 int Integer(
int i)
const
232 int Integer(
const String & key)
const
234 int index = Find(key);
236 return index >= 0 ? integers[index] : -1;
239 void SetInteger(
int i,
int value)
243 void SetInteger(
const String & key,
int value)
248 int IncrementCount(
const String & key);
249 int IncrementCount(
const String & key,
int amount);
250 int DecrementCount(
const String & key);
251 int GetCount(
const String & key)
const;
252 int GetCount(
int index)
const
254 return integers[index];
257 int Add(
const String & s,
int integer);
258 int Find(
const String & s,
int defaultValue);
259 int Find(
const String & s)
const;
264 const String & operator [](
int i)
const
266 return *(strings[i]);
268 String & operator [](
int i)
270 return *(strings[i]);
274 void Delete(
unsigned int index);
275 void Delete(
const String & key)
280 bool SlotInUse(
int index)
const
282 return strings[index] != NULL;
287 unsigned int Iterate(
unsigned int key,
const String &
string)
const
289 unsigned int h = key & mask;
291 while (strings[h] != NULL &&
293 (!stringsEqual(*(strings[h]),
string))))
299 void Insert(
unsigned int where,
unsigned int key,
const String &
string)
301 strings[where] =
new String;
302 *(strings[where]) =
string;
315 unsigned int count, size;
331 void SetSize(
int newsize);
344 double Double(
int i)
const
348 double Double(
const String & key)
const
350 int index = Find(key);
352 return index >= 0 ? doubles[index] : _NAN_;
355 void SetDouble(
int i,
double value)
359 void SetDouble(
const String & key,
double value)
364 int Add(
const String & s,
double value);
365 int Find(
const String & s,
double defaultValue);
366 int Find(
const String & s)
const;
370 const String & operator [](
int i)
const
372 return *(strings[i]);
374 String & operator [](
int i)
376 return *(strings[i]);
380 void Delete(
unsigned int index);
381 void Delete(
const String & key)
386 bool SlotInUse(
int index)
const
388 return strings[index] != NULL;
393 unsigned int Iterate(
unsigned int key,
const String &
string)
const
395 unsigned int h = key & mask;
397 while (strings[h] != NULL &&
399 (!stringsEqual(*(strings[h]),
string))))
405 void Insert(
unsigned int where,
unsigned int key,
const String &
string)
407 strings[where] =
new String;
408 *(strings[where]) =
string;