summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-07-28 06:47:33 +0200
committerTyge Løvset <[email protected]>2020-07-28 06:47:33 +0200
commitb818bb967c6050d14a9c7058f02592a4ffeef9b4 (patch)
treec55c74d129692fdc6ab93d934fc252c7c8acbef7
parentb5351558ac6d5f78750fe93ed9390fed5efa2ac4 (diff)
downloadSTC-modified-b818bb967c6050d14a9c7058f02592a4ffeef9b4.tar.gz
STC-modified-b818bb967c6050d14a9c7058f02592a4ffeef9b4.zip
Lowercase naming
-rw-r--r--README.md46
-rw-r--r--examples/README.md6
-rw-r--r--examples/advanced.c6
-rw-r--r--examples/benchmark.c14
-rw-r--r--examples/bits.c12
-rw-r--r--examples/complex.c4
-rw-r--r--examples/demos.c26
-rw-r--r--examples/geek2.c2
-rw-r--r--examples/geek3.c2
-rw-r--r--examples/geek4.c20
-rw-r--r--examples/geek5.c4
-rw-r--r--examples/geek7.c2
-rw-r--r--examples/heap.c2
-rw-r--r--examples/inits.c6
-rw-r--r--examples/list.c2
-rw-r--r--examples/prime.c2
-rw-r--r--stc/carray.h8
-rw-r--r--stc/cbitset.h74
-rw-r--r--stc/cdefs.h22
-rw-r--r--stc/clist.h78
-rw-r--r--stc/cmap.h60
-rw-r--r--stc/cstr.h160
-rw-r--r--stc/cvec.h20
-rw-r--r--stc/cvecpq.h14
24 files changed, 296 insertions, 296 deletions
diff --git a/README.md b/README.md
index 7d5cb132..03ef8bf3 100644
--- a/README.md
+++ b/README.md
@@ -19,14 +19,14 @@ in *O*(1). Also contains various *splice* functions and (merge) *sort*.
The usage of the containers is similar to the C++ standard containers, so it should be easier for those who are familiar with them.
-All containers mentioned above, except for cstr_t are generic (similar to templates in C++). A simple example:
+All containers mentioned above, except for cstr are generic (similar to templates in C++). A simple example:
```
#include <stc/cvec.h>
declare_cvec(i, int);
int main(void) {
cvec_i vec = cvec_init;
- cvec_i_pushBack(&vec, 42);
+ cvec_i_push_back(&vec, 42);
cvec_i_destroy(&vec);
}
```
@@ -104,15 +104,15 @@ cmap, cset and cvec discussion
**cmap/cset** are the most complex of the containers (although, currently only ~370 lines of code). It uses open hashing, but does not rely on power-of-two size table, nor prime number lengths, and it does not have tombstone buckets. It is still among the fastest hash-tables, as shown above. The default max load-factor is 0.85, and it shrinks (and rehashes) when load-factor goes below 0.15, by default (can be set per hash container).
-You may customize the destroy-, hash- and equals- function. It 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 handy when e.g. having cstr_t as key, as it enables the usage of string literals as key in *put() and *get() functions, instead of requering a constructed cstr_t. Without it, you would have to write:
+You may customize the destroy-, hash- and equals- function. It 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 handy when e.g. having cstr as key, as it enables the usage of string literals as key in *put() and *get() functions, instead of requering a constructed cstr. Without it, you would have to write:
```
-declare_cmap(si, cstr_t, int);
+declare_cmap(si, cstr, int);
...
cmap_si_put(&map, cstr_make("mykey"), 12);
```
but the main incovenience is with lookup:
```
-cstr_t lookup = cstr_make("mykey");
+cstr lookup = cstr_make("mykey");
int x = cmap_si_get(&map, lookup)->value;
cstr_destroy(&lookup);
```
@@ -121,7 +121,7 @@ To avoid this, use *declare_cmap_str()*:
declare_cmap_str(si, int);
...
cmap_si map = cmap_init;
-cmap_si_put(&map, "mykey", 12); // constructs a cstr_t key from the const char* internally.
+cmap_si_put(&map, "mykey", 12); // constructs a cstr key from the const char* internally.
int x = cmap_si_get(&map, "mykey")->value; // no allocation of string key happens here.
cmap_si_destroy(&map);
```
@@ -133,9 +133,9 @@ Also look at **examples/advanced.c**, it demonstrates how to use a custom struct
Example usages
--------------
The first example has a very complex nested container type, which demonstrates the power of this library. Look at the simpler examples below to understand it better. The example adds an element into the data structure, and then accesses it. The type used, with c++ template syntax is:
-**cmapMap**< **cstr_t**, **cmapMap**< *int*, **clist**< **carray2**< *float* >>>>
+**cmapMap**< **cstr**, **cmapMap**< *int*, **clist**< **carray2**< *float* >>>>
-Note: The *cmap_sm_destroy(&theMap)* call below, will destroy all the nested containers including the memory allocated for cstr_t keys in theMap object.
+Note: The *cmap_sm_destroy(&theMap)* call below, will destroy all the nested containers including the memory allocated for cstr keys in theMap object.
```
#include <stc/cstr.h>
#include <stc/cmap.h>
@@ -145,7 +145,7 @@ Note: The *cmap_sm_destroy(&theMap)* call below, will destroy all the nested con
void verify_destroy(float* v) {printf("destroy %g\n", *v);}
declare_carray(f, float, verify_destroy); // you should omit the last argument - float type need no destroy.
-declare_clist(t2, carray2_f, carray2_f_destroy, c_noCompare);
+declare_clist(t2, carray2_f, carray2_f_destroy, c_no_compare);
declare_cmap(il, int, clist_t2, clist_t2_destroy);
declare_cmap_str(sm, cmap_il, cmap_il_destroy);
@@ -161,7 +161,7 @@ int main() {
// Put in some data.
carray2_f_data(table, x)[y] = 3.1415927; // table[x][y]
- clist_t2_pushBack(&tableList, table);
+ clist_t2_push_back(&tableList, table);
cmap_il_put(&listMap, entry, tableList);
cmap_sm_put(&theMap, "First", listMap);
}
@@ -173,12 +173,12 @@ int main() {
cmap_sm_destroy(&theMap); // free up the whole shebang!
}
```
-**cstr_t** string example.
+**cstr** string example.
```
#include <stc/cstr.h>
int main() {
- cstr_t s1 = cstr_make("one-nine-three-seven-five");
+ cstr s1 = cstr_make("one-nine-three-seven-five");
printf("%s.\n", s1.str);
cstr_insert(&s1, 3, "-two");
@@ -197,7 +197,7 @@ int main() {
printf("append: %s\n", s1.str);
cstr_destroy(&s1);
- cstr_t s2 = cstr_from("Index %d: %f", 123, 4.56);
+ cstr s2 = cstr_from("Index %d: %f", 123, 4.56);
cstr_destroy(&s2);
}
```
@@ -210,8 +210,8 @@ int main() {
cvec_ix bignums = cvec_init; // use cvec_ix_init() if initializing after declaration.
cvec_ix_reserve(&bignums, 100);
for (size_t i = 0; i<100; ++i)
- cvec_ix_pushBack(&bignums, i * i * i);
- cvec_ix_popBack(&bignums); // erase the last
+ cvec_ix_push_back(&bignums, i * i * i);
+ cvec_ix_pop_back(&bignums); // erase the last
uint64_t value;
for (size_t i = 0; i < cvec_size(bignums); ++i)
@@ -219,7 +219,7 @@ int main() {
cvec_ix_destroy(&bignums);
}
```
-**cvec** of *cstr_t*.
+**cvec** of *cstr*.
```
#include <stc/cstr.h>
#include <stc/cvec.h>
@@ -227,8 +227,8 @@ declare_cvec_str();
int main() {
cvec_str names = cvec_init;
- cvec_str_pushBack(&names, cstr_make("Mary"));
- cvec_str_pushBack(&names, cstr_make("Joe"));
+ cvec_str_push_back(&names, cstr_make("Mary"));
+ cvec_str_push_back(&names, cstr_make("Joe"));
cstr_assign(&names.data[1], cstr_make("Jake")); // replace Joe
printf("%s\n", names.data[1].str); // Access the string char*
@@ -250,11 +250,11 @@ int main() {
cmap_ii_destroy(&nums);
}
```
-**cset** of *cstr_t*.
+**cset** of *cstr*.
```
#include <stc/cstr.h>
#include <stc/cmap.h>
-declare_cset_str(); // cstr_t set. See the discussion above.
+declare_cset_str(); // cstr set. See the discussion above.
int main() {
cset_str words = cset_init;
@@ -268,11 +268,11 @@ int main() {
cset_str_destroy(&words);
}
```
-**cmap** of *cstr_t -> cstr_t*. Temporary cstr_t values are created by *cstr_make()*, and moved into the container
+**cmap** of *cstr -> cstr*. Temporary cstr values are created by *cstr_make()*, and moved into the container
```
#include <stc/cstr.h>
#include <stc/cmap.h>
-declare_cmap_str(ss, cstr_t, cstr_destroy);
+declare_cmap_str(ss, cstr, cstr_destroy);
int main() {
cmap_ss table = cmap_init;
@@ -298,7 +298,7 @@ int main() {
int N = 2000000, n;
crandom64_t rng = crandom64_uniform_engine(time(NULL));
for (int i=0; i<N; ++i) // two million random numbers
- clist_i_pushBack(&list, crandom64_uinform_int(&rng));
+ clist_i_push_back(&list, crandom64_uinform_int(&rng));
n = 0;
c_foreach (i, clist_i, list)
if (++n % (N/50) == 0) printf("%10d: %zu\n", n, i.item->value);
diff --git a/examples/README.md b/examples/README.md
index e222f8bc..ededc828 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -40,8 +40,8 @@ int vikingvw_equals(const VikingVw* x, const VikingVw* y) {
And the Viking data struct:
```
typedef struct Viking {
- cstr_t name;
- cstr_t country;
+ cstr name;
+ cstr country;
} Viking;
@@ -60,7 +60,7 @@ Viking viking_fromVw(VikingVw vw) {
```
With this in place, we use the full declare_cmap() macro to define {Viking -> int} hash map type:
```
-declare_cmap(vk, Viking, int, c_defaultDestroy, vikingvw_equals, vikingvw_hash,
+declare_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
viking_destroy, VikingVw, viking_getVw, 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.
diff --git a/examples/advanced.c b/examples/advanced.c
index b5481f94..bba534ca 100644
--- a/examples/advanced.c
+++ b/examples/advanced.c
@@ -34,8 +34,8 @@ int vikingvw_equals(const VikingVw* x, const VikingVw* y) {
// Viking data struct -----------------------
typedef struct Viking {
- cstr_t name;
- cstr_t country;
+ cstr name;
+ cstr country;
} Viking;
@@ -53,7 +53,7 @@ Viking viking_fromVw(VikingVw vw) {
// Using the full declare_cmap() macro to define [Viking -> int] hash map type:
-declare_cmap(vk, Viking, int, c_defaultDestroy, vikingvw_equals, vikingvw_hash,
+declare_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
viking_destroy, VikingVw, viking_getVw, viking_fromVw);
// cmap_vk uses vikingvw_hash() for hash value calculations, and vikingvw_equals() for equality test.
diff --git a/examples/benchmark.c b/examples/benchmark.c
index 7ac6481e..568ba880 100644
--- a/examples/benchmark.c
+++ b/examples/benchmark.c
@@ -14,12 +14,12 @@
// Visual Studio: compile with -TP to force C++: cl -TP -EHsc -O2 benchmark.c
-declare_cmap(ii, int64_t, int64_t, c_defaultDestroy, c_defaultEquals, c_fibonacciHash64);
+declare_cmap(ii, int64_t, int64_t, c_default_destroy, c_default_equals, c_fibonacci_hash64);
KHASH_MAP_INIT_INT64(ii, uint64_t)
size_t seed;
-static const float maxLoadFactor = 0.77f;
+static const float max_load_factor = 0.77f;
crandom64_t rng;
#define SEED(s) rng = crandom64_uniform_engine(seed)
@@ -27,12 +27,12 @@ crandom64_t rng;
#define CMAP_SETUP(tag, Key, Value) cmap_##tag map = cmap_init \
- ; cmap_##tag##_setLoadFactors(&map, maxLoadFactor, 0.0)
+ ; cmap_##tag##_set_load_factors(&map, max_load_factor, 0.0)
#define CMAP_PUT(tag, key, val) cmap_##tag##_put(&map, key, val)->value
#define CMAP_ERASE(tag, key) cmap_##tag##_erase(&map, key)
#define CMAP_FIND(tag, key) (cmap_##tag##_find(map, key) != NULL)
#define CMAP_SIZE(tag) cmap_size(map)
-#define CMAP_BUCKETS(tag) (map).bucketCount
+#define CMAP_BUCKETS(tag) (map).bucket_count
#define CMAP_CLEAR(tag) cmap_##tag##_destroy(&map)
#define KMAP_SETUP(tag, Key, Value) khash_t(ii)* map = kh_init(ii); khiter_t ki; int ret
@@ -43,7 +43,7 @@ crandom64_t rng;
#define KMAP_BUCKETS(tag) ((size_t) kh_n_buckets(map))
#define KMAP_CLEAR(tag) kh_destroy(ii, map)
-#define UMAP_SETUP(tag, Key, Value) std::unordered_map<Key, Value> map; map.max_load_factor(maxLoadFactor)
+#define UMAP_SETUP(tag, Key, Value) std::unordered_map<Key, Value> map; map.max_load_factor(max_load_factor)
#define UMAP_PUT(tag, key, val) (map[key] = val)
#define UMAP_FIND(tag, key) (map.find(key) != map.end())
#define UMAP_ERASE(tag, key) map.erase(key)
@@ -51,7 +51,7 @@ crandom64_t rng;
#define UMAP_BUCKETS(tag) map.bucket_count()
#define UMAP_CLEAR(tag) map.clear()
-#define BMAP_SETUP(tag, Key, Value) ska::bytell_hash_map<Key, Value> map; map.max_load_factor(maxLoadFactor)
+#define BMAP_SETUP(tag, Key, Value) ska::bytell_hash_map<Key, Value> map; map.max_load_factor(max_load_factor)
#define BMAP_PUT(tag, key, val) (map[key] = val)
#define BMAP_FIND(tag, key) (map.find(key) != map.end())
#define BMAP_ERASE(tag, key) map.erase(key)
@@ -59,7 +59,7 @@ crandom64_t rng;
#define BMAP_BUCKETS(tag) map.bucket_count()
#define BMAP_CLEAR(tag) map.clear()
-#define FMAP_SETUP(tag, Key, Value) ska::flat_hash_map<Key, Value> map; map.max_load_factor(maxLoadFactor)
+#define FMAP_SETUP(tag, Key, Value) ska::flat_hash_map<Key, Value> map; map.max_load_factor(max_load_factor)
#define FMAP_PUT(tag, key, val) (map[key] = val)
#define FMAP_FIND(tag, key) (map.find(key) != map.end())
#define FMAP_ERASE(tag, key) map.erase(key)
diff --git a/examples/bits.c b/examples/bits.c
index 7c048c80..fd074232 100644
--- a/examples/bits.c
+++ b/examples/bits.c
@@ -2,7 +2,7 @@
#include <stc/cbitset.h>
int main() {
- cbitset_t set = cbitset_make(23, true);
+ cbitset set = cbitset_make(23, true);
printf("count %zu, %zu\n", cbitset_count(set), set.size);
cbitset_reset(&set, 9);
cbitset_resize(&set, 43, false);
@@ -15,14 +15,14 @@ int main() {
cbitset_resize(&set, 77, true);
cbitset_resize(&set, 93, false);
cbitset_resize(&set, 102, true);
- cbitset_setTo(&set, 99, false);
+ cbitset_set_to(&set, 99, false);
printf("%4zu: ", set.size);
for (int i=0; i<set.size; ++i)
printf("%d", cbitset_test(set, i));
puts("");
- cbitset_t s2 = cbitset_from(set);
- cbitset_flipAll(&s2);
+ cbitset s2 = cbitset_from(set);
+ cbitset_flip_all(&s2);
cbitset_set(&s2, 16);
cbitset_set(&s2, 17);
cbitset_set(&s2, 18);
@@ -32,12 +32,12 @@ int main() {
puts("");
printf(" xor: ");
- cbitset_setXor(&set, s2);
+ cbitset_set_xor(&set, s2);
for (int i=0; i<set.size; ++i)
printf("%d", cbitset_test(set, i));
puts("");
- cbitset_setAll(&set, false);
+ cbitset_set_all(&set, false);
printf("%4zu: ", set.size);
for (int i=0; i<set.size; ++i)
printf("%d", cbitset_test(set, i));
diff --git a/examples/complex.c b/examples/complex.c
index 87caaa4e..6a6a268b 100644
--- a/examples/complex.c
+++ b/examples/complex.c
@@ -6,7 +6,7 @@
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(t2, carray2f, carray2f_destroy, c_noCompare);
+declare_clist(t2, carray2f, carray2f_destroy, c_no_compare);
declare_cmap(il, int, clist_t2, clist_t2_destroy);
declare_cmap_str(sm, cmap_il, cmap_il_destroy);
@@ -24,7 +24,7 @@ int main() {
// Put in some data.
carray2f_data(table, y)[x] = 3.1415927; // table[y][x]
- clist_t2_pushBack(&tableList, table);
+ clist_t2_push_back(&tableList, table);
cmap_il_put(&listMap, tableKey, tableList);
cmap_sm_put(&theMap, strKey, listMap);
}
diff --git a/examples/demos.c b/examples/demos.c
index 3a29f7d6..845f0cf0 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 cs = cstr_make("one-nine-three-seven-five");
printf("%s.\n", cs.str);
cstr_insert(&cs, 3, "-two");
@@ -41,10 +41,10 @@ void vectordemo1()
cvec_ix bignums = cvec_init; // = (cvec_ix) cvec_init; if initializing after declaration.
cvec_ix_reserve(&bignums, 100);
for (size_t i = 0; i<=100; ++i)
- cvec_ix_pushBack(&bignums, i * i * i);
+ cvec_ix_push_back(&bignums, i * i * i);
printf("erase - %d: %zu\n", 100, bignums.data[100]);
- cvec_ix_popBack(&bignums); // erase the last
+ cvec_ix_pop_back(&bignums); // erase the last
for (size_t i = 0; i < cvec_size(bignums); ++i) {
if (i >= 90) printf("%zu: %zu\n", i, bignums.data[i]);
@@ -54,15 +54,15 @@ void vectordemo1()
-declare_cvec(cs, cstr_t, cstr_destroy, cstr_compare); // supply inline destructor of values
+declare_cvec(cs, cstr, cstr_destroy, cstr_compare); // supply inline destructor of values
void vectordemo2()
{
printf("\nVECTORDEMO2\n");
cvec_cs names = cvec_init;
- cvec_cs_pushBack(&names, cstr_make("Mary"));
- cvec_cs_pushBack(&names, cstr_make("Joe"));
- cvec_cs_pushBack(&names, cstr_make("Chris"));
+ cvec_cs_push_back(&names, cstr_make("Mary"));
+ cvec_cs_push_back(&names, cstr_make("Joe"));
+ cvec_cs_push_back(&names, cstr_make("Chris"));
cstr_assign(&names.data[1], "Jane"); // replace Joe
printf("names[1]: %s\n", names.data[1].str);
@@ -79,21 +79,21 @@ void listdemo1()
printf("\nLISTDEMO1\n");
clist_ix nums = clist_init, nums2 = clist_init;
for (int i = 0; i < 10; ++i)
- clist_ix_pushBack(&nums, i);
+ clist_ix_push_back(&nums, i);
for (int i = 100; i < 110; ++i)
- clist_ix_pushBack(&nums2, i);
+ clist_ix_push_back(&nums2, i);
c_foreach (i, clist_ix, nums)
printf("value: %d\n", i.item->value);
/* merge/append nums2 to nums */
- clist_ix_spliceAfter(&nums, clist_ix_last(&nums), &nums2);
+ clist_ix_splice_after(&nums, clist_ix_last(&nums), &nums2);
c_foreach (i, clist_ix, nums)
printf("spliced: %d\n", i.item->value);
*clist_ix_find(&nums, 100) *= 10;
clist_ix_sort(&nums); // Sort the array
clist_ix_remove(&nums, 105);
- clist_ix_popFront(&nums);
- clist_ix_pushFront(&nums, -99);
+ clist_ix_pop_front(&nums);
+ clist_ix_push_front(&nums, -99);
c_foreach (i, clist_ix, nums)
printf("sorted: %d\n", i.item->value);
clist_ix_destroy(&nums);
@@ -150,7 +150,7 @@ void mapdemo2()
}
-declare_cmap_str(ss, cstr_t, cstr_destroy);
+declare_cmap_str(ss, cstr, cstr_destroy);
void mapdemo3()
{
diff --git a/examples/geek2.c b/examples/geek2.c
index 988f1f98..c3a9ddfc 100644
--- a/examples/geek2.c
+++ b/examples/geek2.c
@@ -3,7 +3,7 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-declare_cmap_str(ss, cstr_t, cstr_destroy);
+declare_cmap_str(ss, cstr, cstr_destroy);
declare_cset_str();
int main()
diff --git a/examples/geek3.c b/examples/geek3.c
index b8de97c8..4c53a026 100644
--- a/examples/geek3.c
+++ b/examples/geek3.c
@@ -4,7 +4,7 @@
#include <stc/cstr.h>
declare_cmap_str(si, int);
-declare_cmap_str(ss, cstr_t, cstr_destroy);
+declare_cmap_str(ss, cstr, cstr_destroy);
int main ()
{
diff --git a/examples/geek4.c b/examples/geek4.c
index 87f9b919..dcf7edbf 100644
--- a/examples/geek4.c
+++ b/examples/geek4.c
@@ -39,7 +39,7 @@ Efficient Approach: For all the words of the first sentence, we can check if it
declare_cvec_str();
declare_cmap_str(sb, bool);
-declare_cvec(sb, cmapentry_sb, cmapentry_sb_destroy, c_noCompare);
+declare_cvec(sb, cmapentry_sb, cmapentry_sb_destroy, c_no_compare);
// Function to return the count of common words
// in all the sentences
@@ -59,11 +59,11 @@ int commonWords(cvec_str S)
// Extract all words of first string and store it in ans
while (i < cstr_size(S.data[0])) {
// To store separate words
- cstr_t word = cstr_init;
+ cstr word = cstr_init;
cmapentry_sb tmp = {cstr_init, false};
while (i < cstr_size(S.data[0]) && S.data[0].str[i] != ' ') {
- cstr_pushBack(&word, S.data[0].str[i]);
+ cstr_push_back(&word, S.data[0].str[i]);
i++;
}
@@ -75,7 +75,7 @@ int commonWords(cvec_str S)
if (!cstr_empty(word)) {
tmp.key = cstr_move(&word);
tmp.value = true;
- cvec_sb_pushBack(&ans, tmp);
+ cvec_sb_push_back(&ans, tmp);
}
}
@@ -89,9 +89,9 @@ int commonWords(cvec_str S)
i = 0;
while (i < cstr_size(S.data[j])) {
- cstr_t word = cstr_init;
+ cstr word = cstr_init;
while (i < cstr_size(S.data[j]) && S.data[j].str[i] != ' ') {
- cstr_pushBack(&word, S.data[j].str[i]);
+ cstr_push_back(&word, S.data[j].str[i]);
i++;
}
i++;
@@ -137,10 +137,10 @@ int commonWords(cvec_str S)
int main()
{
cvec_str S = cvec_init;
- cvec_str_pushBack(&S, cstr_make("there is a cow"));
- cvec_str_pushBack(&S, cstr_make("cow is our mother"));
- cvec_str_pushBack(&S, cstr_make("cow gives us milk and milk is sweet"));
- cvec_str_pushBack(&S, cstr_make("there is a boy who loves cow"));
+ cvec_str_push_back(&S, cstr_make("there is a cow"));
+ cvec_str_push_back(&S, cstr_make("cow is our mother"));
+ cvec_str_push_back(&S, cstr_make("cow gives us milk and milk is sweet"));
+ cvec_str_push_back(&S, cstr_make("there is a boy who loves cow"));
printf("%d\n", commonWords(S));
cvec_str_destroy(&S);
diff --git a/examples/geek5.c b/examples/geek5.c
index b1e2f2b9..d9885293 100644
--- a/examples/geek5.c
+++ b/examples/geek5.c
@@ -39,11 +39,11 @@ int NumOccurrences(const char* arr[], int n, const char* str, int L, int R)
// then create the entry
if (it == NULL) {
cvec_i A = cvec_init;
- cvec_i_pushBack(&A, i + 1);
+ cvec_i_push_back(&A, i + 1);
cmap_sv_put(&M, temp, A);
}
else {
- cvec_i_pushBack(&it->value, i + 1);
+ cvec_i_push_back(&it->value, i + 1);
}
}
diff --git a/examples/geek7.c b/examples/geek7.c
index 88cfa33c..36805dce 100644
--- a/examples/geek7.c
+++ b/examples/geek7.c
@@ -57,7 +57,7 @@ void findElementsAfterDel(int arr[], int m, int del[],
// If the frequency becomes 0,
// erase it from the map
if (e->value == 0)
- cmap_ii_eraseEntry(&mp, e);
+ cmap_ii_erase_entry(&mp, e);
}
// Else push it in the min heap
diff --git a/examples/heap.c b/examples/heap.c
index f91642ac..857ff1fb 100644
--- a/examples/heap.c
+++ b/examples/heap.c
@@ -14,7 +14,7 @@ int main()
cvec_f vec = cvec_init;
clock_t start = clock();
for (int i=0; i<N; ++i)
- cvec_f_pushBack(&vec, crandom32_uniform_int(&pcg));
+ cvec_f_push_back(&vec, crandom32_uniform_int(&pcg));
cvecpq_f_build(&vec);
printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
diff --git a/examples/inits.c b/examples/inits.c
index 5f8563c7..c7758926 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -4,12 +4,12 @@
#include <stc/cvec.h>
#include <stc/clist.h>
-declare_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t
+declare_cmap(id, int, cstr, cstr_destroy); // Map of int -> cstr
declare_cmap_str(cnt, int);
typedef struct {int x, y;} ipair_t;
-declare_cvec(ip, ipair_t, c_defaultDestroy, c_memCompare);
-declare_clist(ip, ipair_t, c_defaultDestroy, c_memCompare);
+declare_cvec(ip, ipair_t, c_default_destroy, c_mem_compare);
+declare_clist(ip, ipair_t, c_default_destroy, c_mem_compare);
int main(void) {
diff --git a/examples/list.c b/examples/list.c
index 2c8d17cd..352965b2 100644
--- a/examples/list.c
+++ b/examples/list.c
@@ -9,7 +9,7 @@ int main() {
crandom32_t pcg = crandom32_uniform_engine(time(NULL));
int n;
for (int i=0; i<10000000; ++i) // ten million
- clist_ix_pushBack(&list, crandom32_uniform_int(&pcg));
+ clist_ix_push_back(&list, crandom32_uniform_int(&pcg));
n = 100;
c_foreach (i, clist_ix, list)
if (n--) printf("%8d: %10zu\n", 100 - n, i.item->value); else break;
diff --git a/examples/prime.c b/examples/prime.c
index 611690ac..463203d2 100644
--- a/examples/prime.c
+++ b/examples/prime.c
@@ -10,7 +10,7 @@
static inline void sieveOfEratosthenes(size_t n)
{
- cbitset_t prime = cbitset_make(n + 1, true);
+ cbitset prime = cbitset_make(n + 1, true);
printf("computing prime numbers up to %zu\n", n);
cbitset_reset(&prime, 0);
cbitset_reset(&prime, 1);
diff --git a/stc/carray.h b/stc/carray.h
index caab846f..0b0a7751 100644
--- a/stc/carray.h
+++ b/stc/carray.h
@@ -77,7 +77,7 @@ static inline size_t _carray3_size(const size_t* zdim) {
#define declare_carray(...) c_MACRO_OVERLOAD(declare_carray, __VA_ARGS__)
#define declare_carray_2(tag, Value) \
- declare_carray_3(tag, Value, c_defaultDestroy)
+ declare_carray_3(tag, Value, c_default_destroy)
#define declare_carray_3(tag, Value, valueDestroy) \
@@ -98,7 +98,7 @@ static inline size_t _carray3_size(const size_t* zdim) {
\
static inline carray1##tag \
carray1##tag##_make(size_t xdim, Value val) { \
- Value* m = c_new_N(Value, xdim); \
+ Value* m = c_new_n(Value, xdim); \
for (size_t i=0; i<xdim; ++i) m[i] = val; \
carray1##tag a = {m, xdim | _carray_OWN}; \
return a; \
@@ -106,7 +106,7 @@ static inline size_t _carray3_size(const size_t* zdim) {
static inline carray2##tag \
carray2##tag##_make(size_t ydim, size_t xdim, Value val) { \
const size_t n = ydim * xdim; \
- Value* m = c_new_N(Value, n); \
+ Value* m = c_new_n(Value, n); \
for (size_t i=0; i<n; ++i) m[i] = val; \
carray2##tag a = {m, xdim | _carray_OWN, ydim * xdim}; \
return a; \
@@ -114,7 +114,7 @@ static inline size_t _carray3_size(const size_t* zdim) {
static inline carray3##tag \
carray3##tag##_make(size_t zdim, size_t ydim, size_t xdim, Value val) { \
const size_t n = zdim * ydim * xdim; \
- Value* m = c_new_N(Value, n); \
+ Value* m = c_new_n(Value, n); \
for (size_t i=0; i<n; ++i) m[i] = val; \
carray3##tag a = {m, xdim | _carray_OWN, ydim * xdim, zdim}; \
return a; \
diff --git a/stc/cbitset.h b/stc/cbitset.h
index 94488f24..dd5fe2ae 100644
--- a/stc/cbitset.h
+++ b/stc/cbitset.h
@@ -27,7 +27,7 @@ Similar to boost::dynamic_bitset / std::bitset
#include "cbitset.h"
int main() {
- cbitset_t set = cbitset_make(23, true);
+ cbitset set = cbitset_make(23, true);
cbitset_reset(&set, 9);
cbitset_resize(&set, 43, false);
printf("%4zu: ", set.size);for (int i=0; i<set.size; ++i) printf("%d", cbitset_value(&set, i));puts("");
@@ -55,97 +55,97 @@ int main() {
#define cbitset_popcnt64(i) _mm_popcnt_u64(i)
#endif
-typedef struct { uint64_t* _arr; size_t size; } cbitset_t;
+typedef struct { uint64_t* _arr; size_t size; } cbitset;
#define cbitset_init {NULL, 0}
-STC_API void cbitset_resize(cbitset_t* self, size_t size, bool value);
-STC_API size_t cbitset_count(cbitset_t set);
+STC_API void cbitset_resize(cbitset* self, size_t size, bool value);
+STC_API size_t cbitset_count(cbitset set);
-STC_INLINE void cbitset_setAll(cbitset_t *self, bool value);
+STC_INLINE void cbitset_set_all(cbitset *self, bool value);
-STC_INLINE cbitset_t cbitset_make(size_t size, bool value) {
- cbitset_t set = {(uint64_t *) malloc(((size + 63) >> 6) * 8), size};
- cbitset_setAll(&set, value);
+STC_INLINE cbitset cbitset_make(size_t size, bool value) {
+ cbitset set = {(uint64_t *) malloc(((size + 63) >> 6) * 8), size};
+ cbitset_set_all(&set, value);
return set;
}
-STC_INLINE cbitset_t cbitset_from(cbitset_t other) {
+STC_INLINE cbitset cbitset_from(cbitset other) {
size_t n = (other.size + 63) >> 6;
- cbitset_t set = {(uint64_t *) memcpy(malloc(n * 8), other._arr, n * 8), other.size};
+ cbitset set = {(uint64_t *) memcpy(malloc(n * 8), other._arr, n * 8), other.size};
return set;
}
-STC_INLINE void cbitset_destroy(cbitset_t* self) {
+STC_INLINE void cbitset_destroy(cbitset* self) {
free(self->_arr);
}
-STC_INLINE size_t cbitset_size(cbitset_t set) {return set.size;}
+STC_INLINE size_t cbitset_size(cbitset set) {return set.size;}
-STC_INLINE void cbitset_set(cbitset_t *self, size_t i) {
+STC_INLINE void cbitset_set(cbitset *self, size_t i) {
self->_arr[i >> 6] |= 1ull << (i & 63);
}
-STC_INLINE void cbitset_reset(cbitset_t *self, size_t i) {
+STC_INLINE void cbitset_reset(cbitset *self, size_t i) {
self->_arr[i >> 6] &= ~(1ull << (i & 63));
}
-STC_INLINE void cbitset_setTo(cbitset_t *self, size_t i, bool value) {
+STC_INLINE void cbitset_set_to(cbitset *self, size_t i, bool value) {
value ? cbitset_set(self, i) : cbitset_reset(self, i);
}
-STC_INLINE void cbitset_flip(cbitset_t *self, size_t i) {
+STC_INLINE void cbitset_flip(cbitset *self, size_t i) {
self->_arr[i >> 6] ^= 1ull << (i & 63);
}
-STC_INLINE bool cbitset_test(cbitset_t set, size_t i) {
+STC_INLINE bool cbitset_test(cbitset set, size_t i) {
return (set._arr[i >> 6] & (1ull << (i & 63))) != 0;
}
-STC_INLINE void cbitset_setAll(cbitset_t *self, bool value) {
+STC_INLINE void cbitset_set_all(cbitset *self, bool value) {
memset(self->_arr, value ? 0xff : 0x0, ((self->size + 63) >> 6) * 8);
}
-STC_INLINE void cbitset_setAll64(cbitset_t *self, uint64_t pattern) {
+STC_INLINE void cbitset_set_all_64(cbitset *self, uint64_t pattern) {
size_t n = (self->size + 63) >> 6;
for (size_t i=0; i<n; ++i) self->_arr[i] = pattern;
}
-STC_INLINE void cbitset_flipAll(cbitset_t *self) {
+STC_INLINE void cbitset_flip_all(cbitset *self) {
size_t n = (self->size + 63) >> 6;
for (size_t i=0; i<n; ++i) self->_arr[i] ^= ~0ull;
}
/* Intersection */
-STC_INLINE void cbitset_setAnd(cbitset_t *self, cbitset_t other) {
+STC_INLINE void cbitset_set_and(cbitset *self, cbitset other) {
assert(self->size == other.size);
size_t n = (self->size + 63) >> 6;
for (size_t i=0; i<n; ++i) self->_arr[i] &= other._arr[i];
}
/* Union */
-STC_INLINE void cbitset_setOr(cbitset_t *self, cbitset_t other) {
+STC_INLINE void cbitset_set_or(cbitset *self, cbitset other) {
assert(self->size == other.size);
size_t n = (self->size + 63) >> 6;
for (size_t i=0; i<n; ++i) self->_arr[i] |= other._arr[i];
}
/* Exclusive disjunction */
-STC_INLINE void cbitset_setXor(cbitset_t *self, cbitset_t other) {
+STC_INLINE void cbitset_set_xor(cbitset *self, cbitset other) {
assert(self->size == other.size);
size_t n = (self->size + 63) >> 6;
for (size_t i=0; i<n; ++i) self->_arr[i] ^= other._arr[i];
}
-STC_INLINE cbitset_t cbitset_and(cbitset_t s1, cbitset_t s2) {
- cbitset_t set = cbitset_from(s1);
- cbitset_setAnd(&set, s2); return set;
+STC_INLINE cbitset cbitset_and(cbitset s1, cbitset s2) {
+ cbitset set = cbitset_from(s1);
+ cbitset_set_and(&set, s2); return set;
}
-STC_INLINE cbitset_t cbitset_or(cbitset_t s1, cbitset_t s2) {
- cbitset_t set = cbitset_from(s1);
- cbitset_setOr(&set, s2); return set;
+STC_INLINE cbitset cbitset_or(cbitset s1, cbitset s2) {
+ cbitset set = cbitset_from(s1);
+ cbitset_set_or(&set, s2); return set;
}
-STC_INLINE cbitset_t cbitset_xor(cbitset_t s1, cbitset_t s2) {
- cbitset_t set = cbitset_from(s1);
- cbitset_setXor(&set, s2); return set;
+STC_INLINE cbitset cbitset_xor(cbitset s1, cbitset s2) {
+ cbitset set = cbitset_from(s1);
+ cbitset_set_xor(&set, s2); return set;
}
-STC_INLINE cbitset_t cbitset_not(cbitset_t s1) {
- cbitset_t set = cbitset_from(s1);
- cbitset_flipAll(&set); return set;
+STC_INLINE cbitset cbitset_not(cbitset s1) {
+ cbitset set = cbitset_from(s1);
+ cbitset_flip_all(&set); return set;
}
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
-STC_API void cbitset_resize(cbitset_t* self, size_t size, bool value) {
+STC_API void cbitset_resize(cbitset* self, size_t size, bool value) {
size_t new_n = (size + 63) >> 6, osize = self->size, old_n = (osize + 63) >> 6;
self->_arr = (uint64_t *) realloc(self->_arr, new_n * 8);
self->size = size;
@@ -158,7 +158,7 @@ STC_API void cbitset_resize(cbitset_t* self, size_t size, bool value) {
}
}
-STC_API size_t cbitset_count(cbitset_t set) {
+STC_API size_t cbitset_count(cbitset set) {
size_t count = 0, n = (set.size + 63) >> 6;
if (set.size > 0) {
--n; for (size_t i=0; i<n; ++i) count += cbitset_popcnt64(set._arr[i]);
diff --git a/stc/cdefs.h b/stc/cdefs.h
index 8e536438..8f5b896f 100644
--- a/stc/cdefs.h
+++ b/stc/cdefs.h
@@ -57,28 +57,28 @@
/*#define FOO(...) c_MACRO_OVERLOAD(FOO, __VA_ARGS__) #define FOO_0() "0" #define FOO_1(x) "1" #define FOO_2(x,y) "2"*/
#define c_new(T) ((T *) malloc(sizeof(T)))
-#define c_new_N(T, n) ((T *) malloc(sizeof(T) * (n)))
+#define c_new_n(T, n) ((T *) malloc(sizeof(T) * (n)))
#define c_max_alloca (1000)
#define c_swap(T, x, y) { T __t = x; x = y; y = __t; }
#define c_defaultInitRaw(x) (x)
#define c_defaultGetRaw(ptr) (*(ptr))
-#define c_noCompare(x, y) (0)
-#define c_memCompare(x, y) memcmp(x, y, sizeof(*(y)))
-#define c_memEquals(x, y) (memCompare(x, y) == 0)
-#define c_defaultEquals(x, y) (*(x) == *(y))
-#define c_defaultLess(x, y) (*(x) < *(y))
+#define c_no_compare(x, y) (0)
+#define c_mem_compare(x, y) memcmp(x, y, sizeof(*(y)))
+#define c_mem_equals(x, y) (memCompare(x, 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_defaultCompare(x, y) c_compare(c_defaultLess, x, y)
-#define c_defaultDestroy(p) ((void)0)
+#define c_default_compare(x, y) c_compare(c_default_less, x, y)
+#define c_default_destroy(p) ((void)0)
#define c_foreach(it, prefix, container) \
for (prefix##_iter_t it = prefix##_begin(&container); it.item; it = prefix##_next(it))
#define c_items(...) {__VA_ARGS__}
#define c_push(container, prefix, items) do { \
const prefix##_input_t __arr[] = items; \
- prefix##_pushN(container, __arr, sizeof(__arr)/sizeof(prefix##_input_t)); \
+ prefix##_push_n(container, __arr, sizeof(__arr)/sizeof(prefix##_input_t)); \
} while (0)
/* One-byte-at-a-time hash based on Murmur's mix */
@@ -95,13 +95,13 @@ static inline uint32_t c_defaultHash(const void *data, size_t len) {
/* https://programmingpraxis.com/2018/06/19/fibonacci-hash */
/* https://probablydance.com/2018/06/16/fibonacci-hashing-the-optimization-that-the-world-forgot-or-a-better-alternative-to-integer-modulo/ */
-static inline uint32_t c_fibonacciHash32(const void* data, size_t len) {
+static inline uint32_t c_fibonacci_hash32(const void* data, size_t len) {
const volatile uint32_t *key = (const uint32_t *) data;
uint32_t x = *key++ * 2654435769u;
while (len -= 4) x ^= *key++ * 2654435769u;
return x;
}
-static inline uint32_t c_fibonacciHash64(const void* data, size_t len) {
+static inline uint32_t c_fibonacci_hash64(const void* data, size_t len) {
const volatile uint64_t *key = (const uint64_t *) data;
uint64_t x = *key++ * 11400714819323198485ull;
while (len -= 8) x ^= *key++ * 11400714819323198485ull;
diff --git a/stc/clist.h b/stc/clist.h
index 2a86d4b2..26c0a260 100644
--- a/stc/clist.h
+++ b/stc/clist.h
@@ -42,7 +42,7 @@
crandom32_t pcg = crandom32_uniform_engine(12345);
int n;
for (int i=0; i<1000000; ++i) // one million
- clist_ix_pushBack(&list, crandom32_uniform_int(&pcg));
+ clist_ix_push_back(&list, crandom32_uniform_int(&pcg));
n = 0;
c_foreach (i, clist_ix, list)
if (++n % 10000 == 0) printf("%8d: %10zd\n", n, i.item->value);
@@ -59,15 +59,15 @@
#define declare_clist(...) c_MACRO_OVERLOAD(declare_clist, __VA_ARGS__)
#define declare_clist_2(tag, Value) \
- declare_clist_3(tag, Value, c_defaultDestroy)
+ declare_clist_3(tag, Value, c_default_destroy)
#define declare_clist_3(tag, Value, valueDestroy) \
- declare_clist_4(tag, Value, valueDestroy, c_defaultCompare)
+ declare_clist_4(tag, Value, valueDestroy, c_default_compare)
#define declare_clist_4(tag, Value, valueDestroy, valueCompare) \
declare_clist_6(tag, Value, valueDestroy, Value, valueCompare, c_defaultGetRaw)
#define declare_clist_str() \
- declare_clist_6(str, cstr_t, cstr_destroy, const char*, cstr_compareRaw, cstr_getRaw)
+ declare_clist_6(str, cstr, cstr_destroy, const char*, cstr_compareRaw, cstr_getRaw)
-#define declare_clistTypes(tag, Value) \
+#define declare_clist_types(tag, Value) \
typedef struct clistnode_##tag { \
struct clistnode_##tag *next; \
Value value; \
@@ -89,7 +89,7 @@
#define declare_clist_6(tag, Value, valueDestroy, RawValue, valueCompareRaw, valueGetRaw) \
\
- declare_clistTypes(tag, Value); \
+ declare_clist_types(tag, Value); \
\
STC_INLINE clist_##tag \
clist_##tag##_init(void) {clist_##tag x = clist_init; return x;} \
@@ -98,23 +98,23 @@
STC_INLINE void \
clist_##tag##_clear(clist_##tag* self) {clist_##tag##_destroy(self);} \
STC_API void \
- clist_##tag##_pushBack(clist_##tag* self, Value value); \
+ clist_##tag##_push_back(clist_##tag* self, Value value); \
STC_API void \
- clist_##tag##_pushFront(clist_##tag* self, Value value); \
+ clist_##tag##_push_front(clist_##tag* self, Value value); \
STC_API void \
- clist_##tag##_pushN(clist_##tag *self, const Value in[], size_t size); \
+ clist_##tag##_push_n(clist_##tag *self, const Value in[], size_t size); \
STC_API void \
- clist_##tag##_popFront(clist_##tag* self); \
+ clist_##tag##_pop_front(clist_##tag* self); \
STC_API void \
- clist_##tag##_insertAfter(clist_##tag* self, clist_##tag##_iter_t pos, Value value); \
+ clist_##tag##_insert_after(clist_##tag* self, clist_##tag##_iter_t pos, Value value); \
STC_API void \
- clist_##tag##_eraseAfter(clist_##tag* self, clist_##tag##_iter_t pos); \
+ clist_##tag##_erase_after(clist_##tag* self, clist_##tag##_iter_t pos); \
STC_API void \
- clist_##tag##_spliceFront(clist_##tag* self, clist_##tag* other); \
+ clist_##tag##_splice_front(clist_##tag* self, clist_##tag* other); \
STC_API void \
- clist_##tag##_spliceAfter(clist_##tag* self, clist_##tag##_iter_t pos, clist_##tag* other); \
+ clist_##tag##_splice_after(clist_##tag* self, clist_##tag##_iter_t pos, clist_##tag* other); \
STC_API clist_##tag##_iter_t \
- clist_##tag##_findBefore(clist_##tag* self, RawValue val); \
+ clist_##tag##_find_before(clist_##tag* self, RawValue val); \
STC_API Value* \
clist_##tag##_find(clist_##tag* self, RawValue val); \
STC_API clist_##tag##_iter_t \
@@ -154,36 +154,36 @@
STC_API void \
clist_##tag##_destroy(clist_##tag* self) { \
while (self->last) \
- clist_##tag##_popFront(self); \
+ clist_##tag##_pop_front(self); \
} \
\
STC_API void \
- clist_##tag##_pushBack(clist_##tag* self, Value value) { \
- _clist_insertAfter(self, tag, self->last, value); \
+ clist_##tag##_push_back(clist_##tag* self, Value value) { \
+ _clist_insert_after(self, tag, self->last, value); \
self->last = entry; \
} \
STC_API void \
- clist_##tag##_pushFront(clist_##tag* self, Value value) { \
- _clist_insertAfter(self, tag, self->last, value); \
+ clist_##tag##_push_front(clist_##tag* self, Value value) { \
+ _clist_insert_after(self, tag, self->last, value); \
if (!self->last) self->last = entry; \
} \
STC_API void \
- clist_##tag##_pushN(clist_##tag *self, const Value in[], size_t size) { \
- for (size_t i=0; i<size; ++i) clist_##tag##_pushBack(self, in[i]); \
+ clist_##tag##_push_n(clist_##tag *self, const Value in[], size_t size) { \
+ for (size_t i=0; i<size; ++i) clist_##tag##_push_back(self, in[i]); \
} \
STC_API void \
- clist_##tag##_popFront(clist_##tag* self) { \
- _clist_eraseAfter(self, tag, self->last, valueDestroy); \
+ clist_##tag##_pop_front(clist_##tag* self) { \
+ _clist_erase_after(self, tag, self->last, valueDestroy); \
} \
\
STC_API void \
- clist_##tag##_insertAfter(clist_##tag* self, clist_##tag##_iter_t pos, Value value) { \
- _clist_insertAfter(self, tag, pos.item, value); \
+ clist_##tag##_insert_after(clist_##tag* self, clist_##tag##_iter_t pos, Value value) { \
+ _clist_insert_after(self, tag, pos.item, value); \
if (!self->last || pos.item == self->last) self->last = entry; \
} \
STC_API void \
- clist_##tag##_eraseAfter(clist_##tag* self, clist_##tag##_iter_t pos) { \
- _clist_eraseAfter(self, tag, pos.item, valueDestroy); \
+ clist_##tag##_erase_after(clist_##tag* self, clist_##tag##_iter_t pos) { \
+ _clist_erase_after(self, tag, pos.item, valueDestroy); \
} \
\
static inline void \
@@ -199,16 +199,16 @@
other->last = NULL; \
} \
STC_API void \
- clist_##tag##_spliceFront(clist_##tag* self, clist_##tag* other) { \
+ clist_##tag##_splice_front(clist_##tag* self, clist_##tag* other) { \
_clist_##tag##_splice(self, clist_##tag##_last(self), other, false); \
} \
STC_API void \
- clist_##tag##_spliceAfter(clist_##tag* self, clist_##tag##_iter_t pos, clist_##tag* other) { \
+ clist_##tag##_splice_after(clist_##tag* self, clist_##tag##_iter_t pos, clist_##tag* other) { \
_clist_##tag##_splice(self, pos, other, true); \
} \
\
STC_API clist_##tag##_iter_t \
- clist_##tag##_findBefore(clist_##tag* self, RawValue val) { \
+ clist_##tag##_find_before(clist_##tag* self, RawValue val) { \
clist_##tag##_iter_t prev = {self->last, &self->last}; \
c_foreach (i, clist_##tag, *self) { \
RawValue r = valueGetRaw(&i.item->value); \
@@ -222,30 +222,30 @@
\
STC_API Value* \
clist_##tag##_find(clist_##tag* self, RawValue val) { \
- clist_##tag##_iter_t it = clist_##tag##_findBefore(self, val); \
+ clist_##tag##_iter_t it = clist_##tag##_find_before(self, val); \
return it.item ? &it.item->next->value : NULL; \
} \
\
STC_API clist_##tag##_iter_t \
clist_##tag##_remove(clist_##tag* self, RawValue val) { \
- clist_##tag##_iter_t it = clist_##tag##_findBefore(self, val); \
- if (it.item) clist_##tag##_eraseAfter(self, it); \
+ clist_##tag##_iter_t it = clist_##tag##_find_before(self, val); \
+ if (it.item) clist_##tag##_erase_after(self, it); \
return it; \
} \
\
static inline int \
- clist_##tag##_sortCompare(const void* x, const void* y) { \
+ clist_##tag##_sort_compare(const void* x, const void* y) { \
RawValue a = valueGetRaw(&((clistnode_##tag *) x)->value); \
RawValue b = valueGetRaw(&((clistnode_##tag *) y)->value); \
return valueCompareRaw(&a, &b); \
} \
STC_API void \
clist_##tag##_sort(clist_##tag* self) { \
- clistnode__base* last = _clist_mergesort((clistnode__base *) self->last->next, clist_##tag##_sortCompare); \
+ clistnode__base* last = _clist_mergesort((clistnode__base *) self->last->next, clist_##tag##_sort_compare); \
self->last = (clistnode_##tag *) last; \
}
-#define _clist_insertAfter(self, tag, node, val) \
+#define _clist_insert_after(self, tag, node, val) \
clistnode_##tag *entry = c_new (clistnode_##tag), \
*next = self->last ? node->next : entry; \
entry->value = val; \
@@ -253,7 +253,7 @@
if (node) node->next = entry
/* +: set self->last based on node */
-#define _clist_eraseAfter(self, tag, node, valueDestroy) \
+#define _clist_erase_after(self, tag, node, valueDestroy) \
clistnode_##tag* del = node->next, *next = del->next; \
node->next = next; \
if (del == next) self->last = NULL; \
@@ -261,7 +261,7 @@
valueDestroy(&del->value); \
free(del)
-declare_clistTypes(_base, int);
+declare_clist_types(_base, int);
/* Singly linked list Mergesort implementation by Simon Tatham. O(n*log n).
* https://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
diff --git a/stc/cmap.h b/stc/cmap.h
index 74d255f0..017864cd 100644
--- a/stc/cmap.h
+++ b/stc/cmap.h
@@ -60,7 +60,7 @@ int main(void) {
/* https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction */
#define chash_reduce(x, N) ((uint32_t) (((uint64_t) (x) * (N)) >> 32))
-#define chash_entryIndex(h, entryPtr) ((entryPtr) - (h).table)
+#define chash_entry_index(h, entryPtr) ((entryPtr) - (h).table)
enum {chash_HASH = 0x7f, chash_USED = 0x80};
@@ -68,14 +68,14 @@ enum {chash_HASH = 0x7f, chash_USED = 0x80};
c_MACRO_OVERLOAD(declare_cmap, __VA_ARGS__)
#define declare_cmap_3(tag, Key, Value) \
- declare_cmap_4(tag, Key, Value, c_defaultDestroy)
+ declare_cmap_4(tag, Key, Value, c_default_destroy)
#define declare_cmap_4(tag, Key, Value, valueDestroy) \
- declare_cmap_6(tag, Key, Value, valueDestroy, c_defaultEquals, c_defaultHash)
+ declare_cmap_6(tag, Key, Value, valueDestroy, c_default_equals, c_defaultHash)
#define declare_cmap_6(tag, Key, Value, valueDestroy, keyEquals, keyHash) \
declare_cmap_10(tag, Key, Value, valueDestroy, keyEquals, keyHash, \
- c_defaultDestroy, Key, c_defaultGetRaw, c_defaultInitRaw)
+ c_default_destroy, Key, c_defaultGetRaw, c_defaultInitRaw)
#define declare_cmap_10(tag, Key, Value, valueDestroy, keyEqualsRaw, keyHashRaw, \
keyDestroy, RawKey, keyGetRaw, keyInitRaw) \
@@ -87,10 +87,10 @@ enum {chash_HASH = 0x7f, chash_USED = 0x80};
c_MACRO_OVERLOAD(declare_cset, __VA_ARGS__)
#define declare_cset_2(tag, Key) \
- declare_cset_4(tag, Key, c_defaultEquals, c_defaultHash)
+ declare_cset_4(tag, Key, c_default_equals, c_defaultHash)
#define declare_cset_4(tag, Key, keyEquals, keyHash) \
- declare_cset_5(tag, Key, keyEquals, keyHash, c_defaultDestroy)
+ declare_cset_5(tag, Key, keyEquals, keyHash, c_default_destroy)
#define declare_cset_5(tag, Key, keyEquals, keyHash, keyDestroy) \
declare_cset_8(tag, Key, keyEquals, keyHash, keyDestroy, \
@@ -109,13 +109,13 @@ enum {chash_HASH = 0x7f, chash_USED = 0x80};
c_MACRO_OVERLOAD(declare_cmap_str, __VA_ARGS__)
#define declare_cmap_str_2(tag, Value) \
- declare_CHASH_STR(tag, cmap, Value, c_defaultDestroy)
+ declare_CHASH_STR(tag, cmap, Value, c_default_destroy)
#define declare_cmap_str_3(tag, Value, ValueDestroy) \
declare_CHASH_STR(tag, cmap, Value, ValueDestroy)
#define declare_CHASH_STR(tag, ctype, Value, valueDestroy) \
- declare_CHASH(tag, ctype, cstr_t, Value, valueDestroy, cstr_equalsRaw, cstr_hashRaw, \
+ declare_CHASH(tag, ctype, cstr, Value, valueDestroy, cstr_equalsRaw, cstr_hashRaw, \
cstr_destroy, const char*, cstr_getRaw, cstr_make)
#define OPT_1_cset(x)
@@ -146,9 +146,9 @@ typedef RawKey ctype##_##tag##_rawkey_t; \
typedef struct { \
ctype##entry_##tag* table; \
uint8_t* _hashx; \
- uint32_t size, bucketCount; \
- float maxLoadFactor; \
- float shrinkLimitFactor; \
+ uint32_t size, bucket_count; \
+ float max_load_factor; \
+ float shrink_limit_factor; \
} ctype##_##tag; \
\
typedef struct { \
@@ -163,14 +163,14 @@ ctype##_##tag##_size(ctype##_##tag m) {return m.size;} \
STC_API ctype##_##tag \
ctype##_##tag##_make(size_t initialSize); \
STC_API void \
-ctype##_##tag##_pushN(ctype##_##tag* self, const ctype##_##tag##_input_t in[], size_t size); \
+ctype##_##tag##_push_n(ctype##_##tag* self, const ctype##_##tag##_input_t in[], size_t size); \
STC_API void \
ctype##_##tag##_destroy(ctype##_##tag* self); \
STC_API void \
ctype##_##tag##_clear(ctype##_##tag* self); \
STC_INLINE void \
-ctype##_##tag##_setLoadFactors(ctype##_##tag* self, float max, float shrink) { \
- self->maxLoadFactor = max; self->shrinkLimitFactor = shrink; \
+ctype##_##tag##_set_load_factors(ctype##_##tag* self, float max, float shrink) { \
+ self->max_load_factor = max; self->shrink_limit_factor = shrink; \
} \
STC_API ctype##entry_##tag* \
ctype##_##tag##_find(const ctype##_##tag* self, ctype##_##tag##_rawkey_t rawKey); \
@@ -186,7 +186,7 @@ ctype##_##tag##_swap(ctype##_##tag* a, ctype##_##tag* b) { c_swap(ctype##_##tag,
STC_API size_t \
ctype##_##tag##_reserve(ctype##_##tag* self, size_t size); \
STC_API bool \
-ctype##_##tag##_eraseEntry(ctype##_##tag* self, ctype##entry_##tag* entry); \
+ctype##_##tag##_erase_entry(ctype##_##tag* self, ctype##entry_##tag* entry); \
STC_API bool \
ctype##_##tag##_erase(ctype##_##tag* self, ctype##_##tag##_rawkey_t rawKey); \
STC_API ctype##_##tag##_iter_t \
@@ -211,13 +211,13 @@ ctype##_##tag##_make(size_t initialSize) { \
return h; \
} \
STC_API void \
-ctype##_##tag##_pushN(ctype##_##tag* self, const ctype##_##tag##_input_t in[], size_t size) { \
+ctype##_##tag##_push_n(ctype##_##tag* self, const ctype##_##tag##_input_t in[], size_t size) { \
for (size_t i=0; i<size; ++i) ctype##_##tag##_put(self, OPT_2_##ctype(in[i].key, in[i].value)); \
} \
\
STC_INLINE void ctype##_##tag##_wipe_(ctype##_##tag* self) { \
if (self->size == 0) return; \
- ctype##entry_##tag* e = self->table, *end = e + self->bucketCount; \
+ ctype##entry_##tag* e = self->table, *end = e + self->bucket_count; \
uint8_t *hx = self->_hashx; \
for (; e != end; ++e) if (*hx++) ctype##entry_##tag##_destroy(e); \
} \
@@ -231,14 +231,14 @@ STC_API void ctype##_##tag##_destroy(ctype##_##tag* self) { \
STC_API void ctype##_##tag##_clear(ctype##_##tag* self) { \
ctype##_##tag##_wipe_(self); \
self->size = 0; \
- memset(self->_hashx, 0, self->bucketCount); \
+ memset(self->_hashx, 0, self->bucket_count); \
} \
\
STC_API size_t \
ctype##_##tag##_bucket(const ctype##_##tag* self, const ctype##_##tag##_rawkey_t* rawKeyPtr, uint32_t* hxPtr) { \
uint32_t hash = keyHashRaw(rawKeyPtr, sizeof(ctype##_##tag##_rawkey_t)); \
uint32_t sx, hx = (hash & chash_HASH) | chash_USED; \
- size_t cap = self->bucketCount; \
+ size_t cap = self->bucket_count; \
size_t idx = chash_reduce(hash, cap); \
uint8_t* hashx = self->_hashx; \
while ((sx = hashx[idx])) { \
@@ -261,7 +261,7 @@ ctype##_##tag##_find(const ctype##_##tag* self, ctype##_##tag##_rawkey_t rawKey)
} \
\
static inline void ctype##_##tag##_reserveExpand_(ctype##_##tag* self) { \
- if (self->size + 1 >= self->bucketCount * self->maxLoadFactor) \
+ if (self->size + 1 >= self->bucket_count * self->max_load_factor) \
ctype##_##tag##_reserve(self, 7 + self->size * 3 / 2); \
} \
\
@@ -300,14 +300,14 @@ ctype##_##tag##_insert(ctype##_##tag* self, ctype##_##tag##_rawkey_t rawKey, Val
\
STC_API size_t \
ctype##_##tag##_reserve(ctype##_##tag* self, size_t newcap) { \
- size_t oldcap = self->bucketCount; \
+ size_t oldcap = self->bucket_count; \
if (self->size > newcap) return oldcap; \
- newcap /= self->maxLoadFactor; newcap |= 1; \
+ newcap /= self->max_load_factor; newcap |= 1; \
ctype##_##tag tmp = { \
- c_new_N(ctype##entry_##tag, newcap), \
+ c_new_n(ctype##entry_##tag, newcap), \
(uint8_t *) calloc(newcap, sizeof(uint8_t)), \
self->size, (uint32_t) newcap, \
- self->maxLoadFactor, self->shrinkLimitFactor \
+ self->max_load_factor, self->shrink_limit_factor \
}; \
ctype##_##tag##_swap(self, &tmp); \
\
@@ -327,8 +327,8 @@ ctype##_##tag##_reserve(ctype##_##tag* self, size_t newcap) { \
} \
\
STC_API bool \
-ctype##_##tag##_eraseEntry(ctype##_##tag* self, ctype##entry_##tag* entry) { \
- size_t i = chash_entryIndex(*self, entry), j = i, k, cap = self->bucketCount; \
+ctype##_##tag##_erase_entry(ctype##_##tag* self, ctype##entry_##tag* entry) { \
+ size_t i = chash_entry_index(*self, entry), j = i, k, cap = self->bucket_count; \
ctype##entry_##tag* slot = self->table; \
uint8_t* hashx = self->_hashx; \
ctype##_##tag##_rawkey_t r; \
@@ -353,18 +353,18 @@ STC_API bool \
ctype##_##tag##_erase(ctype##_##tag* self, ctype##_##tag##_rawkey_t rawKey) { \
if (self->size == 0) \
return false; \
- size_t cap = self->bucketCount; \
- if (self->size < cap * self->shrinkLimitFactor && cap * sizeof(ctype##entry_##tag) > 1024) \
+ size_t cap = self->bucket_count; \
+ if (self->size < cap * self->shrink_limit_factor && cap * sizeof(ctype##entry_##tag) > 1024) \
ctype##_##tag##_reserve(self, self->size * 6 / 5); \
uint32_t hx; \
size_t i = ctype##_##tag##_bucket(self, &rawKey, &hx); \
- return ctype##_##tag##_eraseEntry(self, self->table + i); \
+ return ctype##_##tag##_erase_entry(self, self->table + i); \
} \
\
STC_API ctype##_##tag##_iter_t \
ctype##_##tag##_begin(ctype##_##tag* map) { \
uint8_t* hx = map->_hashx; \
- ctype##entry_##tag* e = map->table, *end = e + map->bucketCount; \
+ ctype##entry_##tag* e = map->table, *end = e + map->bucket_count; \
while (e != end && !*hx) ++e, ++hx; \
ctype##_##tag##_iter_t it = {e == end ? NULL : e, end, hx}; return it; \
} \
diff --git a/stc/cstr.h b/stc/cstr.h
index 2c2b85d5..3d2584e2 100644
--- a/stc/cstr.h
+++ b/stc/cstr.h
@@ -31,154 +31,154 @@
#include "cdefs.h"
-typedef struct cstr_t {
+typedef struct cstr {
char* str;
-} cstr_t;
+} cstr;
#define _cstr_rep(self) (((size_t *) (self)->str) - 2)
#define _cstr_size(s) ((size_t *) (s).str)[-2]
#define _cstr_mem(cap) (sizeof(size_t) * (3 + (cap)/sizeof(size_t)))
static size_t _cstr_nullrep[] = {0, 0, 0};
-static cstr_t cstr_init = {(char* ) &_cstr_nullrep[2]};
+static cstr cstr_init = {(char* ) &_cstr_nullrep[2]};
#define cstr_size(s) ((const size_t *) (s).str)[-2]
#define cstr_capacity(s) ((const size_t *) (s).str)[-1]
#define cstr_npos ((size_t) (-1))
-STC_API cstr_t
-cstr_makeN(const char* str, size_t len);
-STC_API cstr_t
+STC_API cstr
+cstr_make_n(const char* str, size_t len);
+STC_API cstr
cstr_from(const char* fmt, ...);
STC_API void
-cstr_reserve(cstr_t* self, size_t cap);
+cstr_reserve(cstr* self, size_t cap);
STC_API void
-cstr_resize(cstr_t* self, size_t len, char fill);
-STC_API cstr_t
-cstr_makeReserved(size_t cap);
-STC_API cstr_t*
-cstr_assignN(cstr_t* self, const char* str, size_t len);
-STC_API cstr_t*
-cstr_appendN(cstr_t* self, const char* str, size_t len);
+cstr_resize(cstr* self, size_t len, char fill);
+STC_API cstr
+cstr_make_reserved(size_t cap);
+STC_API cstr*
+cstr_assign_n(cstr* self, const char* str, size_t len);
+STC_API cstr*
+cstr_append_n(cstr* self, const char* str, size_t len);
STC_API void
-cstr_insertN(cstr_t* self, size_t pos, const char* str, size_t n);
+cstr_insert_n(cstr* self, size_t pos, const char* str, size_t n);
STC_API size_t
-cstr_replaceN(cstr_t* self, size_t pos, const char* str1, size_t n1, const char* str2, size_t n2);
+cstr_replace_n(cstr* self, size_t pos, const char* str1, size_t n1, const char* str2, size_t n2);
STC_API void
-cstr_erase(cstr_t* self, size_t pos, size_t n);
+cstr_erase(cstr* self, size_t pos, size_t n);
STC_API char*
-cstr_strnstr(cstr_t s, size_t pos, const char* needle, size_t n);
+cstr_strnstr(cstr s, size_t pos, const char* needle, size_t n);
STC_INLINE void
-cstr_destroy(cstr_t* self) {
+cstr_destroy(cstr* self) {
if (cstr_capacity(*self)) {
free(_cstr_rep(self));
}
}
-STC_INLINE cstr_t
-cstr_makeFilled(size_t len, char fill) {
- cstr_t s = cstr_init;
+STC_INLINE cstr
+cstr_make_filled(size_t len, char fill) {
+ cstr s = cstr_init;
if (len) cstr_resize(&s, len, fill);
return s;
}
-STC_INLINE cstr_t
+STC_INLINE cstr
cstr_make(const char* str) {
- return cstr_makeN(str, strlen(str));
+ return cstr_make_n(str, strlen(str));
}
-STC_INLINE cstr_t
-cstr_makeCopy(cstr_t s) {
- return cstr_makeN(s.str, cstr_size(s));
+STC_INLINE cstr
+cstr_make_copy(cstr s) {
+ return cstr_make_n(s.str, cstr_size(s));
}
STC_INLINE void
-cstr_clear(cstr_t* self) {
+cstr_clear(cstr* self) {
cstr_destroy(self);
*self = cstr_init;
}
-STC_INLINE cstr_t*
-cstr_assign(cstr_t* self, const char* str) {
- return cstr_assignN(self, str, strlen(str));
+STC_INLINE cstr*
+cstr_assign(cstr* self, const char* str) {
+ return cstr_assign_n(self, str, strlen(str));
}
-STC_INLINE cstr_t*
-cstr_copy(cstr_t* self, cstr_t s) {
- return cstr_assignN(self, s.str, cstr_size(s));
+STC_INLINE cstr*
+cstr_copy(cstr* self, cstr s) {
+ return cstr_assign_n(self, s.str, cstr_size(s));
}
-STC_INLINE cstr_t*
-cstr_take(cstr_t* self, cstr_t s) {
+STC_INLINE cstr*
+cstr_take(cstr* self, cstr s) {
if (self->str != s.str && cstr_capacity(*self))
free(_cstr_rep(self));
self->str = s.str;
return self;
}
-STC_INLINE cstr_t
-cstr_move(cstr_t* self) {
- cstr_t tmp = *self;
+STC_INLINE cstr
+cstr_move(cstr* self) {
+ cstr tmp = *self;
*self = cstr_init;
return tmp;
}
-STC_INLINE cstr_t*
-cstr_append(cstr_t* self, const char* str) {
- return cstr_appendN(self, str, strlen(str));
+STC_INLINE cstr*
+cstr_append(cstr* self, const char* str) {
+ return cstr_append_n(self, str, strlen(str));
}
-STC_INLINE cstr_t*
-cstr_appendS(cstr_t* self, cstr_t s) {
- return cstr_appendN(self, s.str, cstr_size(s));
+STC_INLINE cstr*
+cstr_appendS(cstr* self, cstr s) {
+ return cstr_append_n(self, s.str, cstr_size(s));
}
-STC_INLINE cstr_t*
-cstr_pushBack(cstr_t* self, char value) {
- return cstr_appendN(self, &value, 1);
+STC_INLINE cstr*
+cstr_push_back(cstr* self, char value) {
+ return cstr_append_n(self, &value, 1);
}
STC_INLINE void
-cstr_popBack(cstr_t* self) {
+cstr_pop_back(cstr* self) {
--_cstr_size(*self);
}
STC_INLINE char
-cstr_back(cstr_t s) {
+cstr_back(cstr s) {
return s.str[cstr_size(s) - 1];
}
STC_INLINE void
-cstr_insert(cstr_t* self, size_t pos, const char* str) {
- cstr_insertN(self, pos, str, strlen(str));
+cstr_insert(cstr* self, size_t pos, const char* str) {
+ cstr_insert_n(self, pos, str, strlen(str));
}
STC_INLINE size_t
-cstr_replace(cstr_t* self, size_t pos, const char* str1, const char* str2) {
- return cstr_replaceN(self, pos, str1, strlen(str1), str2, strlen(str2));
+cstr_replace(cstr* self, size_t pos, const char* str1, const char* str2) {
+ return cstr_replace_n(self, pos, str1, strlen(str1), str2, strlen(str2));
}
/* readonly */
STC_INLINE bool
-cstr_empty(cstr_t s) {
+cstr_empty(cstr s) {
return cstr_size(s) == 0;
}
STC_INLINE bool
-cstr_equals(cstr_t s1, const char* str) {
+cstr_equals(cstr s1, const char* str) {
return strcmp(s1.str, str) == 0;
}
STC_INLINE bool
-cstr_equalsS(cstr_t s1, cstr_t s2) {
+cstr_equalsS(cstr s1, cstr s2) {
return strcmp(s1.str, s2.str) == 0;
}
STC_INLINE int
cstr_compare(const void* s1, const void* s2) {
- return strcmp(((const cstr_t*)s1)->str, ((const cstr_t*)s2)->str);
+ return strcmp(((const cstr*)s1)->str, ((const cstr*)s2)->str);
}
STC_INLINE size_t
-cstr_findN(cstr_t s, size_t pos, const char* needle, size_t n) {
+cstr_findN(cstr s, size_t pos, const char* needle, size_t n) {
char* res = cstr_strnstr(s, pos, needle, n);
return res ? res - s.str : cstr_npos;
}
STC_INLINE size_t
-cstr_find(cstr_t s, size_t pos, const char* needle) {
+cstr_find(cstr s, size_t pos, const char* needle) {
char* res = strstr(s.str + pos, needle);
return res ? res - s.str : cstr_npos;
}
@@ -200,7 +200,7 @@ STC_INLINE uint32_t cstr_hashRaw(const char* const* sPtr, size_t ignored) {
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
STC_API void
-cstr_reserve(cstr_t* self, size_t cap) {
+cstr_reserve(cstr* self, size_t cap) {
size_t len = cstr_size(*self), oldcap = cstr_capacity(*self);
if (cap > oldcap) {
size_t* rep = (size_t *) realloc(oldcap ? _cstr_rep(self) : NULL, _cstr_mem(cap));
@@ -211,40 +211,40 @@ cstr_reserve(cstr_t* self, size_t cap) {
}
STC_API void
-cstr_resize(cstr_t* self, size_t len, char fill) {
+cstr_resize(cstr* self, size_t len, char fill) {
size_t n = cstr_size(*self);
cstr_reserve(self, len);
if (len > n) memset(self->str + n, fill, len - n);
self->str[_cstr_size(*self) = len] = '\0';
}
-STC_API cstr_t
-cstr_makeReserved(size_t cap) {
+STC_API cstr
+cstr_make_reserved(size_t cap) {
if (cap == 0) return cstr_init;
size_t *rep = (size_t *) malloc(_cstr_mem(cap));
- cstr_t s = {(char *) (rep + 2)};
+ cstr s = {(char *) (rep + 2)};
rep[0] = 0, rep[1] = cap, s.str[0] = '\0';
return s;
}
-STC_API cstr_t
-cstr_makeN(const char* str, size_t len) {
+STC_API cstr
+cstr_make_n(const char* str, size_t len) {
if (len == 0) return cstr_init;
size_t *rep = (size_t *) malloc(_cstr_mem(len));
- cstr_t s = {(char *) (rep + 2)};
+ cstr s = {(char *) (rep + 2)};
memcpy(s.str, str, len);
s.str[rep[0] = rep[1] = len] = '\0';
return s;
}
-STC_API cstr_t
+STC_API cstr
cstr_from(const char* fmt, ...) {
- cstr_t tmp = cstr_init;
+ cstr tmp = cstr_init;
va_list args;
va_start(args, fmt);
int len = vsnprintf(NULL, (size_t)0, fmt, args);
if (len > 0) {
- tmp = cstr_makeReserved(len);
+ tmp = cstr_make_reserved(len);
vsprintf(tmp.str, fmt, args);
_cstr_size(tmp) = len;
}
@@ -252,8 +252,8 @@ cstr_from(const char* fmt, ...) {
return tmp;
}
-STC_API cstr_t*
-cstr_assignN(cstr_t* self, const char* str, size_t len) {
+STC_API cstr*
+cstr_assign_n(cstr* self, const char* str, size_t len) {
if (len || cstr_capacity(*self)) {
cstr_reserve(self, len);
memmove(self->str, str, len);
@@ -262,8 +262,8 @@ cstr_assignN(cstr_t* self, const char* str, size_t len) {
return self;
}
-STC_API cstr_t*
-cstr_appendN(cstr_t* self, const char* str, size_t len) {
+STC_API cstr*
+cstr_append_n(cstr* self, const char* str, size_t len) {
if (len) {
size_t oldlen = cstr_size(*self), newlen = oldlen + len;
if (newlen > cstr_capacity(*self))
@@ -274,7 +274,7 @@ cstr_appendN(cstr_t* self, const char* str, size_t len) {
return self;
}
-STC_INLINE void _cstr_internalMove(cstr_t* self, size_t pos1, size_t pos2) {
+STC_INLINE void _cstr_internalMove(cstr* self, size_t pos1, size_t pos2) {
if (pos1 == pos2)
return;
size_t len = cstr_size(*self), newlen = len + pos2 - pos1;
@@ -285,7 +285,7 @@ STC_INLINE void _cstr_internalMove(cstr_t* self, size_t pos1, size_t pos2) {
}
STC_API void
-cstr_insertN(cstr_t* self, size_t pos, const char* str, size_t n) {
+cstr_insert_n(cstr* self, size_t pos, const char* str, size_t n) {
char* xstr = (char *) memcpy(n > c_max_alloca ? malloc(n) : alloca(n), str, n);
_cstr_internalMove(self, pos, pos + n);
memcpy(&self->str[pos], xstr, n);
@@ -293,7 +293,7 @@ cstr_insertN(cstr_t* self, size_t pos, const char* str, size_t n) {
}
STC_API size_t
-cstr_replaceN(cstr_t* self, size_t pos, const char* str1, size_t n1, const char* str2, size_t n2) {
+cstr_replace_n(cstr* self, size_t pos, const char* str1, size_t n1, const char* str2, size_t n2) {
size_t pos2 = cstr_findN(*self, pos, str1, n1);
if (pos2 == cstr_npos) return cstr_npos;
char* xstr2 = (char *) memcpy(n2 > c_max_alloca ? malloc(n2) : alloca(n2), str2, n2);
@@ -304,7 +304,7 @@ cstr_replaceN(cstr_t* self, size_t pos, const char* str1, size_t n1, const char*
}
STC_API void
-cstr_erase(cstr_t* self, size_t pos, size_t n) {
+cstr_erase(cstr* self, size_t pos, size_t n) {
size_t len = cstr_size(*self);
if (len) {
memmove(&self->str[pos], &self->str[pos + n], len - (pos + n));
@@ -313,7 +313,7 @@ cstr_erase(cstr_t* self, size_t pos, size_t n) {
}
STC_API char*
-cstr_strnstr(cstr_t s, size_t pos, const char* needle, size_t n) {
+cstr_strnstr(cstr s, size_t pos, const char* needle, size_t n) {
char *x = s.str + pos, /* haystack */
*z = s.str + cstr_size(s) - n + 1;
if (x >= z)
diff --git a/stc/cvec.h b/stc/cvec.h
index 062ff601..ad8751e8 100644
--- a/stc/cvec.h
+++ b/stc/cvec.h
@@ -36,13 +36,13 @@
#define declare_cvec(...) c_MACRO_OVERLOAD(declare_cvec, __VA_ARGS__)
#define declare_cvec_2(tag, Value) \
- declare_cvec_3(tag, Value, c_defaultDestroy)
+ declare_cvec_3(tag, Value, c_default_destroy)
#define declare_cvec_3(tag, Value, valueDestroy) \
- declare_cvec_4(tag, Value, valueDestroy, c_defaultCompare)
+ declare_cvec_4(tag, Value, valueDestroy, c_default_compare)
#define declare_cvec_4(tag, Value, valueDestroy, valueCompare) \
declare_cvec_6(tag, Value, valueDestroy, valueCompare, Value, c_defaultGetRaw)
#define declare_cvec_str() \
- declare_cvec_6(str, cstr_t, cstr_destroy, cstr_compareRaw, const char*, cstr_getRaw)
+ declare_cvec_6(str, cstr, cstr_destroy, cstr_compareRaw, const char*, cstr_getRaw)
#define declare_cvec_6(tag, Value, valueDestroy, valueCompareRaw, RawValue, valueGetRaw) \
@@ -56,7 +56,7 @@ cvec_##tag##_init(void) {cvec_##tag x = cvec_init; return x;} \
STC_API cvec_##tag \
cvec_##tag##_make(size_t size, Value null); \
STC_API void \
-cvec_##tag##_pushN(cvec_##tag *self, const Value in[], size_t size); \
+cvec_##tag##_push_n(cvec_##tag *self, const Value in[], size_t size); \
STC_API void \
cvec_##tag##_destroy(cvec_##tag* self); \
STC_API void \
@@ -64,9 +64,9 @@ cvec_##tag##_reserve(cvec_##tag* self, size_t cap); \
STC_API void \
cvec_##tag##_clear(cvec_##tag* self); \
STC_API void \
-cvec_##tag##_pushBack(cvec_##tag* self, Value value); \
+cvec_##tag##_push_back(cvec_##tag* self, Value value); \
STC_INLINE void \
-cvec_##tag##_popBack(cvec_##tag* self) { \
+cvec_##tag##_pop_back(cvec_##tag* self) { \
valueDestroy(&self->data[_cvec_size(*self) - 1]); \
--_cvec_size(*self); \
} \
@@ -123,7 +123,7 @@ cvec_##tag##_make(size_t size, Value null) { \
return vec; \
} \
STC_API void \
-cvec_##tag##_pushN(cvec_##tag *self, const Value in[], size_t size) { \
+cvec_##tag##_push_n(cvec_##tag *self, const Value in[], size_t size) { \
cvec_##tag##_reserve(self, cvec_size(*self) + size); \
_cvec_size(*self) += size; \
for (size_t i=0; i<size; ++i) self->data[i] = in[i]; \
@@ -156,7 +156,7 @@ cvec_##tag##_clear(cvec_##tag* self) { \
} \
\
STC_API void \
-cvec_##tag##_pushBack(cvec_##tag* self, Value value) { \
+cvec_##tag##_push_back(cvec_##tag* self, Value value) { \
size_t len = cvec_size(*self); \
if (len == cvec_capacity(*self)) \
cvec_##tag##_reserve(self, 7 + len * 5 / 3); \
@@ -196,7 +196,7 @@ cvec_##tag##_find(const cvec_##tag* self, RawValue rawValue) { \
} \
\
STC_API int \
-cvec_##tag##_sortCompare(const void* x, const void* y) { \
+cvec_##tag##_sort_compare(const void* x, const void* y) { \
RawValue rx = valueGetRaw((const Value *) x); \
RawValue ry = valueGetRaw((const Value *) y); \
return valueCompareRaw(&rx, &ry); \
@@ -205,7 +205,7 @@ STC_EXTERN_IMPORT void qsort(void *base, size_t nitems, size_t size, int (*compa
STC_API void \
cvec_##tag##_sort(cvec_##tag* self) { \
size_t len = cvec_size(*self); \
- if (len) qsort(self->data, len, sizeof(Value), cvec_##tag##_sortCompare); \
+ if (len) qsort(self->data, len, sizeof(Value), cvec_##tag##_sort_compare); \
}
#else
diff --git a/stc/cvecpq.h b/stc/cvecpq.h
index f78adf04..a8806927 100644
--- a/stc/cvecpq.h
+++ b/stc/cvecpq.h
@@ -60,7 +60,7 @@ cvecpq_##tag##_pop(cvec_##tag* self) {cvecpq_##tag##_erase(self, 0);} \
STC_API void \
cvecpq_##tag##_push(cvec_##tag* self, cvec_##tag##_value_t value); \
STC_API void \
-cvecpq_##tag##_pushN(cvec_##tag *self, const cvec_##tag##_value_t in[], size_t size); \
+cvecpq_##tag##_push_n(cvec_##tag *self, const cvec_##tag##_value_t in[], size_t size); \
\
implement_cvec_priority_queue(tag, cmpOpr) \
typedef cvec_##tag##_value_t cvecpq_##tag##_input_t
@@ -74,9 +74,9 @@ STC_INLINE void \
_cvecpq_##tag##_siftDown(cvec_##tag##_value_t* arr, size_t i, size_t n) { \
size_t r = i, c = i << 1; \
while (c <= n) { \
- if (c < n && cvec_##tag##_sortCompare(&arr[c], &arr[c + 1]) cmpOpr 0) \
+ if (c < n && cvec_##tag##_sort_compare(&arr[c], &arr[c + 1]) cmpOpr 0) \
++c; \
- if (cvec_##tag##_sortCompare(&arr[r], &arr[c]) cmpOpr 0) { \
+ if (cvec_##tag##_sort_compare(&arr[r], &arr[c]) cmpOpr 0) { \
cvec_##tag##_value_t t = arr[r]; arr[r] = arr[c]; arr[r = c] = t; \
} else \
return; \
@@ -88,21 +88,21 @@ STC_API void \
cvecpq_##tag##_erase(cvec_##tag* self, size_t i) { \
size_t n = cvec_size(*self) - 1; \
self->data[i] = self->data[n]; \
- cvec_##tag##_popBack(self); \
+ cvec_##tag##_pop_back(self); \
_cvecpq_##tag##_siftDown(self->data - 1, i + 1, n); \
} \
\
STC_API void \
cvecpq_##tag##_push(cvec_##tag* self, cvec_##tag##_value_t value) { \
- cvec_##tag##_pushBack(self, value); /* sift-up the value */ \
+ cvec_##tag##_push_back(self, value); /* sift-up the value */ \
size_t n = cvec_size(*self), c = n; \
cvec_##tag##_value_t *arr = self->data - 1; \
- for (; c > 1 && cvec_##tag##_sortCompare(&arr[c >> 1], &value) cmpOpr 0; c >>= 1) \
+ for (; c > 1 && cvec_##tag##_sort_compare(&arr[c >> 1], &value) cmpOpr 0; c >>= 1) \
arr[c] = arr[c >> 1]; \
if (c != n) arr[c] = value; \
} \
STC_API void \
-cvecpq_##tag##_pushN(cvec_##tag *self, const cvec_##tag##_value_t in[], size_t size) { \
+cvecpq_##tag##_push_n(cvec_##tag *self, const cvec_##tag##_value_t in[], size_t size) { \
cvec_##tag##_reserve(self, cvec_size(*self) + size); \
for (size_t i=0; i<size; ++i) cvecpq_##tag##_push(self, in[i]); \
} \