43 char data[]; |
42 char data[]; |
44 }; |
43 }; |
45 |
44 |
46 static void cx_hash_map_clear(struct cx_map_s *map) { |
45 static void cx_hash_map_clear(struct cx_map_s *map) { |
47 struct cx_hash_map_s *hash_map = (struct cx_hash_map_s *) map; |
46 struct cx_hash_map_s *hash_map = (struct cx_hash_map_s *) map; |
48 cx_for_n(i, hash_map->bucket_count) { |
47 for (size_t i = 0; i < hash_map->bucket_count; i++) { |
49 struct cx_hash_map_element_s *elem = hash_map->buckets[i]; |
48 struct cx_hash_map_element_s *elem = hash_map->buckets[i]; |
50 if (elem != NULL) { |
49 if (elem != NULL) { |
51 do { |
50 do { |
52 struct cx_hash_map_element_s *next = elem->next; |
51 struct cx_hash_map_element_s *next = elem->next; |
53 // invoke the destructor |
52 // invoke the destructor |
439 if (new_buckets == NULL) { |
438 if (new_buckets == NULL) { |
440 return 1; |
439 return 1; |
441 } |
440 } |
442 |
441 |
443 // iterate through the elements and assign them to their new slots |
442 // iterate through the elements and assign them to their new slots |
444 cx_for_n(slot, hash_map->bucket_count) { |
443 for (size_t slot = 0; slot < hash_map->bucket_count; slot++) { |
445 struct cx_hash_map_element_s *elm = hash_map->buckets[slot]; |
444 struct cx_hash_map_element_s *elm = hash_map->buckets[slot]; |
446 while (elm != NULL) { |
445 while (elm != NULL) { |
447 struct cx_hash_map_element_s *next = elm->next; |
446 struct cx_hash_map_element_s *next = elm->next; |
448 size_t new_slot = elm->key.hash % new_bucket_count; |
447 size_t new_slot = elm->key.hash % new_bucket_count; |
449 |
448 |