blob: d33c17495f9660761129475bd54dbc9248a37b02 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
|
/* { dg-additional-options "-Wno-analyzer-too-complex" } */
#include <stdlib.h>
typedef short hashNx;
typedef struct hashSt {
hashNx *hs_index;
int hs_used;
int hs_slots;
} hashSt;
void hashEmpty(hashSt *td);
int hashAlloc(hashSt *td, int slots) {
hashNx *index;
if (slots > td->hs_slots) {
if (td->hs_index != NULL)
index = realloc(td->hs_index, (size_t)slots * sizeof(hashNx));
else
index = malloc((size_t)slots * sizeof(hashNx));
if (index == NULL)
return 0;
td->hs_index = index;
td->hs_slots = slots;
}
hashEmpty(td);
return 1;
}
void hashEmpty(hashSt *td) {
hashNx *index;
int slots;
for (slots = td->hs_slots, index = td->hs_index; --slots >= 0;)
*index++ = -1;
td->hs_used = 0;
}
|