diff options
| author | Tyge Løvset <[email protected]> | 2020-09-24 16:58:37 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-09-24 16:58:37 +0200 |
| commit | 3be928828630984f4ff2c5cf352ace1366c52341 (patch) | |
| tree | c72decd6ee5d3bcd19013eb56c816759ce908ca8 | |
| parent | bad270ce0034ffbd237bc9ac4a407b0cfe6b1088 (diff) | |
| download | STC-modified-3be928828630984f4ff2c5cf352ace1366c52341.tar.gz STC-modified-3be928828630984f4ff2c5cf352ace1366c52341.zip | |
Changed iter.get to iter.val member. Internal, but used external. Will not change again.
| -rw-r--r-- | README.md | 22 | ||||
| -rw-r--r-- | examples/README.md | 2 | ||||
| -rw-r--r-- | examples/advanced.c | 2 | ||||
| -rw-r--r-- | examples/benchmark.c | 2 | ||||
| -rw-r--r-- | examples/birthday.c | 4 | ||||
| -rw-r--r-- | examples/demos.c | 26 | ||||
| -rw-r--r-- | examples/ex_gaussian.c | 6 | ||||
| -rw-r--r-- | examples/inits.c | 10 | ||||
| -rw-r--r-- | examples/list.c | 12 | ||||
| -rw-r--r-- | examples/mapmap.c | 4 | ||||
| -rw-r--r-- | examples/phonebook.c | 2 | ||||
| -rw-r--r-- | examples/shared_ptr.c | 16 | ||||
| -rw-r--r-- | examples/stack.c | 2 | ||||
| -rw-r--r-- | examples/words.c | 10 | ||||
| -rw-r--r-- | stc/carray.h | 6 | ||||
| -rw-r--r-- | stc/cbitset.h | 6 | ||||
| -rw-r--r-- | stc/cdefs.h | 4 | ||||
| -rw-r--r-- | stc/clist.h | 30 | ||||
| -rw-r--r-- | stc/cmap.h | 20 | ||||
| -rw-r--r-- | stc/csptr.h | 3 | ||||
| -rw-r--r-- | stc/cstr.h | 6 | ||||
| -rw-r--r-- | stc/cvec.h | 20 |
22 files changed, 113 insertions, 102 deletions
@@ -179,7 +179,7 @@ int main() { bignums.data[i] /= i; // make them smaller
c_foreach (i, cvec_ix, bignums)
- printf(" %d", *i.get);
+ printf(" %d", *i.val);
cvec_ix_del(&bignums);
}
// Output:
@@ -205,7 +205,7 @@ int main() { printf("%s\n", names.data[1].str); // Access the second element
c_foreach (i, cvec_str, names)
- printf("item: %s\n", i.get->str);
+ printf("item: %s\n", i.val->str);
cvec_str_del(&names);
}
// Output:
@@ -276,7 +276,7 @@ int main() { printf("size = %zu\n", cmap_str_size(strings));
c_foreach (i, cmap_str, strings)
- printf("%s: %s\n", i.get->first.str, i.get->second.str);
+ printf("%s: %s\n", i.val->first.str, i.val->second.str);
cmap_str_del(&strings); // frees all strings and map.
}
// Output:
@@ -305,7 +305,7 @@ int main() { // iterate the set of cstr_t values:
c_foreach (i, cset_str, words)
- printf("%s ", i.get->str);
+ printf("%s ", i.val->str);
cset_str_del(&words);
}
// Output:
@@ -331,13 +331,13 @@ int main() { printf("initial: ");
c_foreach (i, clist_fx, list)
- printf(" %g", *i.get);
+ printf(" %g", *i.val);
clist_fx_sort(&list); // mergesort O(n*log n)
printf("\nsorted: ");
c_foreach (i, clist_fx, list)
- printf(" %g", *i.get);
+ printf(" %g", *i.val);
clist_fx_del(&list);
}
@@ -395,7 +395,7 @@ int main() { cqueue_i_pop(&queue);
c_foreach (i, cqueue_i, queue)
- printf(" %d", *i.get);
+ printf(" %d", *i.val);
cqueue_i_del(&queue);
}
@@ -517,7 +517,7 @@ cvec_mi make_normal_dist(crand_rng64_t* rng, crand_normal_f64_t* dist, int n) // Transfer cmap entries to a cvec, sort and return it.
cvec_mi hist = cvec_INIT;
c_foreach (i, cmap_ii, mhist) {
- cvec_mi_push_back(&hist, *i.get);
+ cvec_mi_push_back(&hist, *i.val);
}
cvec_mi_sort(&hist);
cmap_ii_del(&mhist);
@@ -529,12 +529,12 @@ void display_hist(cvec_mi hist, int scale, int mean, int stddev) cstr_t bar = cstr_INIT;
int n = 0; // samples
c_foreach (i, cvec_mi, hist)
- n += i.get->second;
+ n += i.val->second;
c_foreach (i, cvec_mi, hist) {
- int k = (int) (i.get->second * stddev * scale * 25ull / 10 / n);
+ int k = (int) (i.val->second * stddev * scale * 25ull / 10 / n);
if (k > 0) {
cstr_take(&bar, cstr_with_size(k, '*'));
- printf("%4d %s\n", i.get->first, bar.str);
+ printf("%4d %s\n", i.val->first, bar.str);
}
}
printf("Normal distribution with mean=%d, stddev=%d. '*' = %.0f samples out of %d.\n",
diff --git a/examples/README.md b/examples/README.md index fd5cd92b..ba6a7cfb 100644 --- a/examples/README.md +++ b/examples/README.md @@ -72,7 +72,7 @@ int main() { cmap_vk_emplace(&vikings, look, 0)->second += 5; // update again
c_foreach (k, cmap_vk, vikings) {
- printf("%s of %s has %d hp\n", k.get->first.name.str, k.get->first.country.str, k.get->second);
+ printf("%s of %s has %d hp\n", k.val->first.name.str, k.val->first.country.str, k.val->second);
}
cmap_vk_del(&vikings);
}
diff --git a/examples/advanced.c b/examples/advanced.c index 7cf55d2c..8c3564f3 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -74,7 +74,7 @@ int main() cmap_vk_emplace(&vikings, einar, 0).first->second += 5; // again c_foreach (k, cmap_vk, vikings) { - printf("%s of %s has %d hp\n", k.get->first.name.str, k.get->first.country.str, k.get->second); + printf("%s of %s has %d hp\n", k.val->first.name.str, k.val->first.country.str, k.val->second); } cmap_vk_del(&vikings); } diff --git a/examples/benchmark.c b/examples/benchmark.c index d1167eb4..dd0001a7 100644 --- a/examples/benchmark.c +++ b/examples/benchmark.c @@ -41,7 +41,7 @@ crand_rng64_t rng; #define CMAP_ERASE(X, key) cmap_##X##_erase(&map, key)
#define CMAP_FIND(X, key) (cmap_##X##_find(map, key) != NULL)
#define CMAP_FOR(X, i) c_foreach (i, cmap_##X, map)
-#define CMAP_ITEM(X, i) i.get->second
+#define CMAP_ITEM(X, i) i.val->second
#define CMAP_SIZE(X) cmap_size(map)
#define CMAP_BUCKETS(X) cmap_##X##_bucket_count(map)
#define CMAP_CLEAR(X) cmap_##X##_clear(&map)
diff --git a/examples/birthday.c b/examples/birthday.c index fae36430..92423b7b 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -46,11 +46,11 @@ void distribution(void) float diff = (float) (clock() - now) / CLOCKS_PER_SEC;
uint64_t sum = 0;
- c_foreach (i, cmap_x, map) sum += i.get->second;
+ c_foreach (i, cmap_x, map) sum += i.val->second;
sum /= map.size;
c_foreach (i, cmap_x, map)
- printf("%u: %zu - %zu\n", i.get->first, i.get->second, sum);
+ printf("%u: %zu - %zu\n", i.val->first, i.val->second, sum);
printf("%.02f\n", diff);
}
diff --git a/examples/demos.c b/examples/demos.c index 85d96e7e..1955d229 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -69,7 +69,7 @@ void vectordemo2() cvec_str_sort(&names); // Sort the array
c_foreach (i, cvec_str, names)
- printf("sorted: %s\n", i.get->str);
+ printf("sorted: %s\n", i.val->str);
cvec_str_del(&names);
}
@@ -84,19 +84,19 @@ void listdemo1() for (int i = 100; i < 110; ++i)
clist_ix_push_back(&nums2, i);
c_foreach (i, clist_ix, nums)
- printf("value: %d\n", *i.get);
+ printf("value: %d\n", *i.val);
/* merge/append nums2 to nums */
clist_ix_splice_front(&nums, &nums2);
c_foreach (i, clist_ix, nums)
- printf("spliced: %d\n", *i.get);
+ printf("spliced: %d\n", *i.val);
- *clist_ix_find(&nums, 100).get *= 10;
+ *clist_ix_find(&nums, 100).val *= 10;
clist_ix_sort(&nums); // Sort the array
clist_ix_remove(&nums, 105);
clist_ix_pop_front(&nums);
clist_ix_push_front(&nums, -99);
c_foreach (i, clist_ix, nums)
- printf("sorted: %d\n", *i.get);
+ printf("sorted: %d\n", *i.val);
clist_ix_del(&nums);
}
@@ -110,7 +110,7 @@ void setdemo1() cset_i_insert(&nums, 11);
c_foreach (i, cset_i, nums)
- printf("set: %d\n", *i.get);
+ printf("set: %d\n", *i.val);
cset_i_del(&nums);
}
@@ -123,7 +123,7 @@ void mapdemo1() cmap_ii nums = cmap_INIT;
cmap_ii_put(&nums, 8, 64);
cmap_ii_put(&nums, 11, 121);
- printf("get 8: %d\n", *cmap_ii_at(&nums, 8));
+ printf("val 8: %d\n", *cmap_ii_at(&nums, 8));
cmap_ii_del(&nums);
}
@@ -139,12 +139,12 @@ void mapdemo2() cmap_si_put(&nums, "Groovy", 200); // overwrite previous
// iterate the map:
- for (cmap_si_iter_t i = cmap_si_begin(&nums); i.get != cmap_si_end(&nums).get; cmap_si_next(&i))
- printf("long: %s: %d\n", i.get->first.str, i.get->second);
+ for (cmap_si_iter_t i = cmap_si_begin(&nums); i.val != cmap_si_end(&nums).val; cmap_si_next(&i))
+ printf("long: %s: %d\n", i.val->first.str, i.val->second);
// or rather use the short form:
c_foreach (i, cmap_si, nums)
- printf("short: %s: %d\n", i.get->first.str, i.get->second);
+ printf("short: %s: %d\n", i.val->first.str, i.val->second);
cmap_si_del(&nums);
}
@@ -161,13 +161,13 @@ void mapdemo3() cmap_str_put(&table, "Sunny", "day");
cmap_str_value_t *e = cmap_str_find(&table, "Make");
c_foreach (i, cmap_str, table)
- printf("entry: %s: %s\n", i.get->first.str, i.get->second.str);
+ printf("entry: %s: %s\n", i.val->first.str, i.val->second.str);
printf("size %zu: remove: Make: %s\n", cmap_size(table), e->second.str);
cmap_str_erase(&table, "Make");
printf("size %zu\n", cmap_size(table));
c_foreach (i, cmap_str, table)
- printf("entry: %s: %s\n", i.get->first.str, i.get->second.str);
+ printf("entry: %s: %s\n", i.val->first.str, i.val->second.str);
cmap_str_del(&table); // frees key and value cstrs, and hash table.
}
@@ -190,7 +190,7 @@ void arraydemo1() printf("%f\n", *carray3f_at(&a3, 5, 4, 3)); // lookup a3[5][4][3] (=10.2f)
c_foreach (i, carray3f, a3)
- *i.get = 1.0f;
+ *i.val = 1.0f;
printf("%f\n", *carray3f_at(&a3, 29, 19, 9));
carray2f_del(&a2); // does nothing, since it is a sub-array.
diff --git a/examples/ex_gaussian.c b/examples/ex_gaussian.c index e5dad57a..1ff494f5 100644 --- a/examples/ex_gaussian.c +++ b/examples/ex_gaussian.c @@ -38,17 +38,17 @@ int main() // Transfer map to vec and sort it by map keys.
cvec_e vhist = cvec_INIT;
c_foreach (i, cmap_i, mhist)
- cvec_e_push_back(&vhist, *i.get);
+ cvec_e_push_back(&vhist, *i.val);
cvec_e_sort(&vhist);
// Print the gaussian bar chart
cstr_t bar = cstr_INIT;
c_foreach (i, cvec_e, vhist) {
- size_t n = (size_t) (i.get->second * Mag / N);
+ size_t n = (size_t) (i.val->second * Mag / N);
if (n > 0) {
// bar string: take ownership in new str after freeing current.
cstr_take(&bar, cstr_with_size(n, '*'));
- printf("%4d %s\n", i.get->first, bar.str);
+ printf("%4d %s\n", i.val->first, bar.str);
}
}
// Cleanup
diff --git a/examples/inits.c b/examples/inits.c index 27ee3c9b..26a05a51 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -26,7 +26,7 @@ int main(void) cvec_f floats = cvec_INIT;
c_push_items(&floats, cvec_f, {4.0f, 2.0f, 5.0f, 3.0f, 1.0f});
- c_foreach (i, cvec_f, floats) printf("%.1f ", *i.get);
+ c_foreach (i, cvec_f, floats) printf("%.1f ", *i.val);
puts("");
// CVEC PRIORITY QUEUE
@@ -53,7 +53,7 @@ int main(void) });
c_foreach (i, cmap_id, idnames)
- printf("%d: %s\n", i.get->first, i.get->second.str);
+ printf("%d: %s\n", i.val->first, i.val->second.str);
puts("");
cmap_id_del(&idnames);
@@ -76,7 +76,7 @@ int main(void) cmap_cnt_emplace(&countries, "Finland", 0).first->second += 20;
c_foreach (i, cmap_cnt, countries)
- printf("%s: %d\n", i.get->first.str, i.get->second);
+ printf("%s: %d\n", i.val->first.str, i.val->second);
puts("");
cmap_cnt_del(&countries);
@@ -92,7 +92,7 @@ int main(void) cvec_ip_sort(&pairs1);
c_foreach (i, cvec_ip, pairs1)
- printf("(%d %d) ", i.get->x, i.get->y);
+ printf("(%d %d) ", i.val->x, i.val->y);
puts("");
cvec_ip_del(&pairs1);
@@ -108,7 +108,7 @@ int main(void) clist_ip_sort(&pairs2);
c_foreach (i, clist_ip, pairs2)
- printf("(%d %d) ", i.get->x, i.get->y);
+ printf("(%d %d) ", i.val->x, i.val->y);
puts("");
clist_ip_del(&pairs2);
}
\ No newline at end of file diff --git a/examples/list.c b/examples/list.c index e3e68ee4..2cc433c6 100644 --- a/examples/list.c +++ b/examples/list.c @@ -17,24 +17,24 @@ int main() { double sum = 0.0;
printf("sumarize %d:\n", m);
c_foreach (i, clist_fx, list)
- sum += *i.get;
+ sum += *i.val;
printf("sum %f\n\n", sum);
k = 0;
c_foreach (i, clist_fx, list)
- if (++k <= 10) printf("%8d: %10f\n", k, *i.get); else break;
+ if (++k <= 10) printf("%8d: %10f\n", k, *i.val); else break;
puts("sort");
clist_fx_sort(&list); // mergesort O(n*log n)
puts("sorted");
k = 0;
c_foreach (i, clist_fx, list)
- if (++k <= 10) printf("%8d: %10f\n", k, *i.get); else break;
+ if (++k <= 10) printf("%8d: %10f\n", k, *i.val); else break;
puts("");
clist_fx_clear(&list);
c_push_items(&list, clist_fx, {10, 20, 30, 40, 30, 50});
- c_foreach (i, clist_fx, list) printf(" %g", *i.get);
+ c_foreach (i, clist_fx, list) printf(" %g", *i.val);
puts("");
int removed = clist_fx_remove(&list, 30);
@@ -44,11 +44,11 @@ int main() { clist_fx_iter_t it = clist_fx_before_begin(&list);
printf("Full: ");
c_foreach (i, clist_fx, list)
- printf(" %g", *i.get);
+ printf(" %g", *i.val);
for (int i=0; i<4; ++i) clist_fx_next(&it);
printf("\nSubs: ");
c_foreach (i, clist_fx, it, clist_fx_end(&list))
- printf(" %g", *i.get);
+ printf(" %g", *i.val);
puts("");
clist_fx_del(&list);
}
\ No newline at end of file diff --git a/examples/mapmap.c b/examples/mapmap.c index 38e88712..6800601f 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -19,8 +19,8 @@ int main(void) { cmap_str_put(&cmap_cfg_emplace(&config, "group", init).first->second, "proj2", "Wind"); // Update
c_foreach (i, cmap_cfg, config)
- c_foreach (j, cmap_str, i.get->second)
- printf("%s: %s - %s (%u)\n", i.get->first.str, j.get->first.str, j.get->second.str, i.get->second.bucket_count);
+ c_foreach (j, cmap_str, i.val->second)
+ printf("%s: %s - %s (%u)\n", i.val->first.str, j.val->first.str, j.val->second.str, i.val->second.bucket_count);
cmap_cfg_del(&config);
}
\ No newline at end of file diff --git a/examples/phonebook.c b/examples/phonebook.c index 90d2fe22..cb7130c1 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -30,7 +30,7 @@ using_cmap_str(); void print_phone_book(cmap_str phone_book)
{
c_foreach (i, cmap_str, phone_book)
- printf("%s\t- %s\n", i.get->first.str, i.get->second.str);
+ printf("%s\t- %s\n", i.val->first.str, i.val->second.str);
}
int main(int argc, char **argv)
diff --git a/examples/shared_ptr.c b/examples/shared_ptr.c index 40f67e11..7bff502c 100644 --- a/examples/shared_ptr.c +++ b/examples/shared_ptr.c @@ -5,16 +5,26 @@ typedef struct { cstr_t name, last; } Person;
+Person* Person_make(Person* p, const char* name, const char* last) {
+ p->name = cstr(name), p->last = cstr(last);
+ return p;
+}
void Person_del(Person* p) {
printf("del %s\n", p->name.str);
- cstr_del(&p->name); cstr_del(&p->last);
+ c_del(cstr, &p->name, &p->last);
+}
+int Person_compare(const Person* p, const Person* q) {
+ int cmp = cstr_equals_s(p->name, q->name);
+ return cmp == 0 ? cstr_equals_s(p->last, q->last) : cmp;
}
//using_clist(p, Person, Person_del);
//using_cqueue(p, clist_p);
using_csptr(p, Person, Person_del);
-using_clist(pp, csptr_p, csptr_p_del);
+int csptr_p_compare(const csptr_p* p, const csptr_p* q) {return Person_compare(p->get, q->get);}
+
+using_clist(pp, csptr_p, csptr_p_del, csptr_p_compare);
using_cqueue(pp, clist_pp);
int main() {
@@ -32,7 +42,7 @@ int main() { cqueue_pp_pop(&queue);
c_foreach (i, cqueue_pp, queue)
- printf(" %s %s\n", i.get->get->name.str, i.get->get->last.str);
+ printf(" %s %s\n", i.val->get->name.str, i.val->get->last.str);
cqueue_pp_del(&queue);
}
\ No newline at end of file diff --git a/examples/stack.c b/examples/stack.c index 68519a9b..f65b9243 100644 --- a/examples/stack.c +++ b/examples/stack.c @@ -21,7 +21,7 @@ int main() { cstack_i_pop(&stack);
c_foreach (i, cstack_i, stack)
- printf(" %d", *i.get);
+ printf(" %d", *i.val);
puts("");
printf("top: %d\n", *cstack_i_top(&stack));
}
\ No newline at end of file diff --git a/examples/words.c b/examples/words.c index c5b513bf..f95c36eb 100644 --- a/examples/words.c +++ b/examples/words.c @@ -18,7 +18,7 @@ int main1() }); clist_str_push_back(&lwords, cstr_from("%f", 123897.0 / 23.0)); c_foreach (w, clist_str, lwords) - printf("%s\n", w.get->str); + printf("%s\n", w.val->str); puts(""); cvec_str words = cvec_INIT; @@ -29,12 +29,10 @@ int main1() cmap_si word_map = cmap_INIT; c_foreach (w, cvec_str, words) - cmap_si_emplace(&word_map, w.get->str, 0).first->second += 1; + cmap_si_emplace(&word_map, w.val->str, 0).first->second += 1; - c_foreach (pair, cmap_si, word_map) { - printf("%d occurrences of word '%s'\n", - pair.get->second, - pair.get->first.str); + c_foreach (i, cmap_si, word_map) { + printf("%d occurrences of word '%s'\n", i.val->second, i.val->first.str); } cmap_si_del(&word_map); diff --git a/stc/carray.h b/stc/carray.h index 3fd7f532..4808307d 100644 --- a/stc/carray.h +++ b/stc/carray.h @@ -69,7 +69,7 @@ STC_INLINE size_t _carray3_size(const size_t* zdim) { #define using_carray_common(D, X, Value, valueDestroy) \
- typedef struct { Value *get; } carray##D##X##_iter_t; \
+ typedef struct { Value *val; } carray##D##X##_iter_t; \
\
STC_INLINE carray##D##X##_iter_t \
carray##D##X##_begin(carray##D##X* a) { \
@@ -80,13 +80,13 @@ STC_INLINE size_t _carray3_size(const size_t* zdim) { carray##D##X##_iter_t it = {a->data + carray##D##_size(*a)}; return it; \
} \
STC_INLINE void \
- carray##D##X##_next(carray##D##X##_iter_t* it) {++it->get;} \
+ carray##D##X##_next(carray##D##X##_iter_t* it) {++it->val;} \
\
STC_INLINE void \
carray##D##X##_del(carray##D##X* self) { \
if (self->_xdim & _carray_OWN) { \
c_foreach_3 (i, carray##D##X, *self) \
- valueDestroy(i.get); \
+ valueDestroy(i.val); \
c_free(self->data); \
} \
}
diff --git a/stc/cbitset.h b/stc/cbitset.h index e2fb9db2..859865a2 100644 --- a/stc/cbitset.h +++ b/stc/cbitset.h @@ -148,7 +148,7 @@ STC_INLINE cbitset_t cbitset_not(cbitset_t s1) { typedef struct {
cbitset_t *_bs;
- size_t get;
+ size_t val;
} cbitset_iter_t;
STC_INLINE cbitset_iter_t
@@ -160,10 +160,10 @@ cbitset_end(cbitset_t* self) { cbitset_iter_t it = {self, self->size}; return it;
}
STC_INLINE void
-cbitset_next(cbitset_iter_t* it) {++it->get;}
+cbitset_next(cbitset_iter_t* it) {++it->val;}
STC_INLINE bool cbitset_itval(cbitset_iter_t it) {
- return cbitset_test(*it._bs, it.get);
+ return cbitset_test(*it._bs, it.val);
}
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
diff --git a/stc/cdefs.h b/stc/cdefs.h index 7034f304..8328c837 100644 --- a/stc/cdefs.h +++ b/stc/cdefs.h @@ -81,9 +81,9 @@ enum {_c_max_buffer = 512}; #define c_foreach(...) c_MACRO_OVERLOAD(c_foreach, __VA_ARGS__)
#define c_foreach_3(it, ctype, cnt) \
- for (ctype##_iter_t it = ctype##_begin(&cnt), it##_end_ = ctype##_end(&cnt); it.get != it##_end_.get; ctype##_next(&it))
+ for (ctype##_iter_t it = ctype##_begin(&cnt), it##_end_ = ctype##_end(&cnt); it.val != it##_end_.val; ctype##_next(&it))
#define c_foreach_4(it, ctype, start, finish) \
- for (ctype##_iter_t it = start, it##_end_ = finish; it.get != it##_end_.get; ctype##_next(&it))
+ for (ctype##_iter_t it = start, it##_end_ = finish; it.val != it##_end_.val; ctype##_next(&it))
#define c_forrange(...) c_MACRO_OVERLOAD(c_forrange, __VA_ARGS__)
#define c_forrange_1(stop) for (size_t _c_i=0, _c_end_=stop; _c_i < _c_end_; ++_c_i)
diff --git a/stc/clist.h b/stc/clist.h index 69523dc0..9483e0f4 100644 --- a/stc/clist.h +++ b/stc/clist.h @@ -45,13 +45,13 @@ clist_ix_push_back(&list, crand_i32(&pcg));
n = 0;
c_foreach (i, clist_ix, list)
- if (++n % 10000 == 0) printf("%8d: %10zd\n", n, i.get->value);
+ if (++n % 10000 == 0) printf("%8d: %10zd\n", n, i.val->value);
// Sort them...
clist_ix_sort(&list); // mergesort O(n*log n)
n = 0;
puts("sorted");
c_foreach (i, clist_ix, list)
- if (++n % 10000 == 0) printf("%8d: %10zd\n", n, i.get->value);
+ if (++n % 10000 == 0) printf("%8d: %10zd\n", n, i.val->value);
clist_ix_del(&list);
}
*/
@@ -81,7 +81,7 @@ \
typedef struct { \
clist_##X##_node_t* const* _last; \
- clist_##X##_value_t* get; \
+ clist_##X##_value_t* val; \
int _state; \
} clist_##X##_iter_t
@@ -163,11 +163,11 @@ STC_API size_t _clist_size(const clist_void* self); } \
STC_INLINE void \
clist_##X##_next(clist_##X##_iter_t* it) { \
- clist_##X##_node_t* node = _clist_node(X, it->get); \
- it->get = ((it->_state += node == *it->_last) == 1) ? NULL : &node->next->value; \
+ clist_##X##_node_t* node = _clist_node(X, it->val); \
+ it->val = ((it->_state += node == *it->_last) == 1) ? NULL : &node->next->value; \
} \
STC_INLINE clist_##X##_value_t* \
- clist_##X##_itval(clist_##X##_iter_t it) {return it.get;} \
+ clist_##X##_itval(clist_##X##_iter_t it) {return it.val;} \
\
STC_API clist_##X##_iter_t \
clist_##X##_insert_after(clist_##X* self, clist_##X##_iter_t pos, Value value); \
@@ -235,19 +235,19 @@ STC_API size_t _clist_size(const clist_void* self); \
STC_API clist_##X##_iter_t \
clist_##X##_insert_after(clist_##X* self, clist_##X##_iter_t pos, Value value) { \
- clist_##X##_node_t* node = pos.get ? _clist_node(X, pos.get) : NULL; \
+ clist_##X##_node_t* node = pos.val ? _clist_node(X, pos.val) : NULL; \
_c_clist_insert_after(self, X, node, value); \
if (node == self->last && pos._state == 0) self->last = entry; \
- pos.get = &entry->value, pos._state = 0; return pos; \
+ pos.val = &entry->value, pos._state = 0; return pos; \
} \
STC_API clist_##X##_iter_t \
clist_##X##_erase_after(clist_##X* self, clist_##X##_iter_t pos) { \
- _clist_##X##_erase_after(self, _clist_node(X, pos.get)); \
+ _clist_##X##_erase_after(self, _clist_node(X, pos.val)); \
clist_##X##_next(&pos); return pos; \
} \
STC_API clist_##X##_iter_t \
clist_##X##_erase_range_after(clist_##X* self, clist_##X##_iter_t first, clist_##X##_iter_t finish) { \
- clist_##X##_node_t* node = _clist_node(X, first.get), *done = finish.get ? _clist_node(X, finish.get) : NULL; \
+ clist_##X##_node_t* node = _clist_node(X, first.val), *done = finish.val ? _clist_node(X, finish.val) : NULL; \
while (node && node->next != done) \
node = _clist_##X##_erase_after(self, node); \
clist_##X##_next(&first); return first; \
@@ -256,8 +256,8 @@ STC_API size_t _clist_size(const clist_void* self); STC_API clist_##X##_iter_t \
clist_##X##_find_before(const clist_##X* self, clist_##X##_iter_t first, clist_##X##_iter_t finish, RawValue val) { \
clist_##X##_iter_t i = first; \
- for (clist_##X##_next(&i); i.get != finish.get; clist_##X##_next(&i)) { \
- RawValue r = valueToRaw(i.get); \
+ for (clist_##X##_next(&i); i.val != finish.val; clist_##X##_next(&i)) { \
+ RawValue r = valueToRaw(i.val); \
if (valueCompareRaw(&r, &val) == 0) return first; \
first = i; \
} \
@@ -267,7 +267,7 @@ STC_API size_t _clist_size(const clist_void* self); STC_API clist_##X##_iter_t \
clist_##X##_find(const clist_##X* self, RawValue val) { \
clist_##X##_iter_t it = clist_##X##_find_before(self, clist_##X##_before_begin(self), clist_##X##_end(self), val); \
- if (it.get != clist_##X##_end(self).get) clist_##X##_next(&it); \
+ if (it.val != clist_##X##_end(self).val) clist_##X##_next(&it); \
return it; \
} \
STC_API clist_##X##_node_t* \
@@ -297,10 +297,10 @@ STC_API size_t _clist_size(const clist_void* self); \
STC_API void \
clist_##X##_splice_after(clist_##X* self, clist_##X##_iter_t pos, clist_##X* other) { \
- if (!pos.get) \
+ if (!pos.val) \
self->last = other->last; \
else if (other->last) { \
- clist_##X##_node_t *node = _clist_node(X, pos.get), *next = node->next; \
+ clist_##X##_node_t *node = _clist_node(X, pos.val), *next = node->next; \
node->next = other->last->next; \
other->last->next = next; \
if (node == self->last && pos._state == 0) self->last = other->last; \
@@ -31,7 +31,7 @@ int main(void) { cset_sx_insert(&s, 5);
cset_sx_insert(&s, 8);
c_foreach (i, cset_sx, s)
- printf("set %d\n", i.get->second);
+ printf("set %d\n", i.val->second);
cset_sx_del(&s);
cmap_mx m = cmap_INIT;
@@ -43,7 +43,7 @@ int main(void) { cmap_mx_put(&m, 5, 'd'); // update
cmap_mx_erase(&m, 8);
c_foreach (i, cmap_mx, m)
- printf("map %d: %c\n", i.get->first, i.get->second);
+ printf("map %d: %c\n", i.val->first, i.val->second);
cmap_mx_del(&m);
}*/
#ifndef CMAP__H__
@@ -198,7 +198,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; } ctype##_##X, ctype##_##X##_t; \
\
typedef struct { \
- ctype##_##X##_value_t *get; \
+ ctype##_##X##_value_t *val; \
uint8_t* _hx; \
} ctype##_##X##_iter_t; \
\
@@ -277,7 +277,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; STC_INLINE ctype##_##X##_iter_t \
ctype##_##X##_begin(ctype##_##X* self) { \
ctype##_##X##_iter_t it = {self->table, self->_hashx}; \
- if (it._hx) while (*it._hx == 0) ++it.get, ++it._hx; \
+ if (it._hx) while (*it._hx == 0) ++it.val, ++it._hx; \
return it; \
} \
STC_INLINE ctype##_##X##_iter_t \
@@ -286,13 +286,13 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; } \
STC_INLINE void \
ctype##_##X##_next(ctype##_##X##_iter_t* it) { \
- while ((++it->get, *++it->_hx == 0)) ; \
+ while ((++it->val, *++it->_hx == 0)) ; \
} \
CMAP_ONLY_##ctype( STC_INLINE ctype##_##X##_mapped_t* \
- ctype##_##X##_itval(ctype##_##X##_iter_t it) {return &it.get->second;} ) \
+ ctype##_##X##_itval(ctype##_##X##_iter_t it) {return &it.val->second;} ) \
\
STC_API void \
- ctype##_##X##_erase_entry(ctype##_##X* self, ctype##_##X##_value_t* get); \
+ ctype##_##X##_erase_entry(ctype##_##X* self, ctype##_##X##_value_t* val); \
STC_INLINE size_t \
ctype##_##X##_erase(ctype##_##X* self, RawKey rawKey) { \
if (self->size == 0) return 0; \
@@ -301,7 +301,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; } \
STC_INLINE ctype##_##X##_iter_t \
ctype##_##X##_erase_at(ctype##_##X* self, ctype##_##X##_iter_t pos) { \
- ctype##_##X##_erase_entry(self, pos.get); \
+ ctype##_##X##_erase_entry(self, pos.val); \
ctype##_##X##_next(&pos); return pos; \
} \
\
@@ -419,8 +419,8 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; } \
\
STC_API void \
- ctype##_##X##_erase_entry(ctype##_##X* self, ctype##_##X##_value_t* get) { \
- size_t i = chash_entry_index(*self, get), j = i, k, cap = self->bucket_count; \
+ ctype##_##X##_erase_entry(ctype##_##X* self, ctype##_##X##_value_t* val) { \
+ size_t i = chash_entry_index(*self, val), j = i, k, cap = self->bucket_count; \
ctype##_##X##_value_t* slot = self->table; \
uint8_t* hashx = self->_hashx; \
ctype##_##X##_entry_del(&slot[i]); \
diff --git a/stc/csptr.h b/stc/csptr.h index 13c6b3ad..406ab74a 100644 --- a/stc/csptr.h +++ b/stc/csptr.h @@ -115,6 +115,9 @@ typedef long atomic_count_t; *self = csptr_##X##_make(p); \
} \
\
+ STC_INLINE csptr_##X##_value_t* \
+ csptr_##X##_get(csptr_##X x) {return x.get;} \
+\
typedef int csptr_##X##_dud
#endif
@@ -30,7 +30,7 @@ #include "cdefs.h"
typedef struct cstr { char* str; } cstr_t;
-typedef struct { char *get; } cstr_iter_t;
+typedef struct { char *val; } cstr_iter_t;
typedef char cstr_value_t;
static size_t _cstr_nullrep[] = {0, 0, 0};
@@ -114,8 +114,8 @@ STC_INLINE cstr_iter_t cstr_end(cstr_t* self) {
cstr_iter_t it = {self->str + cstr_size(*self)}; return it;
}
-STC_INLINE void cstr_next(cstr_iter_t* it) { ++it->get; }
-STC_INLINE char* cstr_itval(cstr_iter_t it) {return it.get;}
+STC_INLINE void cstr_next(cstr_iter_t* it) { ++it->val; }
+STC_INLINE char* cstr_itval(cstr_iter_t it) {return it.val;}
STC_INLINE cstr_t*
cstr_assign(cstr_t* self, const char* str) {
@@ -48,7 +48,7 @@ typedef Value cvec_##X##_value_t; \
typedef RawValue cvec_##X##_rawvalue_t; \
typedef cvec_##X##_rawvalue_t cvec_##X##_input_t; \
- typedef struct { cvec_##X##_value_t *get; } cvec_##X##_iter_t; \
+ typedef struct { cvec_##X##_value_t *val; } cvec_##X##_iter_t; \
\
typedef struct { \
cvec_##X##_value_t* data; \
@@ -106,11 +106,11 @@ \
STC_API cvec_##X##_iter_t \
cvec_##X##_insert_range(cvec_##X* self, cvec_##X##_iter_t pos, cvec_##X##_iter_t first, cvec_##X##_iter_t finish) { \
- return cvec_##X##_insert_range_p(self, pos.get, first.get, finish.get); \
+ return cvec_##X##_insert_range_p(self, pos.val, first.val, finish.val); \
} \
STC_INLINE cvec_##X##_iter_t \
cvec_##X##_insert_at(cvec_##X* self, cvec_##X##_iter_t pos, Value value) { \
- return cvec_##X##_insert_range_p(self, pos.get, &value, &value + 1); \
+ return cvec_##X##_insert_range_p(self, pos.val, &value, &value + 1); \
} \
STC_INLINE cvec_##X##_iter_t \
cvec_##X##_insert_at_idx(cvec_##X* self, size_t idx, Value value) { \
@@ -130,11 +130,11 @@ \
STC_INLINE cvec_##X##_iter_t \
cvec_##X##_erase_range(cvec_##X* self, cvec_##X##_iter_t first, cvec_##X##_iter_t finish) { \
- return cvec_##X##_erase_range_p(self, first.get, finish.get); \
+ return cvec_##X##_erase_range_p(self, first.val, finish.val); \
} \
STC_INLINE cvec_##X##_iter_t \
cvec_##X##_erase_at(cvec_##X* self, cvec_##X##_iter_t pos) { \
- return cvec_##X##_erase_range_p(self, pos.get, pos.get + 1); \
+ return cvec_##X##_erase_range_p(self, pos.val, pos.val + 1); \
} \
STC_INLINE cvec_##X##_iter_t \
cvec_##X##_erase_at_idx(cvec_##X* self, size_t idx) { \
@@ -180,11 +180,11 @@ cvec_##X##_iter_t it = {self->data + cvec_size(*self)}; return it; \
} \
STC_INLINE void \
- cvec_##X##_next(cvec_##X##_iter_t* it) {++it->get;} \
+ cvec_##X##_next(cvec_##X##_iter_t* it) {++it->val;} \
STC_INLINE cvec_##X##_value_t* \
- cvec_##X##_itval(cvec_##X##_iter_t it) {return it.get;} \
+ cvec_##X##_itval(cvec_##X##_iter_t it) {return it.val;} \
STC_INLINE size_t \
- cvec_##X##_idx(cvec_##X v, cvec_##X##_iter_t it) {return it.get - v.data;} \
+ cvec_##X##_idx(cvec_##X v, cvec_##X##_iter_t it) {return it.val - v.data;} \
\
_c_implement_cvec_7(X, Value, valueDestroy, RawValue, valueCompareRaw, valueToRaw, valueFromRaw)
@@ -270,8 +270,8 @@ \
STC_API cvec_##X##_iter_t \
cvec_##X##_find_in_range(const cvec_##X* self, cvec_##X##_iter_t first, cvec_##X##_iter_t finish, RawValue rawValue) { \
- for (; first.get != finish.get; cvec_##X##_next(&first)) { \
- RawValue r = valueToRaw(first.get); \
+ for (; first.val != finish.val; cvec_##X##_next(&first)) { \
+ RawValue r = valueToRaw(first.val); \
if (valueCompareRaw(&r, &rawValue) == 0) return first; \
} \
return cvec_##X##_end(self); \
|
