summaryrefslogtreecommitdiff
path: root/rdoff/collectn.c
blob: d77f54b5c4bc3dec39466f3a13cc3868b2c9ea66 (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
/*
 * collectn.c - implements variable length pointer arrays [collections].
 *
 * This file is public domain.
 */

#include "rdfutils.h"
#include "collectn.h"

void collection_init(Collection * c)
{
    int i;

    for (i = 0; i < 32; i++)
        c->p[i] = NULL;
    c->next = NULL;
}

void **colln(Collection * c, int index)
{
    while (index >= 32) {
        index -= 32;
        if (c->next == NULL) {
            c->next = nasm_malloc(sizeof(Collection));
            collection_init(c->next);
        }
        c = c->next;
    }
    return &(c->p[index]);
}

void collection_reset(Collection * c)
{
    int i;

    if (c->next) {
        collection_reset(c->next);
        nasm_free(c->next);
    }

    c->next = NULL;
    for (i = 0; i < 32; i++)
        c->p[i] = NULL;
}