/[LeafOK_CVS]/lbbs/src/hash_dict.c
ViewVC logotype

Diff of /lbbs/src/hash_dict.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.4 by sysadm, Thu Dec 18 12:04:02 2025 UTC Revision 1.5 by sysadm, Thu Dec 18 12:27:15 2025 UTC
# Line 39  static const unsigned int hash_dict_prim Line 39  static const unsigned int hash_dict_prim
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          {          {
# Line 56  HASH_DICT *hash_dict_create(int item_cou Line 54  HASH_DICT *hash_dict_create(int item_cou
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                  {                  {
# Line 75  HASH_DICT *hash_dict_create(int item_cou Line 73  HASH_DICT *hash_dict_create(int item_cou
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          }          }
# Line 99  void hash_dict_destroy(HASH_DICT *p_dict Line 94  void hash_dict_destroy(HASH_DICT *p_dict
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)


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1