File: select_tests.c

package info (click to toggle)
cmph 0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 1,900 kB
  • ctags: 911
  • sloc: sh: 9,649; ansic: 9,546; makefile: 65
file content (97 lines) | stat: -rw-r--r-- 2,477 bytes parent folder | download | duplicates (6)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "../src/select.h"

#define DEBUG
#include "../src/debug.h"
#include <stdlib.h>

static inline void print_values(select_t * sel)
{
	register cmph_uint32 index;
	
	index = select_query(sel, 0);
	fprintf(stderr, "Index[0]\t= %u\n", index - 0);

	index = select_next_query(sel, index);
	fprintf(stderr, "Next Index\t= %u\n", index);

	index = select_query(sel, 1);
	fprintf(stderr, "Index[1]\t= %u\n", index - 1);

	index = select_next_query(sel, index);
	fprintf(stderr, "Next Index\t= %u\n", index);

	index = select_query(sel, 2);
	fprintf(stderr, "Index[2]\t= %u\n", index - 2);

	index = select_next_query(sel, index);
	fprintf(stderr, "Next Index\t= %u\n", index);

	index = select_query(sel, 3);
	fprintf(stderr, "Index[3]\t= %u\n", index - 3);
}


static inline void print_values_packed(char * sel_packed)
{
	register cmph_uint32 index;
	
	index = select_query_packed(sel_packed, 0);
	fprintf(stderr, "Index[0]\t= %u\n", index - 0);

	index = select_next_query_packed(sel_packed, index);
	fprintf(stderr, "Next Index\t= %u\n", index);

	index = select_query_packed(sel_packed, 1);
	fprintf(stderr, "Index[1]\t= %u\n", index - 1);

	index = select_next_query_packed(sel_packed, index);
	fprintf(stderr, "Next Index\t= %u\n", index);

	index = select_query_packed(sel_packed, 2);
	fprintf(stderr, "Index[2]\t= %u\n", index - 2);

	index = select_next_query_packed(sel_packed, index);
	fprintf(stderr, "Next Index\t= %u\n", index);

	index = select_query_packed(sel_packed, 3);
	fprintf(stderr, "Index[3]\t= %u\n", index - 3);
}

int main(int argc, char **argv)
{
	select_t sel;
	cmph_uint32 n = 4;
	cmph_uint32 keys_vec[4] = {0,1,2,3}; 
	cmph_uint32 m = keys_vec[3];
	char *buf = NULL;
	cmph_uint32 buflen = 0;
	char * select_packed = NULL;
	cmph_uint32 select_pack_size = 0;
	
	select_init(&sel);
	select_generate(&sel, keys_vec, n, m);
	fprintf(stderr, "Space usage = %u\n", select_get_space_usage(&sel));
	print_values(&sel);
	
	fprintf(stderr, "Dumping select structure\n");
	select_dump(&sel, &buf, &buflen);
	
	select_destroy(&sel);
	fprintf(stderr, "Loading select structure\n");
	
	select_load(&sel, buf, buflen);
	print_values(&sel);
	free(buf);;
	
	select_pack_size = select_packed_size(&sel);
	
	select_packed = (char *) calloc(select_pack_size, sizeof(char));
	select_pack(&sel, select_packed);
	select_destroy(&sel);
	
	fprintf(stderr, "Querying the packed select structure\n");
	print_values_packed(select_packed);
	
	free(select_packed);
	return 0;
}