Removed PUBLIC and PRIVATE, corrected some examples and new test
This commit is contained in:
1 parent
a9b775419d
commit
0f84d65656
39 files changed
+322
-327
No files matched your search
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
#include "deque.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
DEQUE_GENERATE(d, deque, static, int)
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
#include "hashmap.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
HASHMAP_GENERATE(hm, hmap, static, int, double)
|
||||
|
||||
@@ -27,7 +26,7 @@ size_t inthash(int t)
|
||||
|
||||
int intcmp(int a, int b)
|
||||
{
|
||||
return a - b;
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
@@ -61,14 +60,14 @@ int main(int argc, char const *argv[])
|
||||
|
||||
for (hm_iter_to_start(&iter); !hm_iter_end(&iter); hm_iter_next(&iter))
|
||||
{
|
||||
printf("M[%2d] = { %2d : %2.2lf }\n", hm_iter_index(&iter), hm_iter_key(&iter), hm_iter_value(&iter));
|
||||
printf("HM[%2d] = { %2d : %2.2lf }\n", hm_iter_index(&iter), hm_iter_key(&iter), hm_iter_value(&iter));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (hm_iter_to_end(&iter); !hm_iter_start(&iter); hm_iter_prev(&iter))
|
||||
{
|
||||
printf("M[%2d] = { %2d : %2.2lf }\n", hm_iter_index(&iter), hm_iter_key(&iter), hm_iter_value(&iter));
|
||||
printf("HM[%2d] = { %2d : %2.2lf }\n", hm_iter_index(&iter), hm_iter_key(&iter), hm_iter_value(&iter));
|
||||
}
|
||||
|
||||
hm_free(hm);
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
#include "hashset.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
HASHSET_GENERATE(hs, hset, static, int)
|
||||
|
||||
@@ -27,12 +26,12 @@ size_t inthash(int t)
|
||||
|
||||
int intcmp(int a, int b)
|
||||
{
|
||||
return a - b;
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// Initialize hash set and add some elements
|
||||
// Initialize hashset and add some elements
|
||||
hset *hs = hs_new(10, 0.9, intcmp, inthash);
|
||||
for (int i = 0; i < 10; i++)
|
||||
hs_insert(hs, i);
|
||||
@@ -60,14 +59,14 @@ int main(int argc, char const *argv[])
|
||||
|
||||
for (hs_iter_to_start(&iter); !hs_iter_end(&iter); hs_iter_next(&iter))
|
||||
{
|
||||
printf("S[%2d] = %2d\n", hs_iter_index(&iter), hs_iter_value(&iter));
|
||||
printf("HS[%2d] = %2d\n", hs_iter_index(&iter), hs_iter_value(&iter));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (hs_iter_to_end(&iter); !hs_iter_start(&iter); hs_iter_prev(&iter))
|
||||
{
|
||||
printf("S[%2d] = %2d\n", hs_iter_index(&iter), hs_iter_value(&iter));
|
||||
printf("HS[%2d] = %2d\n", hs_iter_index(&iter), hs_iter_value(&iter));
|
||||
}
|
||||
|
||||
hs_free(hs);
|
||||
|
||||
@@ -9,11 +9,10 @@
|
||||
*/
|
||||
#include "heap.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int intcmp(int a, int b)
|
||||
{
|
||||
return a - b;
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
HEAP_GENERATE(h, heap, static, int)
|
||||
|
||||
@@ -9,20 +9,19 @@
|
||||
*/
|
||||
#include "linkedlist.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
LINKEDLIST_GENERATE(ll, linkedlist, static, int)
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
// Initialize list and add some elements
|
||||
linkedlist *l = ll_new();
|
||||
// Initialize linkedlist and add some elements
|
||||
linkedlist *ll = ll_new();
|
||||
for (int i = 0; i < 10; i++)
|
||||
ll_push_back(l, i);
|
||||
ll_push_back(ll, i);
|
||||
|
||||
// Initialize iterator
|
||||
linkedlist_iter iter;
|
||||
ll_iter_init(&iter, l);
|
||||
ll_iter_init(&iter, ll);
|
||||
|
||||
// Make the iterator go back and forward
|
||||
for (int j = 0; j < 4; j++)
|
||||
@@ -53,7 +52,7 @@ int main(int argc, char const *argv[])
|
||||
printf("LL[%2d] = %2d\n", ll_iter_index(&iter), ll_iter_value(&iter));
|
||||
}
|
||||
|
||||
ll_free(l);
|
||||
ll_free(ll);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
#include "list.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
LIST_GENERATE(l, list, static, int)
|
||||
|
||||
|
||||
+15
-15
@@ -7,17 +7,13 @@
|
||||
* Leonardo Vencovsky (https://github.com/LeoVen)
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "queue.h"
|
||||
#include <stdio.h>
|
||||
|
||||
QUEUE_GENERATE(q, queue, static, int)
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
size_t i;
|
||||
int r;
|
||||
|
||||
// Initialize queue and add some elements
|
||||
queue *q = q_new(10);
|
||||
for (int i = 0; i < 10; i++)
|
||||
@@ -30,26 +26,30 @@ int main(int argc, char const *argv[])
|
||||
// Make the iterator go back and forward
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
while (q_iter_next(&iter, &r, &i))
|
||||
printf("C[%2d] = %2d\n", i, r);
|
||||
while (!q_iter_end(&iter))
|
||||
{
|
||||
printf("C[%2d] = %2d\n", q_iter_index(&iter), q_iter_value(&iter));
|
||||
q_iter_next(&iter);
|
||||
}
|
||||
printf("\n");
|
||||
while (q_iter_prev(&iter, &r, &i))
|
||||
printf("C[%2d] = %2d\n", i, r);
|
||||
while (!q_iter_start(&iter))
|
||||
{
|
||||
printf("C[%2d] = %2d\n", q_iter_index(&iter), q_iter_value(&iter));
|
||||
q_iter_prev(&iter);
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
for (q_iter_tostart(&iter); !q_iter_end(&iter); /**/)
|
||||
for (q_iter_to_start(&iter); !q_iter_end(&iter); q_iter_next(&iter))
|
||||
{
|
||||
q_iter_next(&iter, &r, &i);
|
||||
printf("Q[%2d] = %2d\n", i, r);
|
||||
printf("Q[%2d] = %2d\n", q_iter_index(&iter), q_iter_value(&iter));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (q_iter_toend(&iter); !q_iter_start(&iter); /**/)
|
||||
for (q_iter_to_end(&iter); !q_iter_start(&iter); q_iter_prev(&iter))
|
||||
{
|
||||
q_iter_prev(&iter, &r, &i);
|
||||
printf("Q[%2d] = %2d\n", i, r);
|
||||
printf("Q[%2d] = %2d\n", q_iter_index(&iter), q_iter_value(&iter));
|
||||
}
|
||||
|
||||
q_free(q);
|
||||
|
||||
+15
-15
@@ -7,17 +7,13 @@
|
||||
* Leonardo Vencovsky (https://github.com/LeoVen)
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "stack.h"
|
||||
#include <stdio.h>
|
||||
|
||||
STACK_GENERATE(s, stack, static, int)
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
size_t i;
|
||||
int r;
|
||||
|
||||
// Initialize stack and add some elements
|
||||
stack *s = s_new(10);
|
||||
for (int i = 0; i < 10; i++)
|
||||
@@ -30,26 +26,30 @@ int main(int argc, char const *argv[])
|
||||
// Make the iterator go back and forward
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
while (s_iter_next(&iter, &r, &i))
|
||||
printf("C[%2d] = %2d\n", i, r);
|
||||
while (!s_iter_end(&iter))
|
||||
{
|
||||
printf("C[%2d] = %2d\n", s_iter_index(&iter), s_iter_value(&iter));
|
||||
s_iter_next(&iter);
|
||||
}
|
||||
printf("\n");
|
||||
while (s_iter_prev(&iter, &r, &i))
|
||||
printf("C[%2d] = %2d\n", i, r);
|
||||
while (!s_iter_start(&iter))
|
||||
{
|
||||
printf("C[%2d] = %2d\n", s_iter_index(&iter), s_iter_value(&iter));
|
||||
s_iter_prev(&iter);
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
for (s_iter_tostart(&iter); !s_iter_end(&iter); /**/)
|
||||
for (s_iter_to_start(&iter); !s_iter_end(&iter); s_iter_next(&iter))
|
||||
{
|
||||
s_iter_next(&iter, &r, &i);
|
||||
printf("S[%2d] = %2d\n", i, r);
|
||||
printf("S[%2d] = %2d\n", s_iter_index(&iter), s_iter_value(&iter));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (s_iter_toend(&iter); !s_iter_start(&iter); /**/)
|
||||
for (s_iter_to_end(&iter); !s_iter_start(&iter); s_iter_prev(&iter))
|
||||
{
|
||||
s_iter_prev(&iter, &r, &i);
|
||||
printf("S[%2d] = %2d\n", i, r);
|
||||
printf("S[%2d] = %2d\n", s_iter_index(&iter), s_iter_value(&iter));
|
||||
}
|
||||
|
||||
s_free(s);
|
||||
|
||||
@@ -7,58 +7,58 @@
|
||||
* Leonardo Vencovsky (https://github.com/LeoVen)
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "treemap.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int intcmp(int a, int b)
|
||||
{
|
||||
return a - b;
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
TREEMAP_GENERATE(tm, tmap, static, int, double)
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
size_t i;
|
||||
int k;
|
||||
double v, varr[10] = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9};
|
||||
double varr[10] = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9};
|
||||
|
||||
// Initialize treemap and add some element
|
||||
tmap *tm = tm_new(intcmp);
|
||||
tmap *hm = tm_new(intcmp);
|
||||
for (int i = 0; i < 10; i++)
|
||||
tm_insert(tm, i, varr[i]);
|
||||
tm_insert(hm, i, varr[i]);
|
||||
|
||||
// Initialize iterator
|
||||
tmap_iter iter;
|
||||
tm_iter_init(&iter, tm);
|
||||
tm_iter_init(&iter, hm);
|
||||
|
||||
// Make the iterator go back and forward
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
while (tm_iter_next(&iter, &k, &v, &i))
|
||||
printf("S[%2d] = { %2d : %2.2lf }\n", i, k, v);
|
||||
while (!tm_iter_end(&iter))
|
||||
{
|
||||
printf("C[%2d] = { %2d : %2.2lf }\n", tm_iter_index(&iter), tm_iter_key(&iter), tm_iter_value(&iter));
|
||||
tm_iter_next(&iter);
|
||||
}
|
||||
printf("\n");
|
||||
while (tm_iter_prev(&iter, &k, &v, &i))
|
||||
printf("S[%2d] = { %2d : %2.2lf }\n", i, k, v);
|
||||
while (!tm_iter_start(&iter))
|
||||
{
|
||||
printf("C[%2d] = { %2d : %2.2lf }\n", tm_iter_index(&iter), tm_iter_key(&iter), tm_iter_value(&iter));
|
||||
tm_iter_prev(&iter);
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
for (tm_iter_tostart(&iter); !tm_iter_end(&iter); /**/)
|
||||
for (tm_iter_to_start(&iter); !tm_iter_end(&iter); tm_iter_next(&iter))
|
||||
{
|
||||
tm_iter_next(&iter, &k, &v, &i);
|
||||
printf("M[%2d] = { %2d : %2.2lf }\n", i, k, v);
|
||||
printf("TM[%2d] = { %2d : %2.2lf }\n", tm_iter_index(&iter), tm_iter_key(&iter), tm_iter_value(&iter));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (tm_iter_toend(&iter); !tm_iter_start(&iter); /**/)
|
||||
for (tm_iter_to_end(&iter); !tm_iter_start(&iter); tm_iter_prev(&iter))
|
||||
{
|
||||
tm_iter_prev(&iter, &k, &v, &i);
|
||||
printf("M[%2d] = { %2d : %2.2lf }\n", i, k, v);
|
||||
printf("TM[%2d] = { %2d : %2.2lf }\n", tm_iter_index(&iter), tm_iter_key(&iter), tm_iter_value(&iter));
|
||||
}
|
||||
|
||||
tm_free(tm);
|
||||
tm_free(hm);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -7,22 +7,18 @@
|
||||
* Leonardo Vencovsky (https://github.com/LeoVen)
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "treeset.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int intcmp(int a, int b)
|
||||
{
|
||||
return a - b;
|
||||
return (a > b) - (a < b);
|
||||
}
|
||||
|
||||
TREESET_GENERATE(ts, tset, static, int)
|
||||
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
size_t i;
|
||||
int r;
|
||||
|
||||
// Initialize treeset and add some elements
|
||||
tset *ts = ts_new(intcmp);
|
||||
for (int i = 0; i < 10; i++)
|
||||
@@ -35,26 +31,30 @@ int main(int argc, char const *argv[])
|
||||
// Make the iterator go back and forward
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
while (ts_iter_next(&iter, &r, &i))
|
||||
printf("C[%2d] = %2d\n", i, r);
|
||||
while (!ts_iter_end(&iter))
|
||||
{
|
||||
printf("C[%2d] = %2d\n", ts_iter_index(&iter), ts_iter_value(&iter));
|
||||
ts_iter_next(&iter);
|
||||
}
|
||||
printf("\n");
|
||||
while (ts_iter_prev(&iter, &r, &i))
|
||||
printf("C[%2d] = %2d\n", i, r);
|
||||
while (!ts_iter_start(&iter))
|
||||
{
|
||||
printf("C[%2d] = %2d\n", ts_iter_index(&iter), ts_iter_value(&iter));
|
||||
ts_iter_prev(&iter);
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
for (ts_iter_tostart(&iter); !ts_iter_end(&iter); /**/)
|
||||
for (ts_iter_to_start(&iter); !ts_iter_end(&iter); ts_iter_next(&iter))
|
||||
{
|
||||
ts_iter_next(&iter, &r, &i);
|
||||
printf("S[%2d] = %2d\n", i, r);
|
||||
printf("TS[%2d] = %2d\n", ts_iter_index(&iter), ts_iter_value(&iter));
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
for (ts_iter_toend(&iter); !ts_iter_start(&iter); /**/)
|
||||
for (ts_iter_to_end(&iter); !ts_iter_start(&iter); ts_iter_prev(&iter))
|
||||
{
|
||||
ts_iter_prev(&iter, &r, &i);
|
||||
printf("S[%2d] = %2d\n", i, r);
|
||||
printf("TS[%2d] = %2d\n", ts_iter_index(&iter), ts_iter_value(&iter));
|
||||
}
|
||||
|
||||
ts_free(ts);
|
||||
|
||||
Reference in new issue
Block a user