31GHash::GHash(GBool deleteKeysA) {
34 deleteKeys = deleteKeysA;
36 tab = (GHashBucket **)gmalloc(size * sizeof(GHashBucket *));
37 for (h = 0; h < size; ++h) {
47 for (h = 0; h < size; ++h) {
60void GHash::add(GString *key, void *val) {
70 tab = (GHashBucket **)gmalloc(size * sizeof(GHashBucket *));
71 for (h = 0; h < size; ++h) {
74 for (i = 0; i < oldSize; ++i) {
77 oldTab[i] = oldTab[i]->next;
96void *GHash::lookup( const GString *key) {
100 if (!(p = find(key, &h))) {
106void *GHash::lookup( const char *key) {
110 if (!(p = find(key, &h))) {
116void *GHash::remove( const GString *key) {
122 if (!(p = find(key, &h))) {
139void *GHash::remove( const char *key) {
145 if (!(p = find(key, &h))) {
162void GHash::startIter(GHashIter **iter) {
163 *iter = new GHashIter;
168GBool GHash::getNext(GHashIter **iter, GString **key, void **val) {
173 (*iter)->p = (*iter)->p->next;
175 while (!(*iter)->p) {
176 if (++(*iter)->h == size) {
181 (*iter)->p = tab[(*iter)->h];
183 *key = (*iter)->p->key;
184 *val = (*iter)->p->val;
188void GHash::killIter(GHashIter **iter) {
193GHashBucket *GHash::find( const GString *key, int *h) {
197 for (p = tab[*h]; p; p = p->next) {
198 if (!p->key->cmp(key)) {
205GHashBucket *GHash::find( const char *key, int *h) {
209 for (p = tab[*h]; p; p = p->next) {
210 if (!p->key->cmp(key)) {
217int GHash::hash( const GString *key) {
223 for (p = key->getCString(), i = 0; i < key->getLength(); ++p, ++i) {
224 h = 17 * h + (int)(*p & 0xff);
226 return ( int)(h % size);
229int GHash::hash( const char *key) {
234 for (p = key; *p; ++p) {
235 h = 17 * h + (int)(*p & 0xff);
237 return ( int)(h % size);
|