19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#define BUCKET_SIZE sizeof(struct of_dictionary_bucket)
static OF_INLINE void
resize(id self, Class isa, size_t count, struct of_dictionary_bucket **data,
size_t *size)
{
float fill = (float)count / *size;
size_t newsize;
struct of_dictionary_bucket *newdata;
uint32_t i;
if (fill > 0.75) {
if (*size > SIZE_MAX / 2)
@throw [OFOutOfRangeException newWithClass: isa];
newsize = *size * 2;
} else if (fill < 0.25)
newsize = *size / 2;
else
return;
newdata = [self allocMemoryForNItems: newsize
withSize: BUCKET_SIZE];
memset(newdata, 0, newsize * BUCKET_SIZE);
|
|
|
|
|
|
|
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#define BUCKET_SIZE sizeof(struct of_dictionary_bucket)
static OF_INLINE void
resize(id self, Class isa, size_t count, struct of_dictionary_bucket **data,
size_t *size)
{
size_t fill = count * 4 / *size;
size_t newsize;
struct of_dictionary_bucket *newdata;
uint32_t i;
if (fill > 3) {
if (*size > SIZE_MAX / 8)
@throw [OFOutOfRangeException newWithClass: isa];
newsize = *size << 1;
} else if (fill < 1)
newsize = *size >> 1;
else
return;
newdata = [self allocMemoryForNItems: newsize
withSize: BUCKET_SIZE];
memset(newdata, 0, newsize * BUCKET_SIZE);
|