src/hash_map.c

changeset 1040
1ecf4dbbc60c
parent 994
3603bdf4a78b
equal deleted inserted replaced
1039:ec62453fc8a6 1040:1ecf4dbbc60c
28 28
29 #include "cx/hash_map.h" 29 #include "cx/hash_map.h"
30 30
31 #include <string.h> 31 #include <string.h>
32 #include <assert.h> 32 #include <assert.h>
33 #include <errno.h>
33 34
34 struct cx_hash_map_element_s { 35 struct cx_hash_map_element_s {
35 /** A pointer to the next element in the current bucket. */ 36 /** A pointer to the next element in the current bucket. */
36 struct cx_hash_map_element_s *next; 37 struct cx_hash_map_element_s *next;
37 38
449 int cxMapRehash(CxMap *map) { 450 int cxMapRehash(CxMap *map) {
450 struct cx_hash_map_s *hash_map = (struct cx_hash_map_s *) map; 451 struct cx_hash_map_s *hash_map = (struct cx_hash_map_s *) map;
451 if (map->collection.size > ((hash_map->bucket_count * 3) >> 2)) { 452 if (map->collection.size > ((hash_map->bucket_count * 3) >> 2)) {
452 453
453 size_t new_bucket_count = (map->collection.size * 5) >> 1; 454 size_t new_bucket_count = (map->collection.size * 5) >> 1;
455 if (new_bucket_count < hash_map->bucket_count) {
456 errno = EOVERFLOW;
457 return 1;
458 }
454 struct cx_hash_map_element_s **new_buckets = cxCalloc( 459 struct cx_hash_map_element_s **new_buckets = cxCalloc(
455 map->collection.allocator, 460 map->collection.allocator,
456 new_bucket_count, sizeof(struct cx_hash_map_element_s *) 461 new_bucket_count, sizeof(struct cx_hash_map_element_s *)
457 ); 462 );
458 463

mercurial