-
Notifications
You must be signed in to change notification settings - Fork 1
/
queryres.c
56 lines (48 loc) · 1.02 KB
/
queryres.c
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
45
46
47
48
49
50
51
52
53
54
55
56
/**
* A structure to store the results of a query.
*
* A partial implementation of a linked list is used to store query results
* because an unknown number of results can be returned.
*
* Author: Gati Aher
*/
#include "queryres.h"
queryres_t *queryres_create()
{
queryres_t *qr = malloc(sizeof(queryres_t));
qr->head = NULL;
qr->len = 0;
}
void queryres_free(queryres_t *qr)
{
//create a link
res_t *ptr = qr->head;
while (ptr != NULL)
{
res_t *temp_ptr = ptr->next;
free(ptr);
ptr = temp_ptr;
}
}
void queryres_add(queryres_t *qr, u_int32_t data)
{
res_t *link = (res_t *)malloc(sizeof(res_t));
link->data = data;
link->next = qr->head;
qr->head = link;
qr->len += 1;
}
void queryres_print(queryres_t *qr)
{
if (qr != NULL)
{
res_t *ptr = qr->head;
printf("\n[ ");
while (ptr != NULL)
{
printf("%d, ", ptr->data);
ptr = ptr->next;
}
printf(" ] len=%d \n", qr->len);
}
}