| 39 |
HASH_DICT *hash_dict_create(int item_count_limit) |
HASH_DICT *hash_dict_create(int item_count_limit) |
| 40 |
{ |
{ |
| 41 |
HASH_DICT *p_dict = NULL; |
HASH_DICT *p_dict = NULL; |
|
unsigned int i; |
|
|
unsigned int j; |
|
| 42 |
|
|
| 43 |
if (item_count_limit <= 0) |
if (item_count_limit <= 0) |
| 44 |
{ |
{ |
| 54 |
} |
} |
| 55 |
|
|
| 56 |
p_dict->prime_index = hash_dict_prime_list_count - 1; |
p_dict->prime_index = hash_dict_prime_list_count - 1; |
| 57 |
for (i = 0; i < hash_dict_prime_list_count; i++) |
for (unsigned int i = 0; i < hash_dict_prime_list_count; i++) |
| 58 |
{ |
{ |
| 59 |
if (item_count_limit < hash_dict_prime_list[i]) |
if (item_count_limit < hash_dict_prime_list[i]) |
| 60 |
{ |
{ |
| 73 |
return NULL; |
return NULL; |
| 74 |
} |
} |
| 75 |
|
|
| 76 |
for (i = 0; i < p_dict->bucket_count; i++) |
for (unsigned int i = 0; i < p_dict->bucket_count; i++) |
| 77 |
{ |
{ |
| 78 |
p_dict->buckets[i] = calloc(HASH_DICT_BUCKET_SIZE, sizeof(HASH_ITEM *)); |
p_dict->buckets[i] = calloc(HASH_DICT_BUCKET_SIZE, sizeof(HASH_ITEM *)); |
| 79 |
if (p_dict->buckets[i] == NULL) |
if (p_dict->buckets[i] == NULL) |
| 80 |
{ |
{ |
| 81 |
log_error("calloc(HASH_DICT_BUCKET_SIZE, HASH_ITEM) error at bucket %d\n", i); |
log_error("calloc(HASH_DICT_BUCKET_SIZE, HASH_ITEM) error at bucket %d\n", i); |
| 82 |
for (j = i - 1; j >= 0; j--) |
p_dict->bucket_count = i; |
| 83 |
{ |
hash_dict_destroy(p_dict); |
|
free(p_dict->buckets[j]); |
|
|
} |
|
|
free(p_dict); |
|
| 84 |
return NULL; |
return NULL; |
| 85 |
} |
} |
| 86 |
} |
} |
| 94 |
{ |
{ |
| 95 |
HASH_ITEM *p_item; |
HASH_ITEM *p_item; |
| 96 |
HASH_ITEM *p_next; |
HASH_ITEM *p_next; |
|
unsigned int i; |
|
|
unsigned int j; |
|
| 97 |
|
|
| 98 |
if (p_dict == NULL) |
if (p_dict == NULL) |
| 99 |
{ |
{ |
| 100 |
return; |
return; |
| 101 |
} |
} |
| 102 |
|
|
| 103 |
for (i = 0; i < p_dict->bucket_count; i++) |
for (unsigned int i = 0; i < p_dict->bucket_count; i++) |
| 104 |
{ |
{ |
| 105 |
for (j = 0; j < HASH_DICT_BUCKET_SIZE; j++) |
for (unsigned int j = 0; j < HASH_DICT_BUCKET_SIZE; j++) |
| 106 |
{ |
{ |
| 107 |
p_item = p_dict->buckets[i][j]; |
p_item = p_dict->buckets[i][j]; |
| 108 |
while (p_item != NULL) |
while (p_item != NULL) |