gksort.c
Go to the documentation of this file.
1 
10 #include <GKlib.h>
11 
12 #define N 10000
13 
14 /*************************************************************************/
16 /*************************************************************************/
17 void test_isort()
18 {
19  gk_idx_t i;
20  int array[N];
21 
22  /* test the increasing sort */
23  printf("Testing iisort...\n");
24  for (i=0; i<N; i++)
25  array[i] = RandomInRange(123432);
26 
27  gk_isorti(N, array);
28 
29  for (i=0; i<N-1; i++) {
30  if (array[i] > array[i+1])
31  printf("gk_isorti error at index %jd [%d %d]\n", (intmax_t)i, array[i], array[i+1]);
32  }
33 
34 
35  /* test the decreasing sort */
36  printf("Testing disort...\n");
37  for (i=0; i<N; i++)
38  array[i] = RandomInRange(123432);
39 
40  gk_isortd(N, array);
41 
42  for (i=0; i<N-1; i++) {
43  if (array[i] < array[i+1])
44  printf("gk_isortd error at index %jd [%d %d]\n", (intmax_t)i, array[i], array[i+1]);
45  }
46 
47 }
48 
49 
50 /*************************************************************************/
52 /*************************************************************************/
53 void test_fsort()
54 {
55  gk_idx_t i;
56  float array[N];
57 
58  /* test the increasing sort */
59  printf("Testing ifsort...\n");
60  for (i=0; i<N; i++)
61  array[i] = RandomInRange(123432)/(1.0+RandomInRange(645323));
62 
63  gk_fsorti(N, array);
64 
65  for (i=0; i<N-1; i++) {
66  if (array[i] > array[i+1])
67  printf("gk_fsorti error at index %jd [%f %f]\n", (intmax_t)i, array[i], array[i+1]);
68  }
69 
70 
71  /* test the decreasing sort */
72  printf("Testing dfsort...\n");
73  for (i=0; i<N; i++)
74  array[i] = RandomInRange(123432)/(1.0+RandomInRange(645323));
75 
76  gk_fsortd(N, array);
77 
78  for (i=0; i<N-1; i++) {
79  if (array[i] < array[i+1])
80  printf("gk_fsortd error at index %jd [%f %f]\n", (intmax_t)i, array[i], array[i+1]);
81  }
82 
83 }
84 
85 
86 /*************************************************************************/
88 /*************************************************************************/
90 {
91  gk_idx_t i;
92  gk_idx_t array[N];
93 
94  /* test the increasing sort */
95  printf("Testing idxsorti...\n");
96  for (i=0; i<N; i++)
97  array[i] = RandomInRange(123432);
98 
99  gk_idxsorti(N, array);
100 
101  for (i=0; i<N-1; i++) {
102  if (array[i] > array[i+1])
103  printf("gk_idxsorti error at index %zd [%zd %zd]\n", (ssize_t)i, (ssize_t)array[i], (ssize_t)array[i+1]);
104  }
105 
106 
107  /* test the decreasing sort */
108  printf("Testing idxsortd...\n");
109  for (i=0; i<N; i++)
110  array[i] = RandomInRange(123432);
111 
112  gk_idxsortd(N, array);
113 
114  for (i=0; i<N-1; i++) {
115  if (array[i] < array[i+1])
116  printf("gk_idxsortd error at index %zd [%zd %zd]\n", (ssize_t)i, (ssize_t)array[i], (ssize_t)array[i+1]);
117  }
118 
119 }
120 
121 
122 
123 /*************************************************************************/
125 /*************************************************************************/
127 {
128  gk_idx_t i;
129  gk_ikv_t array[N];
130 
131  /* test the increasing sort */
132  printf("Testing ikvsorti...\n");
133  for (i=0; i<N; i++) {
134  array[i].key = RandomInRange(123432);
135  array[i].val = i;
136  }
137 
138  gk_ikvsorti(N, array);
139 
140  for (i=0; i<N-1; i++) {
141  if (array[i].key > array[i+1].key)
142  printf("gk_ikvsorti error at index %jd [%d %d] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
143  }
144 
145 
146  /* test the decreasing sort */
147  printf("Testing ikvsortd...\n");
148  for (i=0; i<N; i++) {
149  array[i].key = RandomInRange(123432);
150  array[i].val = i;
151  }
152 
153  gk_ikvsortd(N, array);
154 
155  for (i=0; i<N-1; i++) {
156  if (array[i].key < array[i+1].key)
157  printf("gk_ikvsortd error at index %jd [%d %d] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
158  }
159 
160 }
161 
162 
163 
164 /*************************************************************************/
166 /*************************************************************************/
168 {
169  gk_idx_t i;
170  gk_fkv_t array[N];
171 
172  /* test the increasing sort */
173  printf("Testing fkvsorti...\n");
174  for (i=0; i<N; i++) {
175  array[i].key = RandomInRange(123432)/(1.0+RandomInRange(645323));
176  array[i].val = i;
177  }
178 
179  gk_fkvsorti(N, array);
180 
181  for (i=0; i<N-1; i++) {
182  if (array[i].key > array[i+1].key)
183  printf("gk_fkvsorti error at index %jd [%f %f] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
184  }
185 
186 
187  /* test the decreasing sort */
188  printf("Testing fkvsortd...\n");
189  for (i=0; i<N; i++) {
190  array[i].key = RandomInRange(123432)/(1.0+RandomInRange(645323));
191  array[i].val = i;
192  }
193 
194  gk_fkvsortd(N, array);
195 
196  for (i=0; i<N-1; i++) {
197  if (array[i].key < array[i+1].key)
198  printf("gk_fkvsortd error at index %jd [%f %f] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
199  }
200 
201 }
202 
203 
204 /*************************************************************************/
206 /*************************************************************************/
208 {
209  gk_idx_t i;
210  gk_dkv_t array[N];
211 
212  /* test the increasing sort */
213  printf("Testing dkvsorti...\n");
214  for (i=0; i<N; i++) {
215  array[i].key = RandomInRange(123432)/(1.0+RandomInRange(645323));
216  array[i].val = i;
217  }
218 
219  gk_dkvsorti(N, array);
220 
221  for (i=0; i<N-1; i++) {
222  if (array[i].key > array[i+1].key)
223  printf("gk_dkvsorti error at index %jd [%lf %lf] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
224  }
225 
226 
227  /* test the decreasing sort */
228  printf("Testing dkvsortd...\n");
229  for (i=0; i<N; i++) {
230  array[i].key = RandomInRange(123432)/(1.0+RandomInRange(645323));
231  array[i].val = i;
232  }
233 
234  gk_dkvsortd(N, array);
235 
236  for (i=0; i<N-1; i++) {
237  if (array[i].key < array[i+1].key)
238  printf("gk_dkvsortd error at index %jd [%lf %lf] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
239  }
240 
241 }
242 
243 
244 /*************************************************************************/
246 /*************************************************************************/
248 {
249  gk_idx_t i;
250  gk_skv_t array[N];
251  char line[256];
252 
253  /* test the increasing sort */
254  printf("Testing skvsorti...\n");
255  for (i=0; i<N; i++) {
256  sprintf(line, "%d", RandomInRange(123432));
257  array[i].key = gk_strdup(line);
258  array[i].val = i;
259  }
260 
261  gk_skvsorti(N, array);
262 
263  for (i=0; i<N-1; i++) {
264  if (strcmp(array[i].key, array[i+1].key) > 0)
265  printf("gk_skvsorti error at index %jd [%s %s] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
266  }
267 
268 
269  /* test the decreasing sort */
270  printf("Testing skvsortd...\n");
271  for (i=0; i<N; i++) {
272  sprintf(line, "%d", RandomInRange(123432));
273  array[i].key = gk_strdup(line);
274  array[i].val = i;
275  }
276 
277  gk_skvsortd(N, array);
278 
279  for (i=0; i<N-1; i++) {
280  /*printf("%s\n", array[i].key);*/
281  if (strcmp(array[i].key, array[i+1].key) < 0)
282  printf("gk_skvsortd error at index %jd [%s %s] [%jd %jd]\n", (intmax_t)i, array[i].key, array[i+1].key, (intmax_t)array[i].val, (intmax_t)array[i+1].val);
283  }
284 
285 }
286 
287 
288 /*************************************************************************/
290 /*************************************************************************/
292 {
293  gk_idx_t i;
294  gk_idxkv_t array[N];
295 
296  /* test the increasing sort */
297  printf("Testing idxkvsorti...\n");
298  for (i=0; i<N; i++) {
299  array[i].key = RandomInRange(123432);
300  array[i].val = i;
301  }
302 
303  gk_idxkvsorti(N, array);
304 
305  for (i=0; i<N-1; i++) {
306  if (array[i].key > array[i+1].key)
307  printf("gk_idxkvsorti error at index %zd [%zd %zd] [%zd %zd]\n",
308  (ssize_t)i, (ssize_t)array[i].key, (ssize_t)array[i+1].key,
309  (ssize_t)array[i].val, (ssize_t)array[i+1].val);
310  }
311 
312 
313  /* test the decreasing sort */
314  printf("Testing idxkvsortd...\n");
315  for (i=0; i<N; i++) {
316  array[i].key = RandomInRange(123432);
317  array[i].val = i;
318  }
319 
320  gk_idxkvsortd(N, array);
321 
322  for (i=0; i<N-1; i++) {
323  if (array[i].key < array[i+1].key)
324  printf("gk_idxkvsortd error at index %zd [%zd %zd] [%zd %zd]\n",
325  (ssize_t)i, (ssize_t)array[i].key, (ssize_t)array[i+1].key,
326  (ssize_t)array[i].val, (ssize_t)array[i+1].val);
327  }
328 
329 }
330 
331 
332 
333 
334 int main()
335 {
336  test_isort();
337  test_fsort();
338  test_idxsort();
339 
340  test_ikvsort();
341  test_fkvsort();
342  test_dkvsort();
343  test_skvsort();
344  test_idxkvsort();
345 }
346 
const gtsam::Symbol key('X', 0)
void gk_isorti(size_t, int *)
Definition: sort.c:45
void gk_fkvsorti(size_t, gk_fkv_t *)
Definition: sort.c:245
ssize_t gk_idx_t
Definition: gk_types.h:22
void gk_ikvsorti(size_t, gk_ikv_t *)
Definition: sort.c:157
void gk_skvsortd(size_t, gk_skv_t *)
Definition: sort.c:300
void gk_fsorti(size_t, float *)
Definition: sort.c:67
Definition: numpy.h:680
void test_idxkvsort()
Definition: gksort.c:291
#define N
Definition: gksort.c:12
void gk_skvsorti(size_t, gk_skv_t *)
Definition: sort.c:289
void test_isort()
Definition: gksort.c:17
void gk_fkvsortd(size_t, gk_fkv_t *)
Definition: sort.c:256
void gk_idxsorti(size_t, gk_idx_t *)
Definition: sort.c:111
void test_fsort()
Definition: gksort.c:53
int64_t intmax_t
Definition: ms_stdint.h:128
void test_skvsort()
Definition: gksort.c:247
void gk_idxkvsorti(size_t, gk_idxkv_t *)
Definition: sort.c:311
void gk_ikvsortd(size_t, gk_ikv_t *)
Definition: sort.c:168
void test_idxsort()
Definition: gksort.c:89
char * gk_strdup(char *orgstr)
Duplicates a string.
Definition: string.c:372
void gk_fsortd(size_t, float *)
Definition: sort.c:78
int main()
Definition: gksort.c:334
#define RandomInRange(u)
Definition: gk_macros.h:24
void test_dkvsort()
Definition: gksort.c:207
void gk_idxkvsortd(size_t, gk_idxkv_t *)
Definition: sort.c:322
void gk_idxsortd(size_t, gk_idx_t *)
Definition: sort.c:122
void gk_dkvsortd(size_t, gk_dkv_t *)
Definition: sort.c:278
void test_ikvsort()
Definition: gksort.c:126
void gk_isortd(size_t, int *)
Definition: sort.c:56
void test_fkvsort()
Definition: gksort.c:167
void gk_dkvsorti(size_t, gk_dkv_t *)
Definition: sort.c:267


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:18