summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/astar.c2
-rw-r--r--examples/bits2.c2
-rw-r--r--examples/books.c2
-rw-r--r--examples/complex.c2
-rw-r--r--examples/convert.c2
-rw-r--r--examples/cpque.c2
-rw-r--r--examples/csmap_erase.c2
-rw-r--r--examples/csmap_find.c10
-rw-r--r--examples/demos.c8
-rw-r--r--examples/inits.c2
-rw-r--r--examples/new_arr.c4
-rw-r--r--examples/new_pque.c4
-rw-r--r--examples/new_queue.c4
-rw-r--r--examples/queue.c2
-rw-r--r--examples/stack.c1
15 files changed, 25 insertions, 24 deletions
diff --git a/examples/astar.c b/examples/astar.c
index 4b86df9e..7d90bf35 100644
--- a/examples/astar.c
+++ b/examples/astar.c
@@ -88,7 +88,7 @@ astar(cstr* maze, int width)
point goal = point_from(maze, "!", width);
csmap_pcost_insert(&costs, start, 0);
cpque_point_push(&front, start);
- while (!cpque_point_empty(front))
+ while (!cpque_point_empty(&front))
{
point current = *cpque_point_top(&front);
cpque_point_pop(&front);
diff --git a/examples/bits2.c b/examples/bits2.c
index bb3324e3..73c18351 100644
--- a/examples/bits2.c
+++ b/examples/bits2.c
@@ -2,7 +2,7 @@
// Example of static sized (stack allocated) bitsets
#define i_type Bits
-#define i_len 80 // enable fixed bitset on the stack
+#define i_cap 80 // enable fixed bitset on the stack
#include <stc/cbits.h>
int main()
diff --git a/examples/books.c b/examples/books.c
index b2015208..fb9e4564 100644
--- a/examples/books.c
+++ b/examples/books.c
@@ -33,7 +33,7 @@ int main()
// queried using references (&str).
if (cmap_str_contains(&book_reviews, "Les Misérables")) {
printf("We've got %" PRIuMAX " reviews, but Les Misérables ain't one.",
- cmap_str_size(book_reviews));
+ cmap_str_size(&book_reviews));
}
// oops, this review has a lot of spelling mistakes, let's delete it.
diff --git a/examples/complex.c b/examples/complex.c
index 79a34a6a..c15d3bc7 100644
--- a/examples/complex.c
+++ b/examples/complex.c
@@ -42,7 +42,7 @@ int main() {
// Put in some data in stack array
stack.data[x] = 3.1415927f;
- printf("stack size: %" PRIuMAX "\n", FloatStack_size(stack));
+ printf("stack size: %" PRIuMAX "\n", FloatStack_size(&stack));
StackList list = StackList_init();
StackList_push_back(&list, stack);
diff --git a/examples/convert.c b/examples/convert.c
index c1380c94..56cd1eca 100644
--- a/examples/convert.c
+++ b/examples/convert.c
@@ -36,7 +36,7 @@ int main()
cvec_str_emplace_back(&keys, cstr_str(&i.ref->first));
cvec_str_emplace_back(&values, cstr_str(&i.ref->second));
}
- c_forrange (i, cvec_str_size(keys))
+ c_forrange (i, cvec_str_size(&keys))
printf(" %s: %s\n", cstr_str(keys.data + i), cstr_str(values.data + i));
puts("\nCOPY VEC TO LIST:");
diff --git a/examples/cpque.c b/examples/cpque.c
index 2c08f796..00d2697e 100644
--- a/examples/cpque.c
+++ b/examples/cpque.c
@@ -13,7 +13,7 @@ static bool (*less_fn)(const int* x, const int* y);
void print_queue(ipque q) {
ipque copy = ipque_clone(q);
- while (!ipque_empty(copy)) {
+ while (!ipque_empty(&copy)) {
printf("%d ", *ipque_top(&copy));
ipque_pop(&copy);
}
diff --git a/examples/csmap_erase.c b/examples/csmap_erase.c
index 09d28d78..37d25f37 100644
--- a/examples/csmap_erase.c
+++ b/examples/csmap_erase.c
@@ -12,7 +12,7 @@ void printmap(mymap m)
{
c_foreach (elem, mymap, m)
printf(" [%d, %s]", elem.ref->first, cstr_str(&elem.ref->second));
- printf("\nsize() == %" PRIuMAX "\n\n", mymap_size(m));
+ printf("\nsize() == %" PRIuMAX "\n\n", mymap_size(&m));
}
int main()
diff --git a/examples/csmap_find.c b/examples/csmap_find.c
index c3047110..f74f7fb9 100644
--- a/examples/csmap_find.c
+++ b/examples/csmap_find.c
@@ -17,10 +17,10 @@ void print_elem(csmap_istr_raw p) {
}
#define using_print_collection(CX) \
- void print_collection_##CX(CX t) { \
+ void print_collection_##CX(const CX* t) { \
printf("%" PRIuMAX " elements: ", CX##_size(t)); \
\
- c_foreach (p, CX, t) { \
+ c_foreach (p, CX, *t) { \
print_elem(CX##_value_toraw(p.ref)); \
} \
puts(""); \
@@ -48,7 +48,7 @@ int main()
c_apply(v, csmap_istr_emplace(&m1, c_pair(v)), csmap_istr_raw,
{{40, "Zr"}, {45, "Rh"}});
puts("The starting map m1 is (key, value):");
- print_collection_csmap_istr(m1);
+ print_collection_csmap_istr(&m1);
typedef cvec_istr_value pair;
cvec_istr_push_back(&v, (pair){43, "Tc"});
@@ -59,13 +59,13 @@ int main()
cvec_istr_push_back(&v, (pair){44, "Ru"}); // attempt a duplicate
puts("Inserting the following vector data into m1:");
- print_collection_cvec_istr(v);
+ print_collection_cvec_istr(&v);
c_foreach (i, cvec_istr, cvec_istr_begin(&v), cvec_istr_end(&v))
csmap_istr_emplace(&m1, c_pair(i.ref));
puts("The modified map m1 is (key, value):");
- print_collection_csmap_istr(m1);
+ print_collection_csmap_istr(&m1);
puts("");
findit(m1, 45);
findit(m1, 6);
diff --git a/examples/demos.c b/examples/demos.c
index 7c5b9a4b..4cb50082 100644
--- a/examples/demos.c
+++ b/examples/demos.c
@@ -47,7 +47,7 @@ void vectordemo1()
cvec_ix_pop_back(&bignums); // erase the last
cvec_ix_erase_n(&bignums, 0, 1); // erase the first
- for (size_t i = 0; i < cvec_ix_size(bignums); ++i) {
+ for (size_t i = 0; i < cvec_ix_size(&bignums); ++i) {
printf("%" PRIuMAX ": %" PRIuMAX "\n", i, bignums.data[i]);
}
}
@@ -175,11 +175,11 @@ void mapdemo3()
cmap_str_iter it = cmap_str_find(&table, "Make");
c_foreach (i, cmap_str, table)
printf("entry: %s: %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second));
- printf("size %" PRIuMAX ": remove: Make: %s\n", cmap_str_size(table), cstr_str(&it.ref->second));
+ printf("size %" PRIuMAX ": remove: Make: %s\n", cmap_str_size(&table), cstr_str(&it.ref->second));
//cmap_str_erase(&table, "Make");
cmap_str_erase_at(&table, it);
- printf("size %" PRIuMAX "\n", cmap_str_size(table));
+ printf("size %" PRIuMAX "\n", cmap_str_size(&table));
c_foreach (i, cmap_str, table)
printf("entry: %s: %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second));
cmap_str_drop(&table); // frees key and value cstrs, and hash table.
@@ -200,7 +200,7 @@ void arraydemo1()
float *arr1 = arr3.data[5][4];
printf("arr3: %" PRIuMAX ": (%" PRIuMAX ", %" PRIuMAX ", %" PRIuMAX ") = %" PRIuMAX "\n", sizeof(arr3),
- arr3.xdim, arr3.ydim, arr3.zdim, carr3_f_size(arr3));
+ arr3.xdim, arr3.ydim, arr3.zdim, carr3_f_size(&arr3));
printf("%g\n", arr1[3]); // = 10.2
printf("%g\n", arr2[4][3]); // = 10.2
diff --git a/examples/inits.c b/examples/inits.c
index dc67075c..608dd146 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -44,7 +44,7 @@ int main(void)
c_apply_array(v, cpque_f_push(&floats, *v), const float, nums, c_arraylen(nums));
puts("\npop and show high priorites first:");
- while (! cpque_f_empty(floats)) {
+ while (! cpque_f_empty(&floats)) {
printf("%.1f ", *cpque_f_top(&floats));
cpque_f_pop(&floats);
}
diff --git a/examples/new_arr.c b/examples/new_arr.c
index 8ccc62fa..17a96062 100644
--- a/examples/new_arr.c
+++ b/examples/new_arr.c
@@ -17,7 +17,7 @@ int main()
carr2_int_drop(&volume))
{
int *dat = carr2_int_data(&volume);
- for (size_t i = 0; i < carr2_int_size(volume); ++i)
+ for (size_t i = 0; i < carr2_int_size(&volume); ++i)
dat[i] = i;
for (size_t x = 0; x < volume.xdim; ++x)
@@ -34,7 +34,7 @@ int main()
carr3_int_drop(&volume))
{
int *dat = carr3_int_data(&volume);
- for (size_t i = 0; i < carr3_int_size(volume); ++i)
+ for (size_t i = 0; i < carr3_int_size(&volume); ++i)
dat[i] = i;
for (size_t x = 0; x < volume.xdim; ++x)
diff --git a/examples/new_pque.c b/examples/new_pque.c
index 2e5cf9ca..1f968f4c 100644
--- a/examples/new_pque.c
+++ b/examples/new_pque.c
@@ -46,7 +46,7 @@ int main()
cpque_pnt_push(&pque, (Point){54, 74});
cpque_pnt_push(&pque, (Point){12, 62});
// print
- while (!cpque_pnt_empty(pque)) {
+ while (!cpque_pnt_empty(&pque)) {
cpque_pnt_value *v = cpque_pnt_top(&pque);
printf(" (%d,%d)", v->x, v->y);
cpque_pnt_pop(&pque);
@@ -58,7 +58,7 @@ int main()
cpque_int_push(&ique, 123);
cpque_int_push(&ique, 321);
// print
- for (size_t i=0; i<cpque_int_size(ique); ++i)
+ for (size_t i=0; i<cpque_int_size(&ique); ++i)
printf(" %d", ique.data[i]);
puts("");
}
diff --git a/examples/new_queue.c b/examples/new_queue.c
index f3051871..ea68c9b9 100644
--- a/examples/new_queue.c
+++ b/examples/new_queue.c
@@ -31,7 +31,7 @@ int main() {
cqueue_int_push(&Q, stc64_uniform(&rng, &dist));
// Push or pop on the queue ten million times
- printf("befor: size %" PRIuMAX ", capacity %" PRIuMAX "\n", cqueue_int_size(Q), cqueue_int_capacity(Q));
+ printf("befor: size %" PRIuMAX ", capacity %" PRIuMAX "\n", cqueue_int_size(&Q), cqueue_int_capacity(&Q));
for (int i=n; i>0; --i) {
int r = stc64_uniform(&rng, &dist);
if (r & 1)
@@ -39,6 +39,6 @@ int main() {
else
cqueue_int_pop(&Q);
}
- printf("after: size %" PRIuMAX ", capacity %" PRIuMAX "\n", cqueue_int_size(Q), cqueue_int_capacity(Q));
+ printf("after: size %" PRIuMAX ", capacity %" PRIuMAX "\n", cqueue_int_size(&Q), cqueue_int_capacity(&Q));
}
}
diff --git a/examples/queue.c b/examples/queue.c
index cfc8d988..cc6f8302 100644
--- a/examples/queue.c
+++ b/examples/queue.c
@@ -26,6 +26,6 @@ int main() {
else
--n, cqueue_i_pop(&queue);
}
- printf("%d, %" PRIuMAX "\n", n, cqueue_i_size(queue));
+ printf("%d, %" PRIuMAX "\n", n, cqueue_i_size(&queue));
}
}
diff --git a/examples/stack.c b/examples/stack.c
index ca809c97..1991e269 100644
--- a/examples/stack.c
+++ b/examples/stack.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#define i_tag i
+#define i_cap 100
#define i_val int
#include <stc/cstack.h>