~ubuntu-branches/ubuntu/lucid/curl/lucid-201101212007

« back to all changes in this revision

Viewing changes to lib/hash.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-02-08 11:20:41 UTC
  • mto: (3.1.1 lenny) (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: james.westby@ubuntu.com-20080208112041-hed7sb5r6ghmjf8v
Tags: upstream-7.18.0
ImportĀ upstreamĀ versionĀ 7.18.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: hash.c,v 1.31 2007-09-27 18:12:03 danf Exp $
 
21
 * $Id: hash.c,v 1.32 2007-11-07 09:21:35 bagder Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
#include "setup.h"
39
39
  struct curl_hash *h = (struct curl_hash *) user;
40
40
  struct curl_hash_element *e = (struct curl_hash_element *) element;
41
41
 
42
 
  if (e->key)
 
42
  if(e->key)
43
43
    free(e->key);
44
44
 
45
45
  h->dtor(e->ptr);
57
57
{
58
58
  int i;
59
59
 
60
 
  if (!slots || !hfunc || !comparator ||!dtor) {
 
60
  if(!slots || !hfunc || !comparator ||!dtor) {
61
61
    return 1; /* failure */
62
62
  }
63
63
 
92
92
{
93
93
  struct curl_hash *h;
94
94
 
95
 
  if (!slots || !hfunc || !comparator ||!dtor) {
 
95
  if(!slots || !hfunc || !comparator ||!dtor) {
96
96
    return NULL; /* failure */
97
97
  }
98
98
 
99
99
  h = (struct curl_hash *) malloc(sizeof(struct curl_hash));
100
 
  if (h) {
 
100
  if(h) {
101
101
    if(Curl_hash_init(h, slots, hfunc, comparator, dtor)) {
102
102
      /* failure */
103
103
      free(h);
148
148
 
149
149
  for (le = l->head; le; le = le->next) {
150
150
    he = (struct curl_hash_element *) le->ptr;
151
 
    if (h->comp_func(he->key, he->key_len, key, key_len)) {
 
151
    if(h->comp_func(he->key, he->key_len, key, key_len)) {
152
152
      h->dtor(p);     /* remove the NEW entry */
153
153
      return he->ptr; /* return the EXISTING entry */
154
154
    }
155
155
  }
156
156
 
157
157
  he = mk_hash_element(key, key_len, p);
158
 
  if (he) {
 
158
  if(he) {
159
159
    if(Curl_llist_insert_next(l, l->tail, he)) {
160
160
      ++h->size;
161
161
      return p; /* return the new entry */
182
182
 
183
183
  for (le = l->head; le; le = le->next) {
184
184
    he = le->ptr;
185
 
    if (h->comp_func(he->key, he->key_len, key, key_len)) {
 
185
    if(h->comp_func(he->key, he->key_len, key, key_len)) {
186
186
      Curl_llist_remove(l, le, (void *) h);
187
187
      return 0;
188
188
    }
199
199
 
200
200
  for (le = l->head; le; le = le->next) {
201
201
    he = le->ptr;
202
 
    if (h->comp_func(he->key, he->key_len, key, key_len)) {
 
202
    if(h->comp_func(he->key, he->key_len, key, key_len)) {
203
203
      return he->ptr;
204
204
    }
205
205
  }
254
254
      struct curl_hash_element *he = le->ptr;
255
255
      lnext = le->next;
256
256
      /* ask the callback function if we shall remove this entry or not */
257
 
      if (comp(user, he->ptr)) {
 
257
      if(comp(user, he->ptr)) {
258
258
        Curl_llist_remove(list, le, (void *) h);
259
259
        --h->size; /* one less entry in the hash now */
260
260
      }
266
266
void
267
267
Curl_hash_destroy(struct curl_hash *h)
268
268
{
269
 
  if (!h)
 
269
  if(!h)
270
270
    return;
271
271
 
272
272
  Curl_hash_clean(h);
279
279
  const char *end = key_str + key_length;
280
280
  unsigned long h = 5381;
281
281
 
282
 
  while (key_str < end) {
 
282
  while(key_str < end) {
283
283
    h += h << 5;
284
284
    h ^= (unsigned long) *key_str++;
285
285
  }
292
292
  char *key1 = (char *)k1;
293
293
  char *key2 = (char *)k2;
294
294
 
295
 
  if (key1_len == key2_len &&
 
295
  if(key1_len == key2_len &&
296
296
      *key1 == *key2 &&
297
297
      memcmp(key1, key2, key1_len) == 0) {
298
298
    return 1;
309
309
  struct curl_llist_element *le;
310
310
  struct curl_llist *list;
311
311
  struct curl_hash_element  *he;
312
 
  if (!h)
 
312
  if(!h)
313
313
    return;
314
314
 
315
315
  fprintf(stderr, "=Hash dump=\n");