summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-09-15 22:43:41 +0200
committerTyge Løvset <[email protected]>2020-09-15 22:43:41 +0200
commitf4435af2fc9e9187f7be0149c2eb916db27cb257 (patch)
tree117429619290d165b7a3001f21f3c0e7f37a1045
parentf539099575e14aea9f2e043b9af33d05c47399ad (diff)
downloadSTC-modified-f4435af2fc9e9187f7be0149c2eb916db27cb257.tar.gz
STC-modified-f4435af2fc9e9187f7be0149c2eb916db27cb257.zip
New API Change.
-rw-r--r--README.md60
-rw-r--r--examples/README.md8
-rw-r--r--examples/advanced.c8
-rw-r--r--examples/benchmark.c4
-rw-r--r--examples/birthday.c10
-rw-r--r--examples/complex.c8
-rw-r--r--examples/demos.c42
-rw-r--r--examples/ex_gaussian.c10
-rw-r--r--examples/geek1.c16
-rw-r--r--examples/geek2.c8
-rw-r--r--examples/geek3.c18
-rw-r--r--examples/geek4.c6
-rw-r--r--examples/geek5.c4
-rw-r--r--examples/geek6.c2
-rw-r--r--examples/geek7.c6
-rw-r--r--examples/heap.c4
-rw-r--r--examples/inits.c26
-rw-r--r--examples/list.c12
-rw-r--r--examples/mapmap.c8
-rw-r--r--examples/phonebook.c8
-rw-r--r--examples/priority.c4
-rw-r--r--examples/queue.c4
-rw-r--r--examples/replace.c2
-rw-r--r--examples/stack.c8
-rw-r--r--examples/words.c14
-rw-r--r--stc/carray.h24
-rw-r--r--stc/cbitset.h6
-rw-r--r--stc/cdefs.h8
-rw-r--r--stc/clist.h64
-rw-r--r--stc/cmap.h116
-rw-r--r--stc/cpqueue.h6
-rw-r--r--stc/cqueue.h6
-rw-r--r--stc/cstack.h6
-rw-r--r--stc/cstr.h16
-rw-r--r--stc/cvec.h54
35 files changed, 303 insertions, 303 deletions
diff --git a/README.md b/README.md
index 7f672e92..ca9a3bd0 100644
--- a/README.md
+++ b/README.md
@@ -24,7 +24,7 @@ The usage of the containers is vert similar to the C++ standard containers, so i
All containers mentioned above, except cstr_t and cbitset_t are generic and typesafe (similar to templates in C++). No casting is used. A simple example:
```
#include <stc/cvec.h>
-declare_cvec(i, int);
+cdef_cvec(i, int);
int main(void) {
cvec_i vec = cvec_ini;
@@ -55,10 +55,10 @@ Because it is headers only, files can simply be included in your program. The fu
#include <stc/clist.h>
#include "Vec3.h"
-declare_cmap(ii, int, int);
-declare_cset(ix, int64_t);
-declare_cvec(i, int);
-declare_clist(v3, Vec3);
+cdef_cmap(ii, int, int);
+cdef_cset(ix, int64_t);
+cdef_cvec(i, int);
+cdef_clist(v3, Vec3);
...
```
Performance
@@ -118,23 +118,23 @@ cmap discussion
You can customize the destroy-, hash- and equals- function. **cmap/cset** also supports a few other arguments in the declare-statement that allows to define a convertion from a raw/literal type to the key-type specified. This is very useful when e.g. having cstr as key, as it enables the usage of string literals as key in *put() and find()* functions, instead of requering a constructed cstr. Without it, the code would become:
```
-declare_cmap(si, cstr_t, int); // don't do this.
+cdef_cmap(si, cstr_t, int); // don't do this.
...
-cmap_si_put(&map, cstr_make("mykey"), 12);
+cmap_si_put(&map, cstr("mykey"), 12);
```
This is a problem because cstr_t key may exist in the map, and it would need to destroy the current key and replace it with the new to avoid memory leak. Lookup would also be problematic:
```
-cstr lookup = cstr_make("mykey");
+cstr lookup = cstr("mykey");
int x = cmap_si_find(&map, lookup)->value;
cstr_destroy(&lookup);
```
To avoid this, use
-- *declare_cmap_strkey(tag, valuetype)*
-- *declare_cmap_strval(tag, keytype)*
-- *declare_cmap_str()* // cstr_t -> cstr_t
-- *declare_cset_str()* // cstr_t set
+- *cdef_cmap_strkey(tag, valuetype)*
+- *cdef_cmap_strval(tag, keytype)*
+- *cdef_cmap_str()* // cstr_t -> cstr_t
+- *cdef_cset_str()* // cstr_t set
```
-declare_cmap_strkey(si, int);
+cdef_cmap_strkey(si, int);
...
cmap_si map = cmap_ini;
cmap_si_put(&map, "mykey", 12); // constructs a cstr_t key from the const char* internally.
@@ -142,9 +142,9 @@ int x = cmap_si_find(&map, "mykey")->value; // no allocation of string key happe
cmap_si_destroy(&map);
```
An alternative is to use *char* * as key type, but then you must manage allcoated memory of the hash char* keys yourself.
-Note that this predefined customization is also available for **cvec** and **clist**. See *declare_cvec_str()*, *declare_clist_str()*.
+Note that this predefined customization is also available for **cvec** and **clist**. See *cdef_cvec_str()*, *cdef_clist_str()*.
-To customize your own cmap type to work like cmap_str, you may want to look at **examples/advanced.c**. It demonstrates how to use a custom struct as a hash map key, using the optional parameters to declare_cmap().
+To customize your own cmap type to work like cmap_str, you may want to look at **examples/advanced.c**. It demonstrates how to use a custom struct as a hash map key, using the optional parameters to cdef_cmap().
Example usages
--------------
@@ -155,7 +155,7 @@ The examples folder contains further examples.
#include <stc/cstr.h>
int main() {
- cstr_t s1 = cstr_make("one-nine-three-seven-five");
+ cstr_t s1 = cstr("one-nine-three-seven-five");
printf("%s.\n", s1.str);
cstr_insert(&s1, 3, "-two");
@@ -181,7 +181,7 @@ int main() {
**cvec** of *int64_t*.
```
#include <stc/cvec.h>
-declare_cvec(ix, int64_t); // ix is just an example type tag name.
+cdef_cvec(ix, int64_t); // ix is just an example type tag name.
int main() {
cvec_ix bignums = cvec_ini; // use cvec_ix_init() if initializing after declaration.
@@ -200,7 +200,7 @@ int main() {
```
#include <stc/cstr.h>
#include <stc/cvec.h>
-declare_cvec_str();
+cdef_cvec_str();
int main() {
cvec_str names = cvec_ini;
@@ -212,7 +212,7 @@ int main() {
printf("%s\n", names.data[1].str); // Access the string char*
c_foreach (i, cvec_str, names)
- printf("item %s\n", i.item->str);
+ printf("get %s\n", i.get->str);
cvec_str_destroy(&names);
}
```
@@ -220,7 +220,7 @@ int main() {
```
#include <stdio.h>
#include <stc/cmap.h>
-declare_cmap(ii, int, int);
+cdef_cmap(ii, int, int);
int main() {
cmap_ii nums = cmap_ini;
@@ -235,7 +235,7 @@ int main() {
```
#include <stc/cstr.h>
#include <stc/cmap.h>
-declare_cset_str(); // cstr set. See the discussion above.
+cdef_cset_str(); // cstr set. See the discussion above.
int main() {
cset_str words = cset_ini;
@@ -246,15 +246,15 @@ int main() {
// iterate the set:
c_foreach (i, cset_str, words)
- printf("%s\n", i.item->key.str);
+ printf("%s\n", i.get->key.str);
cset_str_destroy(&words);
}
```
-**cmap** of *cstr -> cstr*. Both cstr keys and values are created internally via *cstr_make()* from const char* inputs.
+**cmap** of *cstr -> cstr*. Both cstr keys and values are created internally via *cstr()* from const char* inputs.
```
#include <stc/cstr.h>
#include <stc/cmap.h>
-declare_cmap_str();
+cdef_cmap_str();
int main() {
cmap_str table = cmap_ini;
@@ -266,7 +266,7 @@ int main() {
printf("size = %zu\n", cmap_size(table));
c_foreach (i, cmap_str, table)
- printf("%s: %s\n", i.item->key.str, i.item->value.str);
+ printf("%s: %s\n", i.get->key.str, i.get->value.str);
cmap_str_destroy(&table); // frees key and value cstrs, and hash table.
}
```
@@ -276,7 +276,7 @@ int main() {
#include <time.h>
#include <stc/clist.h>
#include <stc/crandom.h>
-declare_clist(fx, double);
+cdef_clist(fx, double);
int main() {
clist_fx list = clist_ini;
@@ -288,14 +288,14 @@ int main() {
clist_fx_push_back(&list, crand_uniform_f64(&eng, dist));
k = 0;
c_foreach (i, clist_fx, list)
- if (++k <= 10) printf("%8d: %10f\n", k, i.item->value); else break;
+ if (++k <= 10) printf("%8d: %10f\n", k, i.get->value); else break;
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.item->value); else break;
+ if (++k <= 10) printf("%8d: %10f\n", k, i.get->value); else break;
clist_fx_clear(&list);
@@ -303,7 +303,7 @@ int main() {
c_push(&list, clist_fx, {10, 20, 30, 40, 50});
c_foreach (i, clist_fx, list)
- printf("%f ", i.item->value);
+ printf("%f ", i.get->value);
puts("");
clist_fx_destroy(&list);
@@ -313,7 +313,7 @@ int main() {
```
#include <stdio.h>
#include <stc/carray.h>
-declare_carray(f, float);
+cdef_carray(f, float);
int main()
{
diff --git a/examples/README.md b/examples/README.md
index 26eb4bb1..5c9c990a 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -48,12 +48,12 @@ static inline VikingVw viking_toVw(Viking* vk) {
VikingVw vw = {vk->name.str, vk->country.str}; return vw;
}
static inline Viking viking_fromVw(VikingVw vw) { // note: parameter is by value
- Viking vk = {cstr_make(vw.name), cstr_make(vw.country)}; return vk;
+ Viking vk = {cstr(vw.name), cstr(vw.country)}; return vk;
}
```
-With this in place, we use the full declare_cmap() macro to define {Viking -> int} hash map type:
+With this in place, we use the full cdef_cmap() macro to define {Viking -> int} hash map type:
```
-declare_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
+cdef_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
viking_destroy, VikingVw, viking_toVw, viking_fromVw);
```
cmap_vk uses vikingvw_hash() for hash value calculations, and vikingvw_equals() for equality test. cmap_vk_destroy() will free all memory allocated for Viking keys and the hash table values.
@@ -72,7 +72,7 @@ int main() {
cmap_vk_emplace(&vikings, look, 0)->value += 5; // again
c_foreach (k, cmap_vk, vikings) {
- printf("%s of %s has %d hp\n", k.item->key.name.str, k.item->key.country.str, k.item->value);
+ printf("%s of %s has %d hp\n", k.get->key.name.str, k.get->key.country.str, k.get->value);
}
cmap_vk_destroy(&vikings);
}
diff --git a/examples/advanced.c b/examples/advanced.c
index fe46f5da..ab2cec5f 100644
--- a/examples/advanced.c
+++ b/examples/advanced.c
@@ -47,11 +47,11 @@ VikingVw viking_toVw(Viking* vk) {
VikingVw vw = {vk->name.str, vk->country.str}; return vw;
}
Viking viking_fromVw(VikingVw vw) {
- Viking vk = {cstr_make(vw.name), cstr_make(vw.country)}; return vk;
+ Viking vk = {cstr(vw.name), cstr(vw.country)}; return vk;
}
-// Using the full declare_cmap() macro to define [Viking -> int] hash map type:
-declare_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
+// Using the full cdef_cmap() macro to define [Viking -> int] hash map type:
+cdef_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
viking_destroy, VikingVw, viking_toVw, viking_fromVw);
// cmap_vk uses vikingvw_hash() for hash value calculations, and vikingvw_equals() for equality test.
@@ -74,7 +74,7 @@ int main()
cmap_vk_emplace(&vikings, einar, 0).first->value += 5; // again
c_foreach (k, cmap_vk, vikings) {
- printf("%s of %s has %d hp\n", k.item->key.name.str, k.item->key.country.str, k.item->value);
+ printf("%s of %s has %d hp\n", k.get->key.name.str, k.get->key.country.str, k.get->value);
}
cmap_vk_destroy(&vikings);
}
diff --git a/examples/benchmark.c b/examples/benchmark.c
index 3824e02f..04995de0 100644
--- a/examples/benchmark.c
+++ b/examples/benchmark.c
@@ -22,7 +22,7 @@ static inline uint32_t fibonacci_hash(const void* data, size_t len) {
}
// cmap and khash template expansion
-declare_cmap(ii, int64_t, int64_t, c_default_destroy, c_default_equals, fibonacci_hash);
+cdef_cmap(ii, int64_t, int64_t, c_default_destroy, c_default_equals, fibonacci_hash);
KHASH_MAP_INIT_INT64(ii, int64_t)
@@ -41,7 +41,7 @@ crand_rng64_t rng;
#define CMAP_ERASE(tt, key) cmap_##tt##_erase(&map, key)
#define CMAP_FIND(tt, key) (cmap_##tt##_find(map, key) != NULL)
#define CMAP_FOR(tt, i) c_foreach (i, cmap_##tt, map)
-#define CMAP_ITEM(tt, i) i.item->value
+#define CMAP_ITEM(tt, i) i.get->value
#define CMAP_SIZE(tt) cmap_size(map)
#define CMAP_BUCKETS(tt) cmap_bucket_count(map)
#define CMAP_CLEAR(tt) cmap_##tt##_clear(&map)
diff --git a/examples/birthday.c b/examples/birthday.c
index 59a8aee5..c6a9e541 100644
--- a/examples/birthday.c
+++ b/examples/birthday.c
@@ -7,7 +7,7 @@
#include <stc/cvec.h>
#include <stc/cstr.h>
-declare_cmap(ic, uint64_t, uint8_t);
+cdef_cmap(ic, uint64_t, uint8_t);
const static uint64_t seed = 1234;
const static uint64_t N = 1ull << 27;
@@ -29,8 +29,8 @@ void repeats(void)
}
-declare_cmap(x, uint32_t, uint64_t);
-declare_cvec(x, uint64_t);
+cdef_cmap(x, uint32_t, uint64_t);
+cdef_cvec(x, uint64_t);
void distribution(void)
{
@@ -45,11 +45,11 @@ void distribution(void)
float diff = (float) (clock() - now) / CLOCKS_PER_SEC;
uint64_t sum = 0;
- c_foreach (i, cmap_x, map) sum += i.item->value;
+ c_foreach (i, cmap_x, map) sum += i.get->value;
sum /= map.size;
c_foreach (i, cmap_x, map)
- printf("%u: %zu - %zu\n", i.item->key, i.item->value, sum);
+ printf("%u: %zu - %zu\n", i.get->key, i.get->value, sum);
printf("%.02f\n", diff);
}
diff --git a/examples/complex.c b/examples/complex.c
index 151824e2..f129884a 100644
--- a/examples/complex.c
+++ b/examples/complex.c
@@ -5,10 +5,10 @@
void check_destroy(float* v) {printf("destroy %g\n", *v);}
-declare_carray(f, float, check_destroy); // normally omit the last argument - float type need no destroy.
-declare_clist(y, carray2f, carray2f_destroy, c_no_compare);
-declare_cmap(g, int, clist_y, clist_y_destroy);
-declare_cmap_strkey(s, cmap_g, cmap_g_destroy);
+cdef_carray(f, float, check_destroy); // normally omit the last argument - float type need no destroy.
+cdef_clist(y, carray2f, carray2f_destroy, c_no_compare);
+cdef_cmap(g, int, clist_y, clist_y_destroy);
+cdef_cmap_strkey(s, cmap_g, cmap_g_destroy);
int main() {
int xdim = 4, ydim = 6;
diff --git a/examples/demos.c b/examples/demos.c
index 7b204aa1..b3ed91bb 100644
--- a/examples/demos.c
+++ b/examples/demos.c
@@ -8,7 +8,7 @@
void stringdemo1()
{
printf("\nSTRINGDEMO1\n");
- cstr_t cs = cstr_make("one-nine-three-seven-five");
+ cstr_t cs = cstr("one-nine-three-seven-five");
printf("%s.\n", cs.str);
cstr_insert(&cs, 3, "-two");
@@ -34,7 +34,7 @@ void stringdemo1()
}
-declare_cvec(ix, int64_t); // ix is just an example tag name.
+cdef_cvec(ix, int64_t); // ix is just an example tag name.
void vectordemo1()
{
@@ -55,7 +55,7 @@ void vectordemo1()
-declare_cvec_str();
+cdef_cvec_str();
void vectordemo2()
{
@@ -69,11 +69,11 @@ void vectordemo2()
cvec_str_sort(&names); // Sort the array
c_foreach (i, cvec_str, names)
- printf("sorted: %s\n", i.item->str);
+ printf("sorted: %s\n", i.get->str);
cvec_str_destroy(&names);
}
-declare_clist(ix, int);
+cdef_clist(ix, int);
void listdemo1()
{
@@ -84,23 +84,23 @@ 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.item->value);
+ printf("value: %d\n", i.get->value);
/* merge/append nums2 to nums */
clist_ix_splice_front(&nums, &nums2);
c_foreach (i, clist_ix, nums)
- printf("spliced: %d\n", i.item->value);
+ printf("spliced: %d\n", i.get->value);
- clist_ix_find(&nums, 100).item->value *= 10;
+ clist_ix_find(&nums, 100).get->value *= 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.item->value);
+ printf("sorted: %d\n", i.get->value);
clist_ix_destroy(&nums);
}
-declare_cset(i, int);
+cdef_cset(i, int);
void setdemo1()
{
@@ -110,12 +110,12 @@ void setdemo1()
cset_i_insert(&nums, 11);
c_foreach (i, cset_i, nums)
- printf("set: %d\n", i.item->value);
+ printf("set: %d\n", i.get->value);
cset_i_destroy(&nums);
}
-declare_cmap(ii, int, int);
+cdef_cmap(ii, int, int);
void mapdemo1()
{
@@ -128,7 +128,7 @@ void mapdemo1()
}
-declare_cmap_strkey(si, int); // Shorthand macro for the general declare_cmap expansion.
+cdef_cmap_strkey(si, int); // Shorthand macro for the general cdef_cmap expansion.
void mapdemo2()
{
@@ -139,18 +139,18 @@ void mapdemo2()
cmap_si_put(&nums, "Groovy", 200); // overwrite previous
// iterate the map:
- for (cmap_si_iter_t i = cmap_si_begin(&nums); i.item != cmap_si_end(&nums).item; cmap_si_next(&i))
- printf("long: %s: %d\n", i.item->first.str, i.item->second);
+ 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);
// or rather use the short form:
c_foreach (i, cmap_si, nums)
- printf("short: %s: %d\n", i.item->first.str, i.item->second);
+ printf("short: %s: %d\n", i.get->first.str, i.get->second);
cmap_si_destroy(&nums);
}
-declare_cmap_str();
+cdef_cmap_str();
void mapdemo3()
{
@@ -161,18 +161,18 @@ 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.item->first.str, i.item->second.str);
+ printf("entry: %s: %s\n", i.get->first.str, i.get->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.item->first.str, i.item->second.str);
+ printf("entry: %s: %s\n", i.get->first.str, i.get->second.str);
cmap_str_destroy(&table); // frees key and value CStrs, and hash table (CVec).
}
-declare_carray(f, float);
+cdef_carray(f, float);
void arraydemo1()
{
@@ -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.item = 1.0f;
+ *i.get = 1.0f;
printf("%f\n", *carray3f_at(&a3, 29, 19, 9));
carray2f_destroy(&a2); // does nothing, since it is a sub-array.
diff --git a/examples/ex_gaussian.c b/examples/ex_gaussian.c
index 66abb889..402fba32 100644
--- a/examples/ex_gaussian.c
+++ b/examples/ex_gaussian.c
@@ -7,14 +7,14 @@
#include <stc/cvec.h>
// Declare int -> int hashmap. Uses typetag 'i' for ints.
-declare_cmap(i, int, size_t);
+cdef_cmap(i, int, size_t);
// Declare int vector with map entries that can be sorted by map keys.
static int compare(cmap_i_entry_t *a, cmap_i_entry_t *b) {
return c_default_compare(&a->key, &b->key);
}
// Vector: typetag 'e' for (map) entry
-declare_cvec(e, cmap_i_entry_t, c_default_destroy, compare);
+cdef_cvec(e, cmap_i_entry_t, c_default_destroy, compare);
int main()
{
@@ -38,17 +38,17 @@ int main()
// Transfer map to vec and sort it by map keys.
cvec_e vhist = cvec_ini;
c_foreach (i, cmap_i, mhist)
- cvec_e_push_back(&vhist, *i.item);
+ cvec_e_push_back(&vhist, *i.get);
cvec_e_sort(&vhist);
// Print the gaussian bar chart
cstr_t bar = cstr_ini;
c_foreach (i, cvec_e, vhist) {
- size_t n = (size_t) (i.item->value * Mag / N);
+ size_t n = (size_t) (i.get->value * 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.item->key, bar.str);
+ printf("%4d %s\n", i.get->key, bar.str);
}
}
// Cleanup
diff --git a/examples/geek1.c b/examples/geek1.c
index 983539b8..50e23032 100644
--- a/examples/geek1.c
+++ b/examples/geek1.c
@@ -12,7 +12,7 @@ int a[] = { 1, 2, 2, 3, 2, 4, 10 };
#include <stdio.h>
#include <stc/cmap.h>
-declare_cmap(ii, int, int);
+cdef_cmap(ii, int, int);
// Function to maximize the number of pairs
int findMaximumPairs(int a[], int n, int k)
@@ -30,13 +30,13 @@ int findMaximumPairs(int a[], int n, int k)
c_foreach (it, cmap_ii, hash) {
// If the number is 0
- if (it.item->key == 0) {
+ if (it.get->key == 0) {
// We take half since same number
- count += it.item->value / 2;
- cmap_ii_put(&hash, it.item->key, it.item->key & 1);
+ count += it.get->value / 2;
+ cmap_ii_put(&hash, it.get->key, it.get->key & 1);
} else {
- int one = it.item->key;
- int two = k - it.item->key;
+ int one = it.get->key;
+ int two = k - it.get->key;
cmap_ii_entry_t *hf = cmap_ii_find(&hash, one),
*hs = cmap_ii_emplace(&hash, two, 0).first;
@@ -62,10 +62,10 @@ int findMaximumPairs(int a[], int n, int k)
if (one == two) {
// If same then number of pairs will be half
- count += it.item->value / 2;
+ count += it.get->value / 2;
// Check for remaining
- hf->value = (it.item->key & 1);
+ hf->value = (it.get->key & 1);
}
else {
// Store the number of pairs
diff --git a/examples/geek2.c b/examples/geek2.c
index a02ede25..8b1ff2aa 100644
--- a/examples/geek2.c
+++ b/examples/geek2.c
@@ -3,8 +3,8 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-declare_cmap_str();
-declare_cset_str();
+cdef_cmap_str();
+cdef_cset_str();
int main()
{
@@ -16,7 +16,7 @@ int main()
cset_str_insert(&set, "You");
cset_str_insert(&set, "Tube");
c_foreach (i, cset_str, set)
- printf("%s ", i.item->key.str);
+ printf("%s ", i.get->key.str);
puts("");
// Review some books.
@@ -68,7 +68,7 @@ int main()
// Iterate over everything.
c_foreach (i, cmap_str, book_reviews) {
- printf("- %s: \"%s\"\n", i.item->key.str, i.item->value.str);
+ printf("- %s: \"%s\"\n", i.get->key.str, i.get->value.str);
}
cmap_str_destroy(&book_reviews);
}
diff --git a/examples/geek3.c b/examples/geek3.c
index 9c959f0e..4e83a8ec 100644
--- a/examples/geek3.c
+++ b/examples/geek3.c
@@ -3,8 +3,8 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-declare_cmap_strkey(si, int);
-declare_cmap_strkey(ss, cstr_t, cstr_destroy);
+cdef_cmap_strkey(si, int);
+cdef_cmap_strkey(ss, cstr_t, cstr_destroy);
int main ()
{
@@ -21,7 +21,7 @@ int main ()
cmap_si_emplace(&mymap, "Sun", 0).first->value += 1000;
c_foreach (x, cmap_si, mymap) {
- printf("%s: %d\n", x.item->key.str, x.item->value);
+ printf("%s: %d\n", x.get->key.str, x.get->value);
}
cmap_si_destroy(&mymap);
@@ -29,18 +29,18 @@ int main ()
// Create an unordered_map of three strings (that map to strings)
cmap_ss u = cmap_ini;
- cmap_ss_put(&u, "RED", cstr_make("#FF0000"));
- cmap_ss_put(&u, "GREEN", cstr_make("#00FF00"));
- cmap_ss_put(&u, "BLUE", cstr_make("#0000FF"));
+ cmap_ss_put(&u, "RED", cstr("#FF0000"));
+ cmap_ss_put(&u, "GREEN", cstr("#00FF00"));
+ cmap_ss_put(&u, "BLUE", cstr("#0000FF"));
// Iterate and print keys and values of unordered_map
c_foreach (n, cmap_ss, u) {
- printf("%s: %s\n", n.item->key.str, n.item->value.str);
+ printf("%s: %s\n", n.get->key.str, n.get->value.str);
}
// Add two new entries to the unordered_map
- cmap_ss_put(&u, "BLACK", cstr_make("#000000"));
- cmap_ss_put(&u, "WHITE", cstr_make("#FFFFFF"));
+ cmap_ss_put(&u, "BLACK", cstr("#000000"));
+ cmap_ss_put(&u, "WHITE", cstr("#FFFFFF"));
// Output values by key
printf("The HEX of color RED is:[%s]\n", cmap_ss_find(&u, "RED")->value.str);
diff --git a/examples/geek4.c b/examples/geek4.c
index ec62efbc..3c4c085f 100644
--- a/examples/geek4.c
+++ b/examples/geek4.c
@@ -37,9 +37,9 @@ Efficient Approach: For all the words of the first sentence, we can check if it
#include <stc/cvec.h>
#include <stc/cstr.h>
-declare_cvec_str();
-declare_cmap_strkey(sb, bool);
-declare_cvec(sb, cmap_sb_entry_t, cmap_sb_entry_destroy, c_no_compare);
+cdef_cvec_str();
+cdef_cmap_strkey(sb, bool);
+cdef_cvec(sb, cmap_sb_entry_t, cmap_sb_entry_destroy, c_no_compare);
// Function to return the count of common words
// in all the sentences
diff --git a/examples/geek5.c b/examples/geek5.c
index 614bc387..d8b520c6 100644
--- a/examples/geek5.c
+++ b/examples/geek5.c
@@ -21,8 +21,8 @@ Output: 0
#include <stc/cvec.h>
#include <stc/cstr.h>
-declare_cvec(i, int);
-declare_cmap_strkey(sv, cvec_i, cvec_i_destroy);
+cdef_cvec(i, int);
+cdef_cmap_strkey(sv, cvec_i, cvec_i_destroy);
// Function to return the number of occurrences of
diff --git a/examples/geek6.c b/examples/geek6.c
index badf5bbc..f03053ca 100644
--- a/examples/geek6.c
+++ b/examples/geek6.c
@@ -30,7 +30,7 @@ operation in almost O(1) time complexity.
#include <stdio.h>
#include <stc/cmap.h>
-declare_cset(i, int);
+cdef_cset(i, int);
// Function to find the smallest positive
// missing number
diff --git a/examples/geek7.c b/examples/geek7.c
index eb6b61cb..cb0b35a0 100644
--- a/examples/geek7.c
+++ b/examples/geek7.c
@@ -27,9 +27,9 @@ After inserting all the elements excluding the ones which are to be deleted, Pop
#include <stc/cvec.h>
#include <stc/cpqueue.h>
-declare_cmap(ii, int, int);
-declare_cvec(i, int);
-declare_cpqueue(i, cvec_i, >);
+cdef_cmap(ii, int, int);
+cdef_cvec(i, int);
+cdef_cpqueue(i, cvec_i, >);
// Find k minimum element from arr[0..m-1] after deleting
// elements from del[0..n-1]
diff --git a/examples/heap.c b/examples/heap.c
index a281de01..fc067a41 100644
--- a/examples/heap.c
+++ b/examples/heap.c
@@ -4,8 +4,8 @@
#include <stc/cvec.h>
#include <stc/cpqueue.h>
-declare_cvec(f, float);
-declare_cpqueue(f, cvec_f, >);
+cdef_cvec(f, float);
+cdef_cpqueue(f, cvec_f, >);
int main()
{
diff --git a/examples/inits.c b/examples/inits.c
index 7134c3ff..37b08624 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -5,19 +5,19 @@
#include <stc/cpqueue.h>
#include <stc/clist.h>
-declare_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t
-declare_cmap_strkey(cnt, int);
+cdef_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t
+cdef_cmap_strkey(cnt, int);
typedef struct {int x, y;} ipair_t;
inline static int ipair_compare(const ipair_t* a, const ipair_t* b) {
int c = c_default_compare(&a->x, &b->x);
return c != 0 ? c : c_default_compare(&a->y, &b->y);
}
-declare_cvec(ip, ipair_t, c_default_destroy, ipair_compare);
-declare_clist(ip, ipair_t, c_default_destroy, ipair_compare);
+cdef_cvec(ip, ipair_t, c_default_destroy, ipair_compare);
+cdef_clist(ip, ipair_t, c_default_destroy, ipair_compare);
-declare_cvec(f, float);
-declare_cpqueue(f, cvec_f, >);
+cdef_cvec(f, float);
+cdef_cpqueue(f, cvec_f, >);
int main(void) {
@@ -27,7 +27,7 @@ int main(void) {
cvec_f floats = cvec_ini;
c_push(&floats, cvec_f, {4.0f, 2.0f, 5.0f, 3.0f, 1.0f});
- c_foreach (i, cvec_f, floats) printf("%.1f ", *i.item);
+ c_foreach (i, cvec_f, floats) printf("%.1f ", *i.get);
puts("");
// CVEC PRIORITY QUEUE
@@ -48,13 +48,13 @@ int main(void) {
int year = 2020;
cmap_id idnames = cmap_ini;
c_push(&idnames, cmap_id, {
- {100, cstr_make("Hello")},
- {110, cstr_make("World")},
+ {100, cstr("Hello")},
+ {110, cstr("World")},
{120, cstr_from("Howdy, -%d-", year)},
});
c_foreach (i, cmap_id, idnames)
- printf("%d: %s\n", i.item->key, i.item->value.str);
+ printf("%d: %s\n", i.get->key, i.get->value.str);
puts("");
cmap_id_destroy(&idnames);
@@ -77,7 +77,7 @@ int main(void) {
cmap_cnt_emplace(&countries, "Finland", 0).first->value += 20;
c_foreach (i, cmap_cnt, countries)
- printf("%s: %d\n", i.item->key.str, i.item->value);
+ printf("%s: %d\n", i.get->key.str, i.get->value);
puts("");
cmap_cnt_destroy(&countries);
@@ -93,7 +93,7 @@ int main(void) {
cvec_ip_sort(&pairs1);
c_foreach (i, cvec_ip, pairs1)
- printf("(%d %d) ", i.item->x, i.item->y);
+ printf("(%d %d) ", i.get->x, i.get->y);
puts("");
cvec_ip_destroy(&pairs1);
@@ -109,7 +109,7 @@ int main(void) {
clist_ip_sort(&pairs2);
c_foreach (i, clist_ip, pairs2)
- printf("(%d %d) ", i.item->value.x, i.item->value.y);
+ printf("(%d %d) ", i.get->value.x, i.get->value.y);
puts("");
clist_ip_destroy(&pairs2);
} \ No newline at end of file
diff --git a/examples/list.c b/examples/list.c
index d140d103..c77be371 100644
--- a/examples/list.c
+++ b/examples/list.c
@@ -2,7 +2,7 @@
#include <time.h>
#include <stc/clist.h>
#include <stc/crandom.h>
-declare_clist(fx, double);
+cdef_clist(fx, double);
int main() {
int k, n = 100000;
@@ -13,18 +13,18 @@ int main() {
for (int i = 0; i < 100000; ++i)
clist_fx_push_back(&list, crand_uniform_f64(&eng, &dist));
k = 0; c_foreach (i, clist_fx, list)
- if (++k <= 10) printf("%8d: %10f\n", k, i.item->value); else break;
+ if (++k <= 10) printf("%8d: %10f\n", k, i.get->value); else break;
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.item->value); else break;
+ if (++k <= 10) printf("%8d: %10f\n", k, i.get->value); else break;
puts("");
clist_fx_clear(&list);
c_push(&list, clist_fx, {10, 20, 30, 40, 30, 50});
- c_foreach (i, clist_fx, list) printf(" %g", i.item->value);
+ c_foreach (i, clist_fx, list) printf(" %g", i.get->value);
puts("");
int removed = clist_fx_remove(&list, 30);
@@ -34,11 +34,11 @@ int main() {
clist_fx_iter_t it = clist_fx_before_begin(&list);
printf("Full: ");
c_foreach (i, clist_fx, list)
- printf(" %g", i.item->value);
+ printf(" %g", i.get->value);
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.item->value);
+ printf(" %g", i.get->value);
puts("");
clist_fx_destroy(&list);
} \ No newline at end of file
diff --git a/examples/mapmap.c b/examples/mapmap.c
index f3df9609..4e71f6c0 100644
--- a/examples/mapmap.c
+++ b/examples/mapmap.c
@@ -3,8 +3,8 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-declare_cmap_str();
-declare_cmap_strkey(cfg, cmap_str, cmap_str_destroy);
+cdef_cmap_str();
+cdef_cmap_strkey(cfg, cmap_str, cmap_str_destroy);
int main(void) {
cmap_cfg config = cmap_ini;
@@ -19,8 +19,8 @@ int main(void) {
cmap_str_put(&cmap_cfg_emplace(&config, "group", init).first->value, "proj2", "Wind"); // Update
c_foreach (i, cmap_cfg, config)
- c_foreach (j, cmap_str, i.item->value)
- printf("%s: %s - %s (%u)\n", i.item->key.str, j.item->key.str, j.item->value.str, i.item->value.bucket_count);
+ c_foreach (j, cmap_str, i.get->value)
+ printf("%s: %s - %s (%u)\n", i.get->key.str, j.get->key.str, j.get->value.str, i.get->value.bucket_count);
cmap_cfg_destroy(&config);
} \ No newline at end of file
diff --git a/examples/phonebook.c b/examples/phonebook.c
index 983f4e74..716d4e92 100644
--- a/examples/phonebook.c
+++ b/examples/phonebook.c
@@ -25,12 +25,12 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-declare_cmap_str();
+cdef_cmap_str();
void print_phone_book(cmap_str phone_book)
{
c_foreach (i, cmap_str, phone_book)
- printf("%s\t- %s\n", i.item->key.str, i.item->value.str);
+ printf("%s\t- %s\n", i.get->key.str, i.get->value.str);
}
int main(int argc, char **argv)
@@ -47,8 +47,8 @@ int main(int argc, char **argv)
printf("Phone book:\n");
print_phone_book(phone_book);
- c_try_emplace(&phone_book, cmap_str, "Zak Byers", cstr_make("(551) 396-1880"));
- c_try_emplace(&phone_book, cmap_str, "Zak Byers", cstr_make("(551) 396-1990"));
+ c_try_emplace(&phone_book, cmap_str, "Zak Byers", cstr("(551) 396-1880"));
+ c_try_emplace(&phone_book, cmap_str, "Zak Byers", cstr("(551) 396-1990"));
printf("\nPhone book after adding Zak Byers:\n");
print_phone_book(phone_book);
diff --git a/examples/priority.c b/examples/priority.c
index 8bd2abce..ffc4f97b 100644
--- a/examples/priority.c
+++ b/examples/priority.c
@@ -6,8 +6,8 @@
#include <stc/cmap.h>
#include <stc/crandom.h>
-declare_cvec(i, int64_t);
-declare_cpqueue(i, cvec_i, >); // min-heap (increasing values)
+cdef_cvec(i, int64_t);
+cdef_cpqueue(i, cvec_i, >); // min-heap (increasing values)
int main() {
size_t N = 10000000;
diff --git a/examples/queue.c b/examples/queue.c
index 5bac7535..a912d8ea 100644
--- a/examples/queue.c
+++ b/examples/queue.c
@@ -2,8 +2,8 @@
#include <stc/cqueue.h>
#include <stdio.h>
-declare_clist(i, int);
-declare_cqueue(i, clist_i); // min-heap (increasing values)
+cdef_clist(i, int);
+cdef_cqueue(i, clist_i); // min-heap (increasing values)
int main() {
int n = 10000000;
diff --git a/examples/replace.c b/examples/replace.c
index 6e5fe024..bcc4952e 100644
--- a/examples/replace.c
+++ b/examples/replace.c
@@ -11,7 +11,7 @@ int main ()
// replace signatures used in the same order as described above:
// Ustring positions: 0123456789*123456789*12345
- cstr_t s = cstr_make(base); // "this is a test string."
+ cstr_t s = cstr(base); // "this is a test string."
cstr_t m = cstr_clone(s);
cstr_append(&m, m.str);
diff --git a/examples/stack.c b/examples/stack.c
index dedf1eb5..a60e5564 100644
--- a/examples/stack.c
+++ b/examples/stack.c
@@ -3,10 +3,10 @@
#include <stc/cstr.h>
#include <stc/cstack.h>
-declare_cvec(i, int);
-declare_cvec(c, char);
-declare_cstack(i, cvec_i);
-declare_cstack(c, cvec_c);
+cdef_cvec(i, int);
+cdef_cvec(c, char);
+cdef_cstack(i, cvec_i);
+cdef_cstack(c, cvec_c);
int main() {
cstack_i stack = cstack_i_init();
diff --git a/examples/words.c b/examples/words.c
index 5fc80c62..ad37f72e 100644
--- a/examples/words.c
+++ b/examples/words.c
@@ -4,9 +4,9 @@
#include <stc/clist.h>
#include <stc/cvec.h>
-declare_cvec_str();
-declare_clist_str();
-declare_cmap_strkey(si, int);
+cdef_cvec_str();
+cdef_clist_str();
+cdef_cmap_strkey(si, int);
int main1()
@@ -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.item->value.str);
+ printf("%s\n", w.get->value.str);
puts("");
cvec_str words = cvec_ini;
@@ -29,12 +29,12 @@ int main1()
cmap_si word_map = cmap_ini;
c_foreach (w, cvec_str, words)
- cmap_si_emplace(&word_map, w.item->str, 0).first->value += 1;
+ cmap_si_emplace(&word_map, w.get->str, 0).first->value += 1;
c_foreach (pair, cmap_si, word_map) {
printf("%d occurrences of word '%s'\n",
- pair.item->value,
- pair.item->key.str);
+ pair.get->value,
+ pair.get->key.str);
}
cmap_si_destroy(&word_map);
diff --git a/stc/carray.h b/stc/carray.h
index a7f15ddd..3106b99a 100644
--- a/stc/carray.h
+++ b/stc/carray.h
@@ -30,7 +30,7 @@
Multi-dimensional generic array allocated as one block of heap-memory.
// demo:
#include <stc/carray.h>
-declare_carray(f, float);
+cdef_carray(f, float);
int main()
{
@@ -68,8 +68,8 @@ STC_INLINE size_t _carray3_size(const size_t* zdim) {
}
-#define declare_carray_common(D, X, Value, valueDestroy) \
- typedef struct { Value *item; } carray##D##X##_iter_t; \
+#define cdef_carray_common(D, X, Value, valueDestroy) \
+ typedef struct { Value *get; } carray##D##X##_iter_t; \
\
STC_INLINE carray##D##X##_iter_t \
carray##D##X##_begin(carray##D##X* a) { \
@@ -80,23 +80,23 @@ 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->item;} \
+ carray##D##X##_next(carray##D##X##_iter_t* it) {++it->get;} \
\
STC_INLINE void \
carray##D##X##_destroy(carray##D##X* self) { \
if (self->_xdim & _carray_OWN) { \
c_foreach_3 (i, carray##D##X, *self) \
- valueDestroy(i.item); \
+ valueDestroy(i.get); \
free(self->data); \
} \
}
-#define declare_carray(...) c_MACRO_OVERLOAD(declare_carray, __VA_ARGS__)
-#define declare_carray_2(X, Value) \
- declare_carray_3(X, Value, c_default_destroy)
+#define cdef_carray(...) c_MACRO_OVERLOAD(cdef_carray, __VA_ARGS__)
+#define cdef_carray_2(X, Value) \
+ cdef_carray_3(X, Value, c_default_destroy)
-#define declare_carray_3(X, Value, valueDestroy) \
+#define cdef_carray_3(X, Value, valueDestroy) \
\
typedef Value carray1##X##_value_t; \
typedef carray1##X##_value_t carray2##X##_value_t, carray3##X##_value_t; \
@@ -116,9 +116,9 @@ STC_INLINE size_t _carray3_size(const size_t* zdim) {
size_t _xdim, _yxdim, _zdim; \
} carray3##X; \
\
- declare_carray_common(1, X, Value, valueDestroy) \
- declare_carray_common(2, X, Value, valueDestroy) \
- declare_carray_common(3, X, Value, valueDestroy) \
+ cdef_carray_common(1, X, Value, valueDestroy) \
+ cdef_carray_common(2, X, Value, valueDestroy) \
+ cdef_carray_common(3, X, Value, valueDestroy) \
\
STC_INLINE carray1##X \
carray1##X##_make(size_t xdim, Value val) { \
diff --git a/stc/cbitset.h b/stc/cbitset.h
index 0c5af0e6..b20aedd2 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 item;
+ size_t get;
} 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->item;}
+cbitset_next(cbitset_iter_t* it) {++it->get;}
STC_INLINE bool cbitset_itval(cbitset_iter_t it) {
- return cbitset_test(*it._bs, it.item);
+ return cbitset_test(*it._bs, it.get);
}
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
diff --git a/stc/cdefs.h b/stc/cdefs.h
index dc12b618..df56987e 100644
--- a/stc/cdefs.h
+++ b/stc/cdefs.h
@@ -74,16 +74,16 @@
#define c_mem_equals(x, y) (memcmp(x, y, sizeof(*(y))) == 0)
#define c_default_equals(x, y) (*(x) == *(y))
#define c_default_less(x, y) (*(x) < *(y))
-#define c_compare(less, x, y) (less(x, y) ? -1 : less(y, x))
-#define c_default_compare(x, y) c_compare(c_default_less, x, y)
+#define c_less_compare(less, x, y) (less(x, y) ? -1 : less(y, x))
+#define c_default_compare(x, y) c_less_compare(c_default_less, x, y)
#define c_default_destroy(ptr) ((void) (ptr))
#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.item != it##_end_.item; ctype##_next(&it))
+ for (ctype##_iter_t it = ctype##_begin(&cnt), it##_end_ = ctype##_end(&cnt); it.get != it##_end_.get; ctype##_next(&it))
#define c_foreach_4(it, ctype, start, finish) \
- for (ctype##_iter_t it = start, it##_end_ = finish; it.item != it##_end_.item; ctype##_next(&it))
+ for (ctype##_iter_t it = start, it##_end_ = finish; it.get != it##_end_.get; ctype##_next(&it))
#define c_push(self, ctype, ...) do { \
const ctype##_input_t __arr[] = __VA_ARGS__; \
diff --git a/stc/clist.h b/stc/clist.h
index baba7ed3..827d9096 100644
--- a/stc/clist.h
+++ b/stc/clist.h
@@ -35,7 +35,7 @@
#include <stdio.h>
#include <stc/clist.h>
#include <stc/crandom.h>
- declare_clist(ix, int64_t);
+ cdef_clist(ix, int64_t);
int main() {
clist_ix list = clist_ini;
@@ -45,30 +45,30 @@
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.item->value);
+ if (++n % 10000 == 0) printf("%8d: %10zd\n", n, i.get->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.item->value);
+ if (++n % 10000 == 0) printf("%8d: %10zd\n", n, i.get->value);
clist_ix_destroy(&list);
}
*/
-#define declare_clist(...) c_MACRO_OVERLOAD(declare_clist, __VA_ARGS__)
+#define cdef_clist(...) c_MACRO_OVERLOAD(cdef_clist, __VA_ARGS__)
-#define declare_clist_2(X, Value) \
- declare_clist_3(X, Value, c_default_destroy)
-#define declare_clist_3(X, Value, valueDestroy) \
- declare_clist_4(X, Value, valueDestroy, c_default_compare)
-#define declare_clist_4(X, Value, valueDestroy, valueCompare) \
- declare_clist_7(X, Value, valueDestroy, Value, \
+#define cdef_clist_2(X, Value) \
+ cdef_clist_3(X, Value, c_default_destroy)
+#define cdef_clist_3(X, Value, valueDestroy) \
+ cdef_clist_4(X, Value, valueDestroy, c_default_compare)
+#define cdef_clist_4(X, Value, valueDestroy, valueCompare) \
+ cdef_clist_7(X, Value, valueDestroy, Value, \
valueCompare, c_default_to_raw, c_default_from_raw)
-#define declare_clist_str() declare_clist_7(str, cstr_t, cstr_destroy, const char*, \
- cstr_compare_raw, cstr_to_raw, cstr_make)
+#define cdef_clist_str() cdef_clist_7(str, cstr_t, cstr_destroy, const char*, \
+ cstr_compare_raw, cstr_to_raw, cstr)
-#define declare_clist_types(X, Value) \
+#define cdef_clist_types(X, Value) \
typedef Value clist_##X##_value_t; \
\
typedef struct clist_##X##_node { \
@@ -82,7 +82,7 @@
\
typedef struct { \
clist_##X##_node_t* const* _last; \
- clist_##X##_node_t* item; \
+ clist_##X##_node_t* get; \
int _state; \
} clist_##X##_iter_t
@@ -97,12 +97,12 @@
__pos = ctype##_emplace_after(__self, __pos, __arr[__i]); \
} while (0)
-declare_clist_types(void, int);
+cdef_clist_types(void, int);
STC_API size_t _clist_size(const clist_void* self);
-#define declare_clist_7(X, Value, valueDestroy, RawValue, valueCompareRaw, valueToRaw, valueFromRaw) \
+#define cdef_clist_7(X, Value, valueDestroy, RawValue, valueCompareRaw, valueToRaw, valueFromRaw) \
\
- declare_clist_types(X, Value); \
+ cdef_clist_types(X, Value); \
typedef RawValue clist_##X##_rawvalue_t; \
typedef clist_##X##_rawvalue_t clist_##X##_input_t; \
\
@@ -156,10 +156,10 @@ STC_API size_t _clist_size(const clist_void* self);
} \
STC_INLINE void \
clist_##X##_next(clist_##X##_iter_t* it) { \
- it->item = ((it->_state += it->item == *it->_last) == 1) ? NULL : it->item->next; \
+ it->get = ((it->_state += it->get == *it->_last) == 1) ? NULL : it->get->next; \
} \
STC_INLINE clist_##X##_value_t* \
- clist_##X##_itval(clist_##X##_iter_t it) {return &it.item->value;} \
+ clist_##X##_itval(clist_##X##_iter_t it) {return &it.get->value;} \
\
STC_API clist_##X##_iter_t \
clist_##X##_insert_after(clist_##X* self, clist_##X##_iter_t pos, Value value); \
@@ -171,7 +171,7 @@ STC_API size_t _clist_size(const clist_void* self);
clist_##X##_erase_after(clist_##X* self, clist_##X##_iter_t pos); \
STC_INLINE clist_##X##_iter_t \
clist_##X##_erase_range_after(clist_##X* self, clist_##X##_iter_t pos, clist_##X##_iter_t finish) { \
- while (pos.item != finish.item) pos = clist_##X##_erase_after(self, pos); \
+ while (pos.get != finish.get) pos = clist_##X##_erase_after(self, pos); \
return pos; \
} \
\
@@ -237,21 +237,21 @@ 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_insert_after(self, X, pos.item, value); \
- if (pos.item == self->last && pos._state == 0) self->last = entry; \
- pos.item = entry; return pos; \
+ _clist_insert_after(self, X, pos.get, value); \
+ if (pos.get == self->last && pos._state == 0) self->last = entry; \
+ pos.get = entry; return pos; \
} \
STC_API clist_##X##_iter_t \
clist_##X##_erase_after(clist_##X* self, clist_##X##_iter_t pos) { \
- _clist_erase_after(self, X, pos.item, valueDestroy); \
+ _clist_erase_after(self, X, pos.get, valueDestroy); \
clist_##X##_next(&pos); return pos; \
} \
\
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.item != finish.item; clist_##X##_next(&i)) { \
- RawValue r = valueToRaw(&i.item->value); \
+ for (clist_##X##_next(&i); i.get != finish.get; clist_##X##_next(&i)) { \
+ RawValue r = valueToRaw(&i.get->value); \
if (valueCompareRaw(&r, &val) == 0) return first; \
first = i; \
} \
@@ -261,7 +261,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.item != clist_##X##_end(self).item) clist_##X##_next(&it); \
+ if (it.get != clist_##X##_end(self).get) clist_##X##_next(&it); \
return it; \
} \
\
@@ -269,7 +269,7 @@ STC_API size_t _clist_size(const clist_void* self);
clist_##X##_remove(clist_##X* self, RawValue val) { \
size_t n = 0; \
clist_##X##_iter_t it = clist_##X##_before_begin(self), end = clist_##X##_end(self); \
- while ((it = clist_##X##_find_before(self, it, clist_##X##_end(self), val)).item != clist_##X##_end(self).item) \
+ while ((it = clist_##X##_find_before(self, it, clist_##X##_end(self), val)).get != clist_##X##_end(self).get) \
clist_##X##_erase_after(self, it), ++n; \
return n; \
} \
@@ -307,13 +307,13 @@ STC_API size_t _clist_size(const clist_void* self);
STC_API void
_clist_splice_after(clist_void* self, clist_void_iter_t pos, clist_void* other) {
- if (!pos.item)
+ if (!pos.get)
self->last = other->last;
else if (other->last) {
- clist_void_node_t *next = pos.item->next;
- pos.item->next = other->last->next;
+ clist_void_node_t *next = pos.get->next;
+ pos.get->next = other->last->next;
other->last->next = next;
- if (pos.item == self->last && pos._state == 0) self->last = other->last;
+ if (pos.get == self->last && pos._state == 0) self->last = other->last;
}
other->last = NULL;
}
diff --git a/stc/cmap.h b/stc/cmap.h
index d049cb2b..3cc227cf 100644
--- a/stc/cmap.h
+++ b/stc/cmap.h
@@ -23,15 +23,15 @@
/*
#include <stdio.h>
#include <stc/cmap.h>
-declare_cset(sx, int); // Set of int
-declare_cmap(mx, int, char); // Map of int -> char
+cdef_cset(sx, int); // Set of int
+cdef_cmap(mx, int, char); // Map of int -> char
int main(void) {
cset_sx s = cset_ini;
cset_sx_insert(&s, 5);
cset_sx_insert(&s, 8);
c_foreach (i, cset_sx, s)
- printf("set %d\n", i.item->value);
+ printf("set %d\n", i.get->value);
cset_sx_destroy(&s);
cmap_mx m = cmap_ini;
@@ -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.item->first, i.item->second);
+ printf("map %d: %c\n", i.get->first, i.get->second);
cmap_mx_destroy(&m);
}*/
#ifndef CMAP__H__
@@ -77,73 +77,73 @@ int main(void) {
enum {chash_HASH = 0x7f, chash_USED = 0x80};
typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
-#define declare_cmap(...) \
- c_MACRO_OVERLOAD(declare_cmap, __VA_ARGS__)
+#define cdef_cmap(...) \
+ c_MACRO_OVERLOAD(cdef_cmap, __VA_ARGS__)
-#define declare_cmap_3(X, Key, Mapped) \
- declare_cmap_4(X, Key, Mapped, c_default_destroy)
+#define cdef_cmap_3(X, Key, Mapped) \
+ cdef_cmap_4(X, Key, Mapped, c_default_destroy)
-#define declare_cmap_4(X, Key, Mapped, valueDestroy) \
- declare_cmap_6(X, Key, Mapped, valueDestroy, c_default_equals, c_default_hash16)
+#define cdef_cmap_4(X, Key, Mapped, valueDestroy) \
+ cdef_cmap_6(X, Key, Mapped, valueDestroy, c_default_equals, c_default_hash16)
-#define declare_cmap_6(X, Key, Mapped, valueDestroy, keyEquals, keyHash) \
- declare_cmap_10(X, Key, Mapped, valueDestroy, keyEquals, keyHash, \
+#define cdef_cmap_6(X, Key, Mapped, valueDestroy, keyEquals, keyHash) \
+ cdef_cmap_10(X, Key, Mapped, valueDestroy, keyEquals, keyHash, \
c_default_destroy, Key, c_default_to_raw, c_default_from_raw)
-#define declare_cmap_10(X, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
+#define cdef_cmap_10(X, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
keyDestroy, RawKey, keyToRaw, keyFromRaw) \
- declare_CHASH(X, cmap, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
- keyDestroy, RawKey, keyToRaw, keyFromRaw, Mapped, c_default_from_raw)
+ _declare_CHASH(X, cmap, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
+ keyDestroy, RawKey, keyToRaw, keyFromRaw, Mapped, c_default_from_raw)
/* cset: */
-#define declare_cset(...) \
- c_MACRO_OVERLOAD(declare_cset, __VA_ARGS__)
+#define cdef_cset(...) \
+ c_MACRO_OVERLOAD(cdef_cset, __VA_ARGS__)
-#define declare_cset_2(X, Key) \
- declare_cset_4(X, Key, c_default_equals, c_default_hash16)
+#define cdef_cset_2(X, Key) \
+ cdef_cset_4(X, Key, c_default_equals, c_default_hash16)
-#define declare_cset_4(X, Key, keyEquals, keyHash) \
- declare_cset_5(X, Key, keyEquals, keyHash, c_default_destroy)
+#define cdef_cset_4(X, Key, keyEquals, keyHash) \
+ cdef_cset_5(X, Key, keyEquals, keyHash, c_default_destroy)
-#define declare_cset_5(X, Key, keyEquals, keyHash, keyDestroy) \
- declare_cset_8(X, Key, keyEquals, keyHash, keyDestroy, \
+#define cdef_cset_5(X, Key, keyEquals, keyHash, keyDestroy) \
+ cdef_cset_8(X, Key, keyEquals, keyHash, keyDestroy, \
Key, c_default_to_raw, c_default_from_raw)
-#define declare_cset_8(X, Key, keyEqualsRaw, keyHashRaw, keyDestroy, \
+#define cdef_cset_8(X, Key, keyEqualsRaw, keyHashRaw, keyDestroy, \
RawKey, keyToRaw, keyFromRaw) \
- declare_CHASH(X, cset, Key, Key, void, keyEqualsRaw, keyHashRaw, \
+ _declare_CHASH(X, cset, Key, Key, void, keyEqualsRaw, keyHashRaw, \
keyDestroy, RawKey, keyToRaw, keyFromRaw, void, c_default_from_raw)
/* cset_str, cmap_str, cmap_strkey, cmap_strval: */
-#define declare_cset_str() \
- declare_CHASH_strkey(str, cset, cstr_t, void)
+#define cdef_cset_str() \
+ _declare_CHASH_strkey(str, cset, cstr_t, void)
-#define declare_cmap_str() \
- declare_CHASH(str, cmap, cstr_t, cstr_t, cstr_destroy, cstr_equals_raw, cstr_hash_raw, \
- cstr_destroy, const char*, cstr_to_raw, cstr_make, const char*, cstr_make)
+#define cdef_cmap_str() \
+ _declare_CHASH(str, cmap, cstr_t, cstr_t, cstr_destroy, cstr_equals_raw, cstr_hash_raw, \
+ cstr_destroy, const char*, cstr_to_raw, cstr, const char*, cstr)
-#define declare_cmap_strkey(...) \
- c_MACRO_OVERLOAD(declare_cmap_strkey, __VA_ARGS__)
+#define cdef_cmap_strkey(...) \
+ c_MACRO_OVERLOAD(cdef_cmap_strkey, __VA_ARGS__)
-#define declare_cmap_strkey_2(X, Mapped) \
- declare_CHASH_strkey(X, cmap, Mapped, c_default_destroy)
+#define cdef_cmap_strkey_2(X, Mapped) \
+ _declare_CHASH_strkey(X, cmap, Mapped, c_default_destroy)
-#define declare_cmap_strkey_3(X, Mapped, ValueDestroy) \
- declare_CHASH_strkey(X, cmap, Mapped, ValueDestroy)
+#define cdef_cmap_strkey_3(X, Mapped, ValueDestroy) \
+ _declare_CHASH_strkey(X, cmap, Mapped, ValueDestroy)
-#define declare_cmap_strval(...) \
- c_MACRO_OVERLOAD(declare_cmap_strval, __VA_ARGS__)
+#define cdef_cmap_strval(...) \
+ c_MACRO_OVERLOAD(cdef_cmap_strval, __VA_ARGS__)
-#define declare_cmap_strval_2(X, Key) \
- declare_cmap_strval_4(X, Key, c_default_equals, c_default_hash16)
+#define cdef_cmap_strval_2(X, Key) \
+ cdef_cmap_strval_4(X, Key, c_default_equals, c_default_hash16)
-#define declare_cmap_strval_4(X, Key, keyEquals, keyHash) \
- declare_CHASH(X, cmap, Key, cstr_t, cstr_destroy, keyEquals, keyHash, \
- c_default_destroy, Key, c_default_to_raw, c_default_from_raw, const char*, cstr_make)
+#define cdef_cmap_strval_4(X, Key, keyEquals, keyHash) \
+ _declare_CHASH(X, cmap, Key, cstr_t, cstr_destroy, keyEquals, keyHash, \
+ c_default_destroy, Key, c_default_to_raw, c_default_from_raw, const char*, cstr)
-#define declare_CHASH_strkey(X, ctype, Mapped, valueDestroy) \
- declare_CHASH(X, ctype, cstr_t, Mapped, valueDestroy, cstr_equals_raw, cstr_hash_raw, \
- cstr_destroy, const char*, cstr_to_raw, cstr_make, Mapped, c_default_from_raw)
+#define _declare_CHASH_strkey(X, ctype, Mapped, valueDestroy) \
+ _declare_CHASH(X, ctype, cstr_t, Mapped, valueDestroy, cstr_equals_raw, cstr_hash_raw, \
+ cstr_destroy, const char*, cstr_to_raw, cstr, Mapped, c_default_from_raw)
#define CSET_ONLY_cset(...) __VA_ARGS__
#define CSET_ONLY_cmap(...)
@@ -153,7 +153,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
#define CMAP_ARGS_cmap(x, y) x, y
/* CHASH full: use 'void' for Mapped if ctype is cset */
-#define declare_CHASH(X, ctype, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
+#define _declare_CHASH(X, ctype, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
keyDestroy, RawKey, keyToRaw, keyFromRaw, RawVal, valueFromRaw) \
typedef Key ctype##_##X##_key_t; \
typedef Mapped ctype##_##X##_mapped_t; \
@@ -191,7 +191,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
} ctype##_##X; \
\
typedef struct { \
- ctype##_##X##_value_t *item; \
+ ctype##_##X##_value_t *get; \
uint8_t* _hx; \
} ctype##_##X##_iter_t; \
\
@@ -268,7 +268,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.item, ++it._hx; \
+ if (it._hx) while (*it._hx == 0) ++it.get, ++it._hx; \
return it; \
} \
STC_INLINE ctype##_##X##_iter_t \
@@ -277,13 +277,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->item, *++it->_hx == 0)) ; \
+ while ((++it->get, *++it->_hx == 0)) ; \
} \
CMAP_ONLY_##ctype( STC_INLINE ctype##_##X##_mapped_t* \
- ctype##_##X##_itval(ctype##_##X##_iter_t it) {return &it.item->value;} ) \
+ ctype##_##X##_itval(ctype##_##X##_iter_t it) {return &it.get->value;} ) \
\
STC_API void \
- ctype##_##X##_erase_entry(ctype##_##X* self, ctype##_##X##_value_t* item); \
+ ctype##_##X##_erase_entry(ctype##_##X* self, ctype##_##X##_value_t* get); \
STC_INLINE size_t \
ctype##_##X##_erase(ctype##_##X* self, RawKey rawKey) { \
if (self->size == 0) return 0; \
@@ -292,20 +292,20 @@ 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.item); \
+ ctype##_##X##_erase_entry(self, pos.get); \
ctype##_##X##_next(&pos); return pos; \
} \
\
STC_API uint32_t c_default_hash16(const void *data, size_t len); \
STC_API uint32_t c_default_hash32(const void* data, size_t len); \
\
- implement_CHASH(X, ctype, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
+ _implement_CHASH(X, ctype, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
keyDestroy, RawKey, keyToRaw, keyFromRaw, RawVal, valueFromRaw)
/* -------------------------- IMPLEMENTATION ------------------------- */
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
-#define implement_CHASH(X, ctype, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
+#define _implement_CHASH(X, ctype, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
keyDestroy, RawKey, keyToRaw, keyFromRaw, RawVal, valueFromRaw) \
STC_API ctype##_##X \
ctype##_##X##_with_capacity(size_t cap) { \
@@ -410,8 +410,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* item) { \
- size_t i = chash_entry_index(*self, item), j = i, k, cap = self->bucket_count; \
+ 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##_value_t* slot = self->table; \
uint8_t* hashx = self->_hashx; \
ctype##_##X##_entry_destroy(&slot[i]); \
@@ -446,7 +446,7 @@ STC_API uint32_t c_default_hash32(const void* data, size_t len) {
}
#else
-#define implement_CHASH(X, ctype, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
+#define _implement_CHASH(X, ctype, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
keyDestroy, RawKey, keyToRaw, keyFromRaw)
#endif
diff --git a/stc/cpqueue.h b/stc/cpqueue.h
index 47612e2c..d5f5a9e6 100644
--- a/stc/cpqueue.h
+++ b/stc/cpqueue.h
@@ -25,8 +25,8 @@
#include <stc/crandom.h>
#include <stc/cpqueue.h>
- declare_cvec(f, float);
- declare_cpqueue(f, cvec_f, >); // min-heap (increasing values)
+ cdef_cvec(f, float);
+ cdef_cpqueue(f, cvec_f, >); // min-heap (increasing values)
int main() {
crand_rng32_t gen = crand_rng32_init(1234);
@@ -50,7 +50,7 @@
#include "cvec.h"
-#define declare_cpqueue(X, ctype, cmpOpr) /* cmpOpr: < or > */ \
+#define cdef_cpqueue(X, ctype, cmpOpr) /* cmpOpr: < or > */ \
\
typedef struct ctype cpqueue_##X; \
typedef ctype##_value_t cpqueue_##X##_value_t; \
diff --git a/stc/cqueue.h b/stc/cqueue.h
index 8e6d7096..dfdab1cd 100644
--- a/stc/cqueue.h
+++ b/stc/cqueue.h
@@ -25,8 +25,8 @@
#include <stc/crandom.h>
#include <stc/cqueue.h>
- declare_clist(i, int);
- declare_cqueue(i, clist_i); // min-heap (increasing values)
+ cdef_clist(i, int);
+ cdef_cqueue(i, clist_i); // min-heap (increasing values)
int main() {
int n = 10000000;
@@ -58,7 +58,7 @@
#include "clist.h"
-#define declare_cqueue(X, ctype) \
+#define cdef_cqueue(X, ctype) \
\
typedef struct ctype cqueue_##X; \
typedef ctype##_value_t cqueue_##X##_value_t; \
diff --git a/stc/cstack.h b/stc/cstack.h
index 8f124930..65ccc45f 100644
--- a/stc/cstack.h
+++ b/stc/cstack.h
@@ -26,8 +26,8 @@
#include <stc/cstack.h>
#include <stdio.h>
- declare_cvec(i, int);
- declare_cstack(i, cvec_i);
+ cdef_cvec(i, int);
+ cdef_cstack(i, cvec_i);
int main() {
cstack_i stack = cstack_i_init();
@@ -47,7 +47,7 @@
#include "cvec.h"
-#define declare_cstack(X, ctype) \
+#define cdef_cstack(X, ctype) \
\
typedef struct ctype cstack_##X; \
typedef ctype##_value_t cstack_##X##_value_t; \
diff --git a/stc/cstr.h b/stc/cstr.h
index bd447a59..351e1beb 100644
--- a/stc/cstr.h
+++ b/stc/cstr.h
@@ -30,7 +30,7 @@
#include "cdefs.h"
typedef struct cstr { char* str; } cstr_t;
-typedef struct { char *item; } cstr_iter_t;
+typedef struct { char *get; } cstr_iter_t;
typedef char cstr_value_t;
static size_t _cstr_nullrep[] = {0, 0, 0};
@@ -42,7 +42,7 @@ static cstr_t cstr_ini = {(char* ) &_cstr_nullrep[2]};
#define cstr_npos ((size_t) (-1))
STC_API cstr_t
-cstr_make_n(const char* str, size_t len);
+cstr_n(const char* str, size_t len);
STC_API cstr_t
cstr_from(const char* fmt, ...);
STC_API void
@@ -89,13 +89,13 @@ cstr_with_size(size_t len, char fill) {
return s;
}
STC_INLINE cstr_t
-cstr_make(const char* str) {
- return cstr_make_n(str, strlen(str));
+cstr(const char* str) {
+ return cstr_n(str, strlen(str));
}
STC_INLINE cstr_t
cstr_clone(cstr_t s) {
- return cstr_make_n(s.str, cstr_size(s));
+ return cstr_n(s.str, cstr_size(s));
}
STC_INLINE void
@@ -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->item; }
-STC_INLINE char* cstr_itval(cstr_iter_t it) {return it.item;}
+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 cstr_t*
cstr_assign(cstr_t* self, const char* str) {
@@ -228,7 +228,7 @@ cstr_resize(cstr_t* self, size_t len, char fill) {
}
STC_API cstr_t
-cstr_make_n(const char* str, size_t len) {
+cstr_n(const char* str, size_t len) {
if (len == 0) return cstr_ini;
size_t *rep = (size_t *) malloc(_cstr_mem(len));
cstr_t s = {(char *) memcpy(rep + 2, str, len)};
diff --git a/stc/cvec.h b/stc/cvec.h
index 98c970f0..1adb3cca 100644
--- a/stc/cvec.h
+++ b/stc/cvec.h
@@ -32,18 +32,18 @@
#define cvec_capacity(v) _cvec_safe_capacity((v).data)
#define cvec_empty(v) (cvec_size(v) == 0)
-#define declare_cvec(...) c_MACRO_OVERLOAD(declare_cvec, __VA_ARGS__)
-#define declare_cvec_2(X, Value) \
- declare_cvec_3(X, Value, c_default_destroy)
-#define declare_cvec_3(X, Value, valueDestroy) \
- declare_cvec_4(X, Value, valueDestroy, c_default_compare)
-#define declare_cvec_4(X, Value, valueDestroy, valueCompare) \
- declare_cvec_7(X, Value, valueDestroy, valueCompare, Value, c_default_to_raw, c_default_from_raw)
-#define declare_cvec_str() \
- declare_cvec_7(str, cstr_t, cstr_destroy, cstr_compare_raw, const char*, cstr_to_raw, cstr_make)
+#define cdef_cvec(...) c_MACRO_OVERLOAD(cdef_cvec, __VA_ARGS__)
+#define cdef_cvec_2(X, Value) \
+ cdef_cvec_3(X, Value, c_default_destroy)
+#define cdef_cvec_3(X, Value, valueDestroy) \
+ cdef_cvec_4(X, Value, valueDestroy, c_default_compare)
+#define cdef_cvec_4(X, Value, valueDestroy, valueCompare) \
+ cdef_cvec_7(X, Value, valueDestroy, valueCompare, Value, c_default_to_raw, c_default_from_raw)
+#define cdef_cvec_str() \
+ cdef_cvec_7(str, cstr_t, cstr_destroy, cstr_compare_raw, const char*, cstr_to_raw, cstr)
-#define declare_cvec_7(X, Value, valueDestroy, valueCompareRaw, RawValue, valueToRaw, valueFromRaw) \
+#define cdef_cvec_7(X, Value, valueDestroy, valueCompareRaw, RawValue, valueToRaw, valueFromRaw) \
\
typedef struct cvec_##X { \
Value* data; \
@@ -51,7 +51,7 @@
typedef Value cvec_##X##_value_t; \
typedef RawValue cvec_##X##_rawvalue_t; \
typedef cvec_##X##_rawvalue_t cvec_##X##_input_t; \
- typedef struct { Value *item; } cvec_##X##_iter_t; \
+ typedef struct { Value *get; } cvec_##X##_iter_t; \
\
STC_INLINE cvec_##X \
cvec_##X##_init(void) {cvec_##X v = cvec_ini; return v;} \
@@ -132,12 +132,12 @@
\
STC_INLINE cvec_##X##_iter_t \
cvec_##X##_erase_at(cvec_##X* self, cvec_##X##_iter_t pos) { \
- cvec_##X##_iter_t next = {pos.item + 1}; \
+ cvec_##X##_iter_t next = {pos.get + 1}; \
return cvec_##X##_erase_range(self, pos, next); \
} \
STC_INLINE cvec_##X##_iter_t \
cvec_##X##_erase_at_idx(cvec_##X* self, size_t idx) { \
- cvec_##X##_iter_t first = {self->data + idx}, finish = {first.item + 1}; \
+ cvec_##X##_iter_t first = {self->data + idx}, finish = {first.get + 1}; \
return cvec_##X##_erase_range(self, first, finish); \
} \
STC_INLINE cvec_##X##_iter_t \
@@ -181,11 +181,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->item;} \
+ cvec_##X##_next(cvec_##X##_iter_t* it) {++it->get;} \
STC_INLINE cvec_##X##_value_t* \
- cvec_##X##_itval(cvec_##X##_iter_t it) {return it.item;} \
+ cvec_##X##_itval(cvec_##X##_iter_t it) {return it.get;} \
STC_INLINE size_t \
- cvec_##X##_idx(cvec_##X v, cvec_##X##_iter_t it) {return it.item - v.data;} \
+ cvec_##X##_idx(cvec_##X v, cvec_##X##_iter_t it) {return it.get - v.data;} \
\
implement_cvec_7(X, Value, valueDestroy, RawValue, valueCompareRaw, valueToRaw, valueFromRaw)
@@ -242,13 +242,13 @@
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) { \
enum {max_buf = c_max_alloca / sizeof(Value) + 1}; Value buf[max_buf]; \
- size_t len = finish.item - first.item, idx = pos.item - self->data, size = cvec_size(*self); \
- Value* xbuf = (Value *) memcpy(len > max_buf ? c_new_n(Value, len) : buf, first.item, len * sizeof(Value)); \
+ size_t len = finish.get - first.get, idx = pos.get - self->data, size = cvec_size(*self); \
+ Value* xbuf = (Value *) memcpy(len > max_buf ? c_new_n(Value, len) : buf, first.get, len * sizeof(Value)); \
if (size + len > cvec_capacity(*self)) \
cvec_##X##_reserve(self, 4 + (size + len) * 3 / 2); \
- pos.item = self->data + idx; \
- memmove(pos.item + len, pos.item, (size - idx) * sizeof(Value)); \
- memcpy(pos.item, xbuf, len * sizeof(Value)); \
+ pos.get = self->data + idx; \
+ memmove(pos.get + len, pos.get, (size - idx) * sizeof(Value)); \
+ memcpy(pos.get, xbuf, len * sizeof(Value)); \
_cvec_size(self) += len; \
if (len > max_buf) free(xbuf); \
return pos; \
@@ -256,11 +256,11 @@
\
STC_API cvec_##X##_iter_t \
cvec_##X##_erase_range(cvec_##X* self, cvec_##X##_iter_t first, cvec_##X##_iter_t finish) { \
- intptr_t len = finish.item - first.item; \
+ intptr_t len = finish.get - first.get; \
if (len > 0) { \
- Value* p = first.item, *end = p + _cvec_size(self); \
- while (p != finish.item) valueDestroy(p++); \
- memmove(first.item, finish.item, (end - finish.item) * sizeof(Value)); \
+ Value* p = first.get, *end = p + _cvec_size(self); \
+ while (p != finish.get) valueDestroy(p++); \
+ memmove(first.get, finish.get, (end - finish.get) * sizeof(Value)); \
_cvec_size(self) -= len; \
} \
return first; \
@@ -268,8 +268,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.item != finish.item; cvec_##X##_next(&first)) { \
- RawValue r = valueToRaw(first.item); \
+ for (; first.get != finish.get; cvec_##X##_next(&first)) { \
+ RawValue r = valueToRaw(first.get); \
if (valueCompareRaw(&r, &rawValue) == 0) return first; \
} \
return cvec_##X##_end(self); \