1.1 --- a/templates/progops.c Fri Dec 02 00:55:45 2016 +0100
1.2 +++ b/templates/progops.c Fri Dec 02 18:31:20 2016 +0100
1.3 @@ -35,21 +35,34 @@
1.4 return data;
1.5 }
1.6
1.7 +static inline unsigned int __mapping_buckets(unsigned int n)
1.8 +{
1.9 + return n > 0 ? n / 2 : 5;
1.10 +}
1.11 +
1.12 __mapping *__new_mapping(unsigned int n)
1.13 {
1.14 /* Allocate a number of buckets. */
1.15 - __mapping *data = (__mapping *) __ALLOCATE(1, __MAPPING_SIZE(__MAPPING_BUCKETS));
1.16 + unsigned int capacity = __mapping_buckets(n);
1.17 + __mapping *data = (__mapping *) __ALLOCATE(1, __MAPPING_SIZE(capacity));
1.18 unsigned int i;
1.19
1.20 - /* Allocate fragments with an initial size of 2 * n / __MAPPING_BUCKETS,
1.21 - assuming a mostly uniform distribution of values across the buckets. */
1.22 + /* Create arrays for key and value buckets. */
1.23 +
1.24 + data->keys = (__fragment **) __ALLOCATE(capacity, sizeof(__fragment *));
1.25 + data->values = (__fragment **) __ALLOCATE(capacity, sizeof(__fragment *));
1.26
1.27 - for (i = 0; i < __MAPPING_BUCKETS; i++)
1.28 + /* Allocate fragments with an initial size of 2, assuming a mostly uniform
1.29 + distribution of values across the buckets will occur. */
1.30 +
1.31 + for (i = 0; i < capacity; i++)
1.32 {
1.33 - data->keys[i] = __new_fragment(2 * n / __MAPPING_BUCKETS);
1.34 - data->values[i] = __new_fragment(2 * n / __MAPPING_BUCKETS);
1.35 + data->keys[i] = __new_fragment(2);
1.36 + data->values[i] = __new_fragment(2);
1.37 }
1.38
1.39 + data->size = 0;
1.40 + data->capacity = capacity;
1.41 return data;
1.42 }
1.43