-
Notifications
You must be signed in to change notification settings - Fork 1
/
Index_test_01.c
204 lines (167 loc) · 6.76 KB
/
Index_test_01.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* Test code for Index.c module. This includes it directly, so can
* call static functions including _Index_op().
*
* gcc Index_test_01.c -o Index_test_01 && ./Index_test_01
*/
#include "Index.c"
#include "Mem.c"
#include "String.c"
#include "Cfg.c"
static void check(int val, int expected)
{
if (val == expected) {
printf("good\n");
}
else {
printf("bad\n");
}
}
FILE *gvf;
void gvout1(Index_node *node)
{
fprintf(gvf, "node%ld[label = \"<f0> |<f1> %" PRIu32 "|<f2> \"];\n", node->key, node->key);
}
void gvout2(Index_node *node)
{
if (node->left) {
fprintf(gvf, "\"node%ld\":f0 -> \"node%ld\":f1;\n", node->key, node->left->key);
}
if (node->right) {
fprintf(gvf, "\"node%ld\":f2 -> \"node%ld\":f1;\n", node->key, node->right->key);
}
}
void make_gv(Index *idx, const char *filename)
{
gvf = fopen(filename, "w");
if (!gvf) {
perror(filename);
return;
}
fprintf(gvf, "digraph g {\n");
fprintf(gvf, "node [shape = record,height=.1];\n");
Index_walk(idx, gvout1);
Index_walk(idx, gvout2);
fprintf(gvf, "}\n");
fclose(gvf);
}
int main()
{
{
Index *idx = Index_new();
int err;
_Index_op(idx, S("one"), NULL, (void*)1, NULL, INDEX_OP_ADD, 0, &err);
check(err, INDEX_NO_ERROR);
_Index_op(idx, S("two"), NULL, (void*)2, NULL, INDEX_OP_ADD, 0, &err);
check(err, INDEX_NO_ERROR);
_Index_op(idx, S("three"), NULL, (void*)3, NULL, INDEX_OP_ADD, 0, &err);
check(err, INDEX_NO_ERROR);
_Index_op(idx, S("four"), NULL, (void*)4, NULL, INDEX_OP_ADD, 0, &err);
check(err, INDEX_NO_ERROR);
_Index_op(idx, S("five"), NULL, (void*)5, NULL, INDEX_OP_ADD, 0, &err);
check(err, INDEX_NO_ERROR);
void *result;
_Index_op(idx, S("three"), NULL, NULL, &result, INDEX_OP_FIND, 0, &err);
check(err, INDEX_NO_ERROR);
printf("[three]: %ld\n", (long)result);
_Index_op(idx, S("one"), NULL, NULL, &result, INDEX_OP_FIND, 0, &err);
check(err, INDEX_NO_ERROR);
printf("[one]: %ld\n", (long)result);
_Index_op(idx, S("two"), NULL, NULL, &result, INDEX_OP_FIND, 0, &err);
check(err, INDEX_NO_ERROR);
printf("[two]: %ld\n", (long)result);
_Index_op(idx, S("four"), NULL, NULL, &result, INDEX_OP_FIND, 0, &err);
check(err, INDEX_NO_ERROR);
printf("[four]: %ld\n", (long)result);
_Index_op(idx, S("five"), NULL, NULL, &result, INDEX_OP_FIND, 0, &err);
check(err, INDEX_NO_ERROR);
printf("[five]: %ld\n", (long)result);
_Index_op(idx, S("six"), NULL, NULL, &result, INDEX_OP_FIND, 0, &err);
check(err, INDEX_KEY_NOT_FOUND);
_Index_op(idx, S("two"), NULL, (void*)22, &result, INDEX_OP_ADD, 0, &err);
check(err, INDEX_DUPLICATE_KEY);
_Index_op(idx, S("two"), NULL, (void*)22, &result, INDEX_OP_ADD, 1, &err);
check(err, INDEX_NO_ERROR);
printf("[old two]: %ld\n", (long)result);
_Index_op(idx, S("two"), NULL, NULL, &result, INDEX_OP_FIND, 0, &err);
check(err, INDEX_NO_ERROR);
printf("[two]: %ld\n", (long)result);
_Index_op(idx, S("two"), NULL, NULL, NULL, INDEX_OP_FIND, 0, &err);
check(err, INDEX_NO_DEST);
_Index_op(idx, NULL, NULL, NULL, &result, INDEX_OP_FIND, 0, &err);
check(err, INDEX_NO_KEY);
_Index_op(NULL, NULL, NULL, NULL, &result, INDEX_OP_FIND, 0, &err);
check(err, INDEX_NO_IDX);
}
{
const char * text = "\
I am wondering if I can avoid the shift by using different fixed-valuey \
mask operations depending on the current bit offset into a 32 or 64 \
bit source word. There would be a similar block of code repeated for \
each possible bit offset, with a switch statement at the top. It \
would be trading code size for a possible reduction in number of \
instructions executed, but I think it should all fit into the \
instruction cache for any processor that I care about. \
Sometimes I wonder about huffman decoding for Jpeg blocks, and whether \
it could be done with a linear worst-case procedure consisting of only \
arithmetic operations (add, subtract, multiply, divide), leaving \
sparse output. Then that output could be translated to the final \
output values, again using arithmetic operations. Avoid conditionals \
and lookup tables. Pre-generate intermediate factors, as long as they \
are constant. If all this works, then it might be possible to use \
planar hardware operators to decompress an entire frame worth of \
DCT blocks in parallel. Or, if the DCTs are hard to separate, \
several frames worth in parallel. \
I was considering using Unix epoch times with millisecond resolution, \
stored in a uint64_t. This would last 6 million times the current \
date value. But for 30fps video, even 1ms error per frame could \
accumulate and throw off the video by one frame in only a single \
second. And MpegTS wants 90KHz resolution. I will stick with timevals \
for now. Or why not double-precision floats? \
TS playback on iOS is a little choppy, for both birdcam and satellite \
input sources. I think this might be because of the ordering of the \
TS packets. If the video and audio input objects (elementary packets) \
have timestamps and known duration, then I could spread the period \
over the packets and assign an estimated timestamp to each packet, \
even those that do not include PTS/DTS. Then it should be relatively \
easy to sort the packets for writeout, and more accurately insert PAT \
and PMT packets.";
String_list *strs = String_split_s(text, " ");
printf("%d strings\n", String_list_len(strs));
Index *idx = Index_new();
int i;
for (i=0; i < String_list_len(strs); i++) {
void *oldvalue = NULL;
int err = 0;
int d = (i%2);
printf("%d: adding %s with delete=%d ; ", i, s(String_list_get(strs, i)), d);
_Index_op(idx, String_list_get(strs, i), NULL, (void*)(long)i, &oldvalue, INDEX_OP_ADD, d, &err);
printf("err=%d oldvalue=%ld\n", err, (long)oldvalue);
}
printf("count=%d\n", idx->count);
Index_analyze(idx);
make_gv(idx, "one.gv");
for (i=0; i < String_list_len(strs); i+=2) {
void *oldvalue = NULL;
int err = 0;
int d = 1;
printf("%d: finding %s with delete=%d ; ", i, s(String_list_get(strs, i)), d);
_Index_op(idx, String_list_get(strs, i), NULL, NULL, &oldvalue, INDEX_OP_FIND, d, &err);
printf("err=%d oldvalue=%ld\n", err, (long)oldvalue);
}
printf("count=%d\n", idx->count);
Index_analyze(idx);
make_gv(idx, "two.gv");
for (i=1; i < String_list_len(strs); i+=2) {
void *oldvalue = NULL;
int err = 0;
int d = 1;
printf("%d: finding %s with delete=%d ; ", i, s(String_list_get(strs, i)), d);
_Index_op(idx, String_list_get(strs, i), NULL, NULL, &oldvalue, INDEX_OP_FIND, d, &err);
printf("err=%d oldvalue=%ld\n", err, (long)oldvalue);
}
printf("count=%d\n", idx->count);
Index_analyze(idx);
}
return 0;
}