summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-09-03 12:59:41 +0200
committerTyge Løvset <[email protected]>2020-09-03 12:59:41 +0200
commita4e2ee22fd57665d2388d5debc17db896a4a389f (patch)
tree6a3a88772cd9d3b604f9def4c0579ed941983f61
parentaaa3d7f6a107a668b1f24d8ed061fe74237d9883 (diff)
downloadSTC-modified-a4e2ee22fd57665d2388d5debc17db896a4a389f.tar.gz
STC-modified-a4e2ee22fd57665d2388d5debc17db896a4a389f.zip
Changed constant <container>_init to <container>_ini to avoid conflict with <container>_init() method.
Reverted name cprique back to cpqueue.
-rw-r--r--README.md18
-rw-r--r--examples/README.md2
-rw-r--r--examples/advanced.c2
-rw-r--r--examples/benchmark.c2
-rw-r--r--examples/birthday.c2
-rw-r--r--examples/complex.c6
-rw-r--r--examples/demos.c14
-rw-r--r--examples/ex_gaussian.c6
-rw-r--r--examples/geek1.c2
-rw-r--r--examples/geek2.c4
-rw-r--r--examples/geek3.c4
-rw-r--r--examples/geek4.c12
-rw-r--r--examples/geek5.c4
-rw-r--r--examples/geek6.c2
-rw-r--r--examples/geek7.c16
-rw-r--r--examples/heap.c18
-rw-r--r--examples/inits.c14
-rw-r--r--examples/list.c2
-rw-r--r--examples/mapmap.c4
-rw-r--r--examples/phonebook.c2
-rw-r--r--examples/priority.c18
-rw-r--r--examples/random.c2
-rw-r--r--examples/stack.c5
-rw-r--r--examples/words.c6
-rw-r--r--stc/cbitset.h2
-rw-r--r--stc/clist.h6
-rw-r--r--stc/cmap.h12
-rw-r--r--stc/coption.h6
-rw-r--r--stc/cpqueue.h (renamed from stc/cprique.h)94
-rw-r--r--stc/cqueue.h4
-rw-r--r--stc/cstack.h4
-rw-r--r--stc/cstr.h29
-rw-r--r--stc/cvec.h8
33 files changed, 170 insertions, 162 deletions
diff --git a/README.md b/README.md
index 8f3c9f84..b5f76405 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ An elegant, fully typesafe, generic, customizable, user-friendly, consistent, an
- **stc/cvec.h** - Dynamic generic **vector** class, works well as a **stack**.
- **stc/cstack.h** - **stack** adapter, currently works with *cvec*.
- **stc/cqueue.h** - **queue** adapter, currently works with *clist*.
-- **stc/cprique.h** - **priority queue** adapter. Works with *cvec*.
+- **stc/cpqueue.h** - **priority queue** adapter. Works with *cvec*.
- **stc/coption.h** - Implementation of a **getopt_long()**-like function, *coption_get()*, to parse command line arguments.
- **stc/crandom.h** - A few very efficent modern random number generators *pcg32* and my own *64-bit PRNG* inspired by *sfc64*. Both uniform and normal distributions.
- **stc/cdefs.h** - A common include file with a few general definitions.
@@ -27,7 +27,7 @@ All containers mentioned above, except cstr_t and cbitset_t are generic and type
declare_cvec(i, int);
int main(void) {
- cvec_i vec = cvec_init;
+ cvec_i vec = cvec_ini;
cvec_i_push_back(&vec, 42);
cvec_i_destroy(&vec);
}
@@ -136,7 +136,7 @@ To avoid this, use
```
declare_cmap_strkey(si, int);
...
-cmap_si map = cmap_init;
+cmap_si map = cmap_ini;
cmap_si_put(&map, "mykey", 12); // constructs a cstr_t key from the const char* internally.
int x = cmap_si_find(&map, "mykey")->value; // no allocation of string key happens here.
cmap_si_destroy(&map);
@@ -184,7 +184,7 @@ int main() {
declare_cvec(ix, int64_t); // ix is just an example type tag name.
int main() {
- cvec_ix bignums = cvec_init; // use cvec_ix_init() if initializing after declaration.
+ cvec_ix bignums = cvec_ini; // use cvec_ix_init() if initializing after declaration.
cvec_ix_reserve(&bignums, 100);
for (size_t i = 0; i<100; ++i)
cvec_ix_push_back(&bignums, i * i * i);
@@ -203,7 +203,7 @@ int main() {
declare_cvec_str();
int main() {
- cvec_str names = cvec_init;
+ cvec_str names = cvec_ini;
cvec_str_push_back(&names, "Mary");
cvec_str_push_back(&names, "Joe");
cstr_assign(&names.data[1], "Jake"); // replace "Joe".
@@ -223,7 +223,7 @@ int main() {
declare_cmap(ii, int, int);
int main() {
- cmap_ii nums = cmap_init;
+ cmap_ii nums = cmap_ini;
cmap_ii_put(&nums, 8, 64); // put() works as c++ std::unordered_map<>::insert_or_replace()
cmap_ii_insert(&nums, 11, 121); // only insert value if key does not exists - like std::unordered_map::insert().
@@ -238,7 +238,7 @@ int main() {
declare_cset_str(); // cstr set. See the discussion above.
int main() {
- cset_str words = cset_init;
+ cset_str words = cset_ini;
cset_str_put(&words, "Hello");
cset_str_put(&words, "Cruel");
cset_str_put(&words, "World");
@@ -257,7 +257,7 @@ int main() {
declare_cmap_str();
int main() {
- cmap_str table = cmap_init;
+ cmap_str table = cmap_ini;
cmap_str_put(&table, "Make", "my");
cmap_str_put(&table, "Rainy", "day");
cmap_str_put(&table, "Sunny", "afternoon");
@@ -279,7 +279,7 @@ int main() {
declare_clist(fx, double);
int main() {
- clist_fx list = clist_init;
+ clist_fx list = clist_ini;
crand_eng64_t eng = crand_eng64_init(time(NULL));
crand_uniform_f64_t dist = crand_uniform_f64_init(100.0, 1000.0);
int k;
diff --git a/examples/README.md b/examples/README.md
index 661f7555..7947f16c 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -60,7 +60,7 @@ cmap_vk uses vikingvw_hash() for hash value calculations, and vikingvw_equals()
Finally, main which also demos the generic c_push() of multiple elements:
```
int main() {
- cmap_vk vikings = cmap_init;
+ cmap_vk vikings = cmap_ini;
c_push(&vikings, cmap_vk, c_items(
{ {"Einar", "Norway"}, 20 },
{ {"Olaf", "Denmark"}, 24 },
diff --git a/examples/advanced.c b/examples/advanced.c
index 03baf5fc..90f800e0 100644
--- a/examples/advanced.c
+++ b/examples/advanced.c
@@ -62,7 +62,7 @@ declare_cmap(vk, Viking, int, c_default_destroy, vikingvw_equals, vikingvw_hash,
int main()
{
- cmap_vk vikings = cmap_init;
+ cmap_vk vikings = cmap_ini;
c_push(&vikings, cmap_vk, c_items(
{{"Einar", "Norway"}, 20},
{{"Olaf", "Denmark"}, 24},
diff --git a/examples/benchmark.c b/examples/benchmark.c
index d4e1e82c..1c94397d 100644
--- a/examples/benchmark.c
+++ b/examples/benchmark.c
@@ -34,7 +34,7 @@ crand_rng64_t rng;
#define RAND(N) (crand_i64(&rng) & ((1 << N) - 1))
-#define CMAP_SETUP(tt, Key, Value) cmap_##tt map = cmap_init \
+#define CMAP_SETUP(tt, Key, Value) cmap_##tt map = cmap_ini \
; cmap_##tt##_set_load_factors(&map, max_load_factor, 0.0)
#define CMAP_PUT(tt, key, val) cmap_##tt##_put(&map, key, val)->value
#define CMAP_INSERT(tt, key, val) cmap_##tt##_insert(&map, key, val)
diff --git a/examples/birthday.c b/examples/birthday.c
index 4f6e7a8b..be2114da 100644
--- a/examples/birthday.c
+++ b/examples/birthday.c
@@ -16,7 +16,7 @@ const static uint64_t mask = (1ull << 52) - 1;
void repeats(void)
{
crand_rng64_t rng = crand_rng64_init(seed);
- cmap_ic m = cmap_init;
+ cmap_ic m = cmap_ini;
cmap_ic_reserve(&m, N);
clock_t now = clock();
for (size_t i = 0; i < N; ++i) {
diff --git a/examples/complex.c b/examples/complex.c
index 8810bac5..25a59eff 100644
--- a/examples/complex.c
+++ b/examples/complex.c
@@ -14,14 +14,14 @@ int main() {
int xdim = 4, ydim = 6;
int x = 1, y = 5, tableKey = 42;
const char* strKey = "first";
- cmap_s myMap = cmap_init;
+ cmap_s myMap = cmap_ini;
{ // Construct.
carray2f table = carray2f_make(ydim, xdim, 0.f);
printf("table: (%zu, %zu)\n", carray2_ydim(table), carray2_xdim(table));
- clist_y tableList = clist_init;
+ clist_y tableList = clist_ini;
// Put in some data.
- cmap_g listMap = cmap_init;
+ cmap_g listMap = cmap_ini;
*carray2f_at(&table, y, x) = 3.1415927; // table[y][x]
clist_y_push_back(&tableList, table);
diff --git a/examples/demos.c b/examples/demos.c
index 731197e3..6b2806fa 100644
--- a/examples/demos.c
+++ b/examples/demos.c
@@ -39,7 +39,7 @@ declare_cvec(ix, int64_t); // ix is just an example tag name.
void vectordemo1()
{
printf("\nVECTORDEMO1\n");
- cvec_ix bignums = cvec_init; // = (cvec_ix) cvec_init; if initializing after declaration.
+ cvec_ix bignums = cvec_ini; // = (cvec_ix) cvec_ini; if initializing after declaration.
cvec_ix_reserve(&bignums, 100);
for (size_t i = 0; i<=100; ++i)
cvec_ix_push_back(&bignums, i * i * i);
@@ -60,7 +60,7 @@ declare_cvec_str();
void vectordemo2()
{
printf("\nVECTORDEMO2\n");
- cvec_str names = cvec_init;
+ cvec_str names = cvec_ini;
cvec_str_push_back(&names, "Mary");
cvec_str_push_back(&names, "Joe");
cvec_str_push_back(&names, "Chris");
@@ -78,7 +78,7 @@ declare_clist(ix, int);
void listdemo1()
{
printf("\nLISTDEMO1\n");
- clist_ix nums = clist_init, nums2 = clist_init;
+ clist_ix nums = clist_ini, nums2 = clist_ini;
for (int i = 0; i < 10; ++i)
clist_ix_push_back(&nums, i);
for (int i = 100; i < 110; ++i)
@@ -105,7 +105,7 @@ declare_cset(i, int);
void setdemo1()
{
printf("\nSETDEMO1\n");
- cset_i nums = cset_init;
+ cset_i nums = cset_ini;
cset_i_put(&nums, 8);
cset_i_put(&nums, 11);
@@ -120,7 +120,7 @@ declare_cmap(ii, int, int);
void mapdemo1()
{
printf("\nMAPDEMO1\n");
- cmap_ii nums = cmap_init;
+ cmap_ii nums = cmap_ini;
cmap_ii_put(&nums, 8, 64);
cmap_ii_put(&nums, 11, 121);
@@ -134,7 +134,7 @@ declare_cmap_strkey(si, int); // Shorthand macro for the general declare_cmap ex
void mapdemo2()
{
printf("\nMAPDEMO2\n");
- cmap_si nums = cmap_init;
+ cmap_si nums = cmap_ini;
cmap_si_put(&nums, "Hello", 64);
cmap_si_put(&nums, "Groovy", 121);
cmap_si_put(&nums, "Groovy", 200); // overwrite previous
@@ -156,7 +156,7 @@ declare_cmap_strkey(ss, cstr_t, cstr_destroy);
void mapdemo3()
{
printf("\nMAPDEMO3\n");
- cmap_ss table = cmap_init;
+ cmap_ss table = cmap_ini;
cmap_ss_put(&table, "Map", cstr_make("test"));
cmap_ss_put(&table, "Make", cstr_make("my"));
cmap_ss_put(&table, "Sunny", cstr_make("day"));
diff --git a/examples/ex_gaussian.c b/examples/ex_gaussian.c
index 75efec51..a4682a2b 100644
--- a/examples/ex_gaussian.c
+++ b/examples/ex_gaussian.c
@@ -29,20 +29,20 @@ int main()
crand_normal_f64_t dist = crand_normal_f64_init(rng, Mean, StdDev);
// Create histogram map
- cmap_i mhist = cmap_init;
+ cmap_i mhist = cmap_ini;
for (size_t i = 0; i < N; ++i) {
int index = round( crand_normal_f64(&dist) );
cmap_i_insert(&mhist, index, 0)->value += 1;
}
// Transfer map to vec and sort it by map keys.
- cvec_e vhist = cvec_init;
+ cvec_e vhist = cvec_ini;
c_foreach (i, cmap_i, mhist)
cvec_e_push_back(&vhist, *i.item);
cvec_e_sort(&vhist);
// Print the gaussian bar chart
- cstr_t bar = cstr_init;
+ cstr_t bar = cstr_ini;
c_foreach (i, cvec_e, vhist) {
size_t n = (size_t) (i.item->value * Mag / N);
if (n > 0) {
diff --git a/examples/geek1.c b/examples/geek1.c
index 44824978..8759e143 100644
--- a/examples/geek1.c
+++ b/examples/geek1.c
@@ -19,7 +19,7 @@ int findMaximumPairs(int a[], int n, int k)
{
// Hash-table
- cmap_ii hash = cmap_init;
+ cmap_ii hash = cmap_ini;
for (int i = 0; i < n; i++) {
cmap_ii_insert(&hash, a[i] % k, 0)->value++;
}
diff --git a/examples/geek2.c b/examples/geek2.c
index 6141518f..0e8b384a 100644
--- a/examples/geek2.c
+++ b/examples/geek2.c
@@ -10,8 +10,8 @@ int main()
{
// Lets use an explicit type signature (which would
// be `cmap<String, String>` in this example).
- cmap_str book_reviews = cmap_init;
- cset_str set = cset_init;
+ cmap_str book_reviews = cmap_ini;
+ cset_str set = cset_ini;
cset_str_put(&set, "Hello");
cset_str_put(&set, "You");
cset_str_put(&set, "Tube");
diff --git a/examples/geek3.c b/examples/geek3.c
index ad2bdfa1..044d7b16 100644
--- a/examples/geek3.c
+++ b/examples/geek3.c
@@ -8,7 +8,7 @@ declare_cmap_strkey(ss, cstr_t, cstr_destroy);
int main ()
{
- cmap_si mymap = cmap_init;
+ cmap_si mymap = cmap_ini;
cmap_si_put(&mymap, "Mars", 3000);
cmap_si_put(&mymap, "Saturn", 60000);
cmap_si_put(&mymap, "Jupiter", 70000);
@@ -28,7 +28,7 @@ int main ()
puts("------------------------");
// Create an unordered_map of three strings (that map to strings)
- cmap_ss u = cmap_init;
+ 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"));
diff --git a/examples/geek4.c b/examples/geek4.c
index a62a6fd1..06c93de4 100644
--- a/examples/geek4.c
+++ b/examples/geek4.c
@@ -49,7 +49,7 @@ int commonWords(cvec_str S)
// To store all the words of first string
- cvec_sb ans = cvec_init;
+ cvec_sb ans = cvec_ini;
// m will store number of strings in given vector
m = cvec_size(S);
@@ -59,8 +59,8 @@ 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;
- cmap_sb_entry_t tmp = {cstr_init, false};
+ cstr_t word = cstr_ini;
+ cmap_sb_entry_t tmp = {cstr_ini, false};
while (i < cstr_size(S.data[0]) && S.data[0].str[i] != ' ') {
cstr_push_back(&word, S.data[0].str[i]);
@@ -85,11 +85,11 @@ int commonWords(cvec_str S)
for (j = 1; j < m; j++) {
// It will be used to check if a word is present
// in a particuler string
- cmap_sb has = cmap_init;
+ cmap_sb has = cmap_ini;
i = 0;
while (i < cstr_size(S.data[j])) {
- cstr_t word = cstr_init;
+ cstr_t word = cstr_ini;
while (i < cstr_size(S.data[j]) && S.data[j].str[i] != ' ') {
cstr_push_back(&word, S.data[j].str[i]);
i++;
@@ -136,7 +136,7 @@ int commonWords(cvec_str S)
// Driver code
int main()
{
- cvec_str S = cvec_init;
+ cvec_str S = cvec_ini;
cvec_str_push_back(&S, "there is a cow");
cvec_str_push_back(&S, "cow is our mother");
cvec_str_push_back(&S, "cow gives us milk and milk is sweet");
diff --git a/examples/geek5.c b/examples/geek5.c
index a0531ad3..614bc387 100644
--- a/examples/geek5.c
+++ b/examples/geek5.c
@@ -29,7 +29,7 @@ declare_cmap_strkey(sv, cvec_i, cvec_i_destroy);
int NumOccurrences(const char* arr[], int n, const char* str, int L, int R)
{
// To store the indices of strings in the array
- cmap_sv M = cmap_init;
+ cmap_sv M = cmap_ini;
for (int i = 0; i < n; i++) {
const char* temp = arr[i];
cmap_sv_entry_t *it = cmap_sv_find(&M, temp);
@@ -38,7 +38,7 @@ int NumOccurrences(const char* arr[], int n, const char* str, int L, int R)
// have an entry in the map
// then create the entry
if (it == NULL) {
- cvec_i A = cvec_init;
+ cvec_i A = cvec_ini;
cvec_i_push_back(&A, i + 1);
cmap_sv_put(&M, temp, A);
}
diff --git a/examples/geek6.c b/examples/geek6.c
index db0b3bcf..e906600f 100644
--- a/examples/geek6.c
+++ b/examples/geek6.c
@@ -37,7 +37,7 @@ declare_cset(i, int);
int missingNumber(int a[], int n)
{
// Declaring an unordered_map
- cset_i mp = cset_init;
+ cset_i mp = cset_ini;
// if array value is positive
// store it in map
diff --git a/examples/geek7.c b/examples/geek7.c
index c686b014..4be984ee 100644
--- a/examples/geek7.c
+++ b/examples/geek7.c
@@ -25,11 +25,11 @@ After inserting all the elements excluding the ones which are to be deleted, Pop
#include <stc/clist.h>
#include <stc/cmap.h>
#include <stc/cvec.h>
-#include <stc/cprique.h>
+#include <stc/cpqueue.h>
declare_cmap(ii, int, int);
declare_cvec(i, int);
-declare_cprique(i, cvec_i, >);
+declare_cpqueue(i, cvec_i, >);
// Find k minimum element from arr[0..m-1] after deleting
// elements from del[0..n-1]
@@ -37,14 +37,14 @@ void findElementsAfterDel(int arr[], int m, int del[],
int n, int k)
{
// Hash Map of the numbers to be deleted
- cmap_ii mp = cmap_init;
+ cmap_ii mp = cmap_ini;
for (int i = 0; i < n; ++i) {
// Increment the count of del[i]
cmap_ii_insert(&mp, del[i], 0)->value++;
}
- cprique_i heap = cprique_i_init();
+ cpqueue_i heap = cpqueue_i_init();
for (int i = 0; i < m; ++i) {
@@ -63,17 +63,17 @@ void findElementsAfterDel(int arr[], int m, int del[],
// Else push it in the min heap
else
- cprique_i_push(&heap, arr[i]);
+ cpqueue_i_push(&heap, arr[i]);
}
// Print top k elements in the min heap
for (int i = 0; i < k; ++i) {
- printf("%d ", *cprique_i_top(&heap));
+ printf("%d ", *cpqueue_i_top(&heap));
// Pop the top element
- cprique_i_pop(&heap);
+ cpqueue_i_pop(&heap);
}
- cprique_i_destroy(&heap);
+ cpqueue_i_destroy(&heap);
}
int main()
diff --git a/examples/heap.c b/examples/heap.c
index fbcef0cd..5917dd30 100644
--- a/examples/heap.c
+++ b/examples/heap.c
@@ -2,10 +2,10 @@
#include <time.h>
#include <stc/crandom.h>
#include <stc/cvec.h>
-#include <stc/cprique.h>
+#include <stc/cpqueue.h>
declare_cvec(f, float);
-declare_cprique(f, cvec_f, >);
+declare_cpqueue(f, cvec_f, >);
int main()
{
@@ -13,33 +13,33 @@ int main()
crand_rng32_t pcg;
int N = 3000000, M = 100;
- cprique_f pq = cprique_f_init();
+ cpqueue_f pq = cpqueue_f_init();
pcg = crand_rng32_init(seed);
clock_t start = clock();
for (int i=0; i<N; ++i)
cvec_f_push_back(&pq, crand_i32(&pcg));
- cprique_f_build(&pq);
+ cpqueue_f_build(&pq);
printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
for (int i=0; i<M; ++i)
- printf("%.0f ", *cprique_f_top(&pq)), cprique_f_pop(&pq);
+ printf("%.0f ", *cpqueue_f_top(&pq)), cpqueue_f_pop(&pq);
start = clock();
for (int i=M; i<N; ++i)
- cprique_f_pop(&pq);
+ cpqueue_f_pop(&pq);
printf("\n\npopped PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
pcg = crand_rng32_init(seed);
start = clock();
for (int i=0; i<N; ++i)
- cprique_f_push(&pq, crand_i32(&pcg));
+ cpqueue_f_push(&pq, crand_i32(&pcg));
printf("pushed PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
for (int i=0; i<M; ++i)
- printf("%.0f ", *cprique_f_top(&pq)), cprique_f_pop(&pq);
+ printf("%.0f ", *cpqueue_f_top(&pq)), cpqueue_f_pop(&pq);
puts("");
- cprique_f_destroy(&pq);
+ cpqueue_f_destroy(&pq);
}
diff --git a/examples/inits.c b/examples/inits.c
index dada8fac..d7b7a37b 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -2,7 +2,7 @@
#include <stc/cstr.h>
#include <stc/cmap.h>
#include <stc/cvec.h>
-#include <stc/cprique.h>
+#include <stc/cpqueue.h>
#include <stc/clist.h>
declare_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t
@@ -17,7 +17,7 @@ declare_cvec(ip, ipair_t, c_default_destroy, ipair_compare);
declare_clist(ip, ipair_t, c_default_destroy, ipair_compare);
declare_cvec(f, float);
-declare_cprique(f, cvec_f, >);
+declare_cpqueue(f, cvec_f, >);
int main(void) {
@@ -31,16 +31,16 @@ int main(void) {
// CVEC PRIORITY QUEUE
- cprique_f_build(&floats); // reorganise vec
- c_push(&floats, cprique_f, c_items(40.0f, 20.0f, 50.0f, 30.0f, 10.0f));
+ cpqueue_f_build(&floats); // reorganise vec
+ c_push(&floats, cpqueue_f, c_items(40.0f, 20.0f, 50.0f, 30.0f, 10.0f));
// sorted:
while (cvec_size(floats) > 0) {
- printf("%.1f ", *cprique_f_top(&floats));
- cprique_f_pop(&floats);
+ printf("%.1f ", *cpqueue_f_top(&floats));
+ cpqueue_f_pop(&floats);
}
puts("\n");
- cprique_f_destroy(&floats);
+ cpqueue_f_destroy(&floats);
// CMAP ID
diff --git a/examples/list.c b/examples/list.c
index 3aff4482..3b46f02b 100644
--- a/examples/list.c
+++ b/examples/list.c
@@ -6,7 +6,7 @@ declare_clist(fx, double);
int main() {
int k, n = 100000;
- clist_fx list = clist_init;
+ clist_fx list = clist_ini;
crand_rng64_t eng = crand_rng64_init(time(NULL));
crand_uniform_f64_t dist = crand_uniform_f64_init(eng, 0.0f, n);
diff --git a/examples/mapmap.c b/examples/mapmap.c
index d0d8c8fa..a0c1b173 100644
--- a/examples/mapmap.c
+++ b/examples/mapmap.c
@@ -7,8 +7,8 @@ declare_cmap_str();
declare_cmap_strkey(cfg, cmap_str, cmap_str_destroy);
int main(void) {
- cmap_cfg config = cmap_init;
- cmap_str init = cmap_init;
+ cmap_cfg config = cmap_ini;
+ cmap_str init = cmap_ini;
cmap_str_put(&cmap_cfg_insert(&config, "user", init)->value, "name", "Joe");
cmap_str_put(&cmap_cfg_insert(&config, "user", init)->value, "groups", "proj1,proj3");
cmap_str_put(&cmap_cfg_insert(&config, "group", init)->value, "proj1", "Energy");
diff --git a/examples/phonebook.c b/examples/phonebook.c
index 15df04e3..d2ed227f 100644
--- a/examples/phonebook.c
+++ b/examples/phonebook.c
@@ -36,7 +36,7 @@ void print_phone_book(cmap_str phone_book)
int main(int argc, char **argv)
{
bool erased;
- cmap_str phone_book = cmap_init;
+ cmap_str phone_book = cmap_ini;
c_push(&phone_book, cmap_str, c_items(
{"Lilia Friedman", "(892) 670-4739"},
{"Tariq Beltran", "(489) 600-7575"},
diff --git a/examples/priority.c b/examples/priority.c
index fc0526bf..82e78621 100644
--- a/examples/priority.c
+++ b/examples/priority.c
@@ -2,34 +2,34 @@
#include <stdio.h>
#include <time.h>
#include <stc/cvec.h>
-#include <stc/cprique.h>
+#include <stc/cpqueue.h>
#include <stc/cmap.h>
#include <stc/crandom.h>
declare_cvec(i, int64_t);
-declare_cprique(i, cvec_i, >); // min-heap (increasing values)
+declare_cpqueue(i, cvec_i, >); // min-heap (increasing values)
int main() {
size_t N = 10000000;
crand_rng64_t pcg = crand_rng64_init(time(NULL));
crand_uniform_i64_t dist = crand_uniform_i64_init(pcg, 0, N * 10);
- cprique_i heap = cprique_i_init();
+ cpqueue_i heap = cpqueue_i_init();
// Push ten million random numbers to priority queue
for (int i=0; i<N; ++i)
- cprique_i_push(&heap, crand_uniform_i64(&dist));
+ cpqueue_i_push(&heap, crand_uniform_i64(&dist));
// push some negative numbers too.
- c_push(&heap, cprique_i, c_items(-231, -32, -873, -4, -343));
+ c_push(&heap, cpqueue_i, c_items(-231, -32, -873, -4, -343));
for (int i=0; i<N; ++i)
- cprique_i_push(&heap, crand_uniform_i64(&dist));
+ cpqueue_i_push(&heap, crand_uniform_i64(&dist));
// Extract the hundred smallest.
for (int i=0; i<100; ++i) {
- printf("%zd ", *cprique_i_top(&heap));
- cprique_i_pop(&heap);
+ printf("%zd ", *cpqueue_i_top(&heap));
+ cpqueue_i_pop(&heap);
}
- cprique_i_destroy(&heap);
+ cpqueue_i_destroy(&heap);
}
diff --git a/examples/random.c b/examples/random.c
index bf4bd6bd..16632373 100644
--- a/examples/random.c
+++ b/examples/random.c
@@ -58,7 +58,7 @@ int main()
if (n >= 0 && n < R) ++hist[n];
}
- cstr_t bar = cstr_init;
+ cstr_t bar = cstr_ini;
for (int i=0; i < R; ++i) {
cstr_take(&bar, cstr_with_size(hist[i] * 25ull * R / N2, '*'));
printf("%2d %s\n", i, bar.str);
diff --git a/examples/stack.c b/examples/stack.c
index 321228a2..de30c5b4 100644
--- a/examples/stack.c
+++ b/examples/stack.c
@@ -1,12 +1,15 @@
-#include <stc/cstack.h>
#include <stdio.h>
+#include <stc/cstr.h>
+#include <stc/cstack.h>
declare_cvec(i, int);
declare_cstack(i, cvec_i);
+declare_cstack(c, cstr);
int main() {
cstack_i stack = cstack_i_init();
+ cstack_c chars = cstack_c_init();
for (int i=0; i<100; ++i)
cstack_i_push(&stack, i*i);
diff --git a/examples/words.c b/examples/words.c
index 98134cf6..275ffee7 100644
--- a/examples/words.c
+++ b/examples/words.c
@@ -11,7 +11,7 @@ declare_cmap_strkey(si, int);
int main1()
{
- clist_str lwords = clist_init;
+ clist_str lwords = clist_ini;
c_push(&lwords, clist_str, c_items(
"this", "sentence", "is", "not", "a", "sentence",
"this", "sentence", "is", "a", "hoax"
@@ -21,13 +21,13 @@ int main1()
printf("%s\n", w.item->value.str);
puts("");
- cvec_str words = cvec_init;
+ cvec_str words = cvec_ini;
c_push(&words, cvec_str, c_items(
"this", "sentence", "is", "not", "a", "sentence",
"this", "sentence", "is", "a", "hoax"
));
- cmap_si word_map = cmap_init;
+ cmap_si word_map = cmap_ini;
c_foreach (w, cvec_str, words)
++cmap_si_insert(&word_map, w.item->str, 0)->value;
diff --git a/stc/cbitset.h b/stc/cbitset.h
index 31dd3f18..32659a36 100644
--- a/stc/cbitset.h
+++ b/stc/cbitset.h
@@ -48,7 +48,7 @@ int main() {
typedef struct cbitset { uint64_t* _arr; size_t size; } cbitset_t;
-#define cbitset_init {NULL, 0}
+#define cbitset_ini {NULL, 0}
STC_API void cbitset_resize(cbitset_t* self, size_t size, bool value);
STC_API size_t cbitset_count(cbitset_t set);
diff --git a/stc/clist.h b/stc/clist.h
index 39479a09..530cd222 100644
--- a/stc/clist.h
+++ b/stc/clist.h
@@ -38,7 +38,7 @@
declare_clist(ix, int64_t);
int main() {
- clist_ix list = clist_init;
+ clist_ix list = clist_ini;
crand_rng32_t pcg = crand_rng32_init(12345);
int n;
for (int i=0; i<1000000; ++i) // one million
@@ -82,7 +82,7 @@
clist_##tag##_node_t *item, *end, **_last; \
} clist_##tag##_iter_t
-#define clist_init {NULL}
+#define clist_ini {NULL}
#define clist_empty(list) ((list).last == NULL)
@@ -97,7 +97,7 @@ STC_API size_t _clist_size(const clist_void* self);
typedef clist_##tag##_rawvalue_t clist_##tag##_input_t; \
\
STC_INLINE clist_##tag \
- clist_##tag##_init(void) {clist_##tag x = clist_init; return x;} \
+ clist_##tag##_init(void) {clist_##tag x = clist_ini; return x;} \
STC_INLINE bool \
clist_##tag##_empty(clist_##tag ls) {return clist_empty(ls);} \
STC_INLINE size_t \
diff --git a/stc/cmap.h b/stc/cmap.h
index 615ab7cb..44f39174 100644
--- a/stc/cmap.h
+++ b/stc/cmap.h
@@ -28,13 +28,13 @@ declare_cset(sx, int); // Set of int
declare_cmap(mx, int, char); // Map of int -> char
int main(void) {
- cset_sx s = cset_init;
+ cset_sx s = cset_ini;
cset_sx_put(&s, 5);
cset_sx_put(&s, 8);
c_foreach (i, cset_sx, s) printf("set %d\n", i.item->key);
cset_sx_destroy(&s);
- cmap_mx m = cmap_init;
+ cmap_mx m = cmap_ini;
cmap_mx_put(&m, 5, 'a');
cmap_mx_put(&m, 8, 'b');
cmap_mx_put(&m, 12, 'c');
@@ -53,11 +53,11 @@ int main(void) {
#include <string.h>
#include "cdefs.h"
-#define cmap_init {NULL, NULL, 0, 0, 0.85f, 0.15f}
+#define cmap_ini {NULL, NULL, 0, 0, 0.85f, 0.15f}
#define cmap_empty(m) ((m).size == 0)
#define cmap_size(m) ((size_t) (m).size)
#define cmap_bucket_count(m) ((size_t) (m).bucket_count)
-#define cset_init cmap_init
+#define cset_ini cmap_ini
#define cset_size(s) cmap_size(s)
#define cset_bucket_count(s) cmap_bucket_count(s)
#define cmap_try_emplace(tag, self, k, v) do { \
@@ -181,7 +181,7 @@ typedef struct { \
} ctype##_##tag##_iter_t; \
\
STC_INLINE ctype##_##tag \
-ctype##_##tag##_init(void) {ctype##_##tag m = cmap_init; return m;} \
+ctype##_##tag##_init(void) {ctype##_##tag m = cmap_ini; return m;} \
STC_INLINE bool \
ctype##_##tag##_empty(ctype##_##tag m) {return m.size == 0;} \
STC_INLINE size_t \
@@ -265,7 +265,7 @@ implement_CHASH(tag, ctype, Key, Value, valueDestroy, keyEqualsRaw, keyHashRaw,
keyDestroy, RawKey, keyToRaw, keyFromRaw, RawValue, valueFromRaw) \
STC_API ctype##_##tag \
ctype##_##tag##_with_capacity(size_t cap) { \
- ctype##_##tag h = ctype##_init; \
+ ctype##_##tag h = ctype##_ini; \
ctype##_##tag##_reserve(&h, cap); \
return h; \
} \
diff --git a/stc/coption.h b/stc/coption.h
index e1c6e7cb..4b0712d6 100644
--- a/stc/coption.h
+++ b/stc/coption.h
@@ -43,7 +43,7 @@ Example:
const char* optstr = "xy:z::123";
printf("program -x -y ARG -z [ARG] -1 -2 -3 --foo --bar ARG --opt [ARG] [ARGUMENTS]\n");
int c;
- coption_t opt = coption_init;
+ coption_t opt = coption_ini;
while ((c = coption_get(&opt, argc, argv, optstr, longopts)) != -1) {
switch (c) {
case '?': printf("error: unknown option: %s\n", opt.faulty); break;
@@ -83,7 +83,7 @@ typedef struct {
int val;
} coption_long_t;
-static const coption_t coption_init = {1, 0, NULL, NULL, -1, 1, 0, 0, {'-', '?', '\0'}};
+static const coption_t coption_ini = {1, 0, NULL, NULL, -1, 1, 0, 0, {'-', '?', '\0'}};
static void _coption_permute(char *argv[], int j, int n) { /* move argv[j] over n elements to the left */
int k;
@@ -93,7 +93,7 @@ static void _coption_permute(char *argv[], int j, int n) { /* move argv[j] over
argv[j - k] = p;
}
-/* @param opt output; must be initialized to coption_init on first call
+/* @param opt output; must be initialized to coption_ini on first call
* @return ASCII val for a short option; longopt.val for a long option;
* -1 if argv[] is fully processed; '?' for an unknown option or
* an ambiguous long option; ':' if an option argument is missing
diff --git a/stc/cprique.h b/stc/cpqueue.h
index 92a1f8c2..8873b0cd 100644
--- a/stc/cprique.h
+++ b/stc/cpqueue.h
@@ -24,78 +24,78 @@
/* Priority Queue using heap, with adapter class (normally cvec).
#include <stc/crandom.h>
- #include <stc/cprique.h>
+ #include <stc/cpqueue.h>
declare_cvec(f, float);
- declare_cprique(f, cvec_f, >); // min-heap (increasing values)
+ declare_cpqueue(f, cvec_f, >); // min-heap (increasing values)
int main() {
crand_rng32_t gen = crand_rng32_init(1234);
crand_uniform_f32_t dist = crand_uniform_f32_init(10.0f, 100.0f);
- cprique_f queue = cprique_f_init();
+ cpqueue_f queue = cpqueue_f_init();
// Push ten million random numbers onto the queue.
for (int i=0; i<10000000; ++i)
- cprique_f_push(&queue, crand_uniform_f32(&gen, dist));
+ cpqueue_f_push(&queue, crand_uniform_f32(&gen, dist));
// Extract the 100 smallest.
for (int i=0; i<100; ++i) {
- printf("%f ", *cprique_f_top(queue));
- cprique_f_pop(&queue);
+ printf("%f ", *cpqueue_f_top(queue));
+ cpqueue_f_pop(&queue);
}
- cprique_f_destroy(&queue);
+ cpqueue_f_destroy(&queue);
}
*/
-#ifndef CPRIQUE__H__
-#define CPRIQUE__H__
+#ifndef CPQUEUE__H__
+#define CPQUEUE__H__
#include "cvec.h"
-#define declare_cprique(tag, ctype, cmpOpr) /* cmpOpr: < or > */ \
+#define declare_cpqueue(tag, ctype, cmpOpr) /* cmpOpr: < or > */ \
\
-typedef ctype cprique_##tag; \
-typedef ctype##_value_t cprique_##tag##_value_t; \
-typedef ctype##_rawvalue_t cprique_##tag##_rawvalue_t; \
-typedef ctype##_input_t cprique_##tag##_input_t; \
-STC_INLINE cprique_##tag \
-cprique_##tag##_init() {return ctype##_init();} \
+typedef struct ctype cpqueue_##tag; \
+typedef ctype##_value_t cpqueue_##tag##_value_t; \
+typedef ctype##_rawvalue_t cpqueue_##tag##_rawvalue_t; \
+typedef ctype##_input_t cpqueue_##tag##_input_t; \
+STC_INLINE cpqueue_##tag \
+cpqueue_##tag##_init() {return ctype##_init();} \
STC_INLINE size_t \
-cprique_##tag##_size(cprique_##tag pq) {return ctype##_size(pq);} \
+cpqueue_##tag##_size(cpqueue_##tag pq) {return ctype##_size(pq);} \
STC_INLINE bool \
-cprique_##tag##_empty(cprique_##tag pq) {return ctype##_empty(pq);} \
+cpqueue_##tag##_empty(cpqueue_##tag pq) {return ctype##_empty(pq);} \
STC_INLINE void \
-cprique_##tag##_destroy(cprique_##tag* self) {ctype##_destroy(self);} \
+cpqueue_##tag##_destroy(cpqueue_##tag* self) {ctype##_destroy(self);} \
STC_API void \
-cprique_##tag##_build(cprique_##tag* self); \
+cpqueue_##tag##_build(cpqueue_##tag* self); \
STC_API void \
-cprique_##tag##_erase(cprique_##tag* self, size_t i); \
-STC_INLINE const cprique_##tag##_value_t* \
-cprique_##tag##_top(const cprique_##tag* self) {return &self->data[0];} \
+cpqueue_##tag##_erase(cpqueue_##tag* self, size_t i); \
+STC_INLINE const cpqueue_##tag##_value_t* \
+cpqueue_##tag##_top(const cpqueue_##tag* self) {return &self->data[0];} \
STC_INLINE void \
-cprique_##tag##_pop(cprique_##tag* self) {cprique_##tag##_erase(self, 0);} \
+cpqueue_##tag##_pop(cpqueue_##tag* self) {cpqueue_##tag##_erase(self, 0);} \
STC_API void \
-cprique_##tag##_push_v(cprique_##tag* self, cprique_##tag##_value_t value); \
+cpqueue_##tag##_push_v(cpqueue_##tag* self, cpqueue_##tag##_value_t value); \
STC_INLINE void \
-cprique_##tag##_push(cprique_##tag* self, cprique_##tag##_rawvalue_t rawValue) { \
- cprique_##tag##_push_v(self, ctype##_value_from_raw(rawValue)); \
+cpqueue_##tag##_push(cpqueue_##tag* self, cpqueue_##tag##_rawvalue_t rawValue) { \
+ cpqueue_##tag##_push_v(self, ctype##_value_from_raw(rawValue)); \
} \
STC_API void \
-cprique_##tag##_push_n(cprique_##tag *self, const cprique_##tag##_input_t in[], size_t size); \
+cpqueue_##tag##_push_n(cpqueue_##tag *self, const cpqueue_##tag##_input_t in[], size_t size); \
\
-implement_cprique(tag, ctype, cmpOpr)
+implement_cpqueue(tag, ctype, cmpOpr)
/* -------------------------- IMPLEMENTATION ------------------------- */
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
-#define implement_cprique(tag, ctype, cmpOpr) \
+#define implement_cpqueue(tag, ctype, cmpOpr) \
\
STC_INLINE void \
-_cprique_##tag##_sift_down(cprique_##tag##_value_t* arr, size_t i, size_t n) { \
+_cpqueue_##tag##_sift_down(cpqueue_##tag##_value_t* arr, size_t i, size_t n) { \
size_t r = i, c = i << 1; \
while (c <= n) { \
if (c < n && ctype##_value_compare(&arr[c], &arr[c + 1]) cmpOpr 0) \
++c; \
if (ctype##_value_compare(&arr[r], &arr[c]) cmpOpr 0) { \
- cprique_##tag##_value_t t = arr[r]; arr[r] = arr[c]; arr[r = c] = t; \
+ cpqueue_##tag##_value_t t = arr[r]; arr[r] = arr[c]; arr[r = c] = t; \
} else \
return; \
c <<= 1; \
@@ -103,39 +103,39 @@ _cprique_##tag##_sift_down(cprique_##tag##_value_t* arr, size_t i, size_t n) { \
} \
\
STC_API void \
-cprique_##tag##_build(cprique_##tag* self) { \
- size_t n = cprique_##tag##_size(*self); \
- cprique_##tag##_value_t *arr = self->data - 1; \
+cpqueue_##tag##_build(cpqueue_##tag* self) { \
+ size_t n = cpqueue_##tag##_size(*self); \
+ cpqueue_##tag##_value_t *arr = self->data - 1; \
for (size_t k = n >> 1; k != 0; --k) \
- _cprique_##tag##_sift_down(arr, k, n); \
+ _cpqueue_##tag##_sift_down(arr, k, n); \
} \
\
STC_API void \
-cprique_##tag##_erase(cprique_##tag* self, size_t i) { \
- size_t n = cprique_##tag##_size(*self) - 1; \
+cpqueue_##tag##_erase(cpqueue_##tag* self, size_t i) { \
+ size_t n = cpqueue_##tag##_size(*self) - 1; \
self->data[i] = self->data[n]; \
ctype##_pop_back(self); \
- _cprique_##tag##_sift_down(self->data - 1, i + 1, n); \
+ _cpqueue_##tag##_sift_down(self->data - 1, i + 1, n); \
} \
\
STC_API void \
-cprique_##tag##_push_v(cprique_##tag* self, cprique_##tag##_value_t value) { \
+cpqueue_##tag##_push_v(cpqueue_##tag* self, cpqueue_##tag##_value_t value) { \
ctype##_push_back(self, value); /* sift-up the value */ \
- size_t n = cprique_##tag##_size(*self), c = n; \
- cprique_##tag##_value_t *arr = self->data - 1; \
+ size_t n = cpqueue_##tag##_size(*self), c = n; \
+ cpqueue_##tag##_value_t *arr = self->data - 1; \
for (; c > 1 && ctype##_value_compare(&arr[c >> 1], &value) cmpOpr 0; c >>= 1) \
arr[c] = arr[c >> 1]; \
if (c != n) arr[c] = value; \
} \
STC_API void \
-cprique_##tag##_push_n(cprique_##tag *self, const cprique_##tag##_input_t in[], size_t size) { \
- ctype##_reserve(self, cprique_##tag##_size(*self) + size); \
- for (size_t i=0; i<size; ++i) cprique_##tag##_push(self, in[i]); \
+cpqueue_##tag##_push_n(cpqueue_##tag *self, const cpqueue_##tag##_input_t in[], size_t size) { \
+ ctype##_reserve(self, cpqueue_##tag##_size(*self) + size); \
+ for (size_t i=0; i<size; ++i) cpqueue_##tag##_push(self, in[i]); \
} \
-typedef int cprique_##tag##_dud
+typedef int cpqueue_##tag##_dud
#else
-#define implement_cprique(tag, ctype, cmpOpr)
+#define implement_cpqueue(tag, ctype, cmpOpr)
#endif
#endif
diff --git a/stc/cqueue.h b/stc/cqueue.h
index 824f70dc..8f9dc698 100644
--- a/stc/cqueue.h
+++ b/stc/cqueue.h
@@ -60,7 +60,7 @@
#define declare_cqueue(tag, ctype) \
\
-typedef ctype cqueue_##tag; \
+typedef struct ctype cqueue_##tag; \
typedef ctype##_value_t cqueue_##tag##_value_t; \
typedef ctype##_rawvalue_t cqueue_##tag##_rawvalue_t; \
typedef ctype##_input_t cqueue_##tag##_input_t; \
@@ -86,11 +86,11 @@ STC_INLINE void \
cqueue_##tag##_push(cqueue_##tag* self, cqueue_##tag##_rawvalue_t rawValue) { \
ctype##_push_back(self, rawValue); \
} \
+ \
STC_API void \
cqueue_##tag##_push_n(cqueue_##tag *self, const cqueue_##tag##_input_t in[], size_t size) { \
ctype##_push_n(self, in, size); \
} \
- \
typedef ctype##_iter_t cqueue_##tag##_iter_t; \
STC_INLINE cqueue_##tag##_iter_t \
cqueue_##tag##_begin(cqueue_##tag* self) {return ctype##_begin(self);} \
diff --git a/stc/cstack.h b/stc/cstack.h
index d90eee4e..5da47719 100644
--- a/stc/cstack.h
+++ b/stc/cstack.h
@@ -49,7 +49,7 @@
#define declare_cstack(tag, ctype) \
\
-typedef ctype cstack_##tag; \
+typedef struct ctype cstack_##tag; \
typedef ctype##_value_t cstack_##tag##_value_t; \
typedef ctype##_rawvalue_t cstack_##tag##_rawvalue_t; \
typedef ctype##_input_t cstack_##tag##_input_t; \
@@ -73,11 +73,11 @@ STC_INLINE void \
cstack_##tag##_push(cstack_##tag* self, cstack_##tag##_rawvalue_t rawValue) { \
ctype##_push_back(self, rawValue); \
} \
+ \
STC_API void \
cstack_##tag##_push_n(cstack_##tag *self, const cstack_##tag##_input_t in[], size_t size) { \
ctype##_push_n(self, in, size); \
} \
- \
typedef ctype##_iter_t cstack_##tag##_iter_t; \
STC_INLINE cstack_##tag##_iter_t \
cstack_##tag##_begin(cstack_##tag* self) {return ctype##_begin(self);} \
diff --git a/stc/cstr.h b/stc/cstr.h
index f4d7bea3..c615b325 100644
--- a/stc/cstr.h
+++ b/stc/cstr.h
@@ -39,13 +39,13 @@ typedef char cstr_value_t, cstr_rawvalue_t, cstr_input_t;
static size_t _cstr_nullrep[] = {0, 0, 0};
-static cstr_t cstr_init = {(char* ) &_cstr_nullrep[2]};
+static cstr_t cstr_ini = {(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_empty(s) (cstr_size(s) == 0)
-#define cstr_front(s) (s).str[0]
-#define cstr_back(s) (s).str[_cstr_size(s) - 1] /* may have side effect */
#define cstr_npos ((size_t) (-1))
+#define cstr_push_n cstr_append_n
+#define cstr_push_back_v cstr_push_back
STC_API cstr_t
cstr_make_n(const char* str, size_t len);
@@ -73,6 +73,9 @@ c_strnstr(const char* s, const char* needle, size_t n);
/* gives true string capacity: 7, 23, 39, ... */
#define _cstr_cap(size) ((((size) + 24) >> 4) * 16 - 9)
+STC_INLINE cstr_t
+cstr_init() {return cstr_ini;}
+
STC_INLINE void
cstr_destroy(cstr_t* self) {
if (cstr_capacity(*self))
@@ -81,13 +84,13 @@ cstr_destroy(cstr_t* self) {
STC_INLINE cstr_t
cstr_with_capacity(size_t cap) {
- cstr_t s = cstr_init;
+ cstr_t s = cstr_ini;
cstr_reserve(&s, cap);
return s;
}
STC_INLINE cstr_t
cstr_with_size(size_t len, char fill) {
- cstr_t s = cstr_init;
+ cstr_t s = cstr_ini;
cstr_resize(&s, len, fill);
return s;
}
@@ -106,6 +109,11 @@ cstr_clear(cstr_t* self) {
self->str[_cstr_size(*self) = 0] = '\0';
}
+STC_INLINE char*
+cstr_front(cstr_t* self) {return self->str;}
+STC_INLINE char*
+cstr_back(cstr_t* self) {return self->str + _cstr_size(*self) - 1;}
+
STC_INLINE cstr_iter_t
cstr_begin(cstr_t* self) {
cstr_iter_t it = {self->str, self->str + cstr_size(*self)}; return it;
@@ -128,7 +136,7 @@ cstr_take(cstr_t* self, cstr_t s) {
STC_INLINE cstr_t
cstr_move(cstr_t* self) {
cstr_t tmp = *self;
- *self = cstr_init;
+ *self = cstr_ini;
return tmp;
}
@@ -136,14 +144,11 @@ STC_INLINE cstr_t*
cstr_append(cstr_t* self, const char* str) {
return cstr_append_n(self, str, strlen(str));
}
-/*STC_INLINE void
-cstr_push_n(cstr_t* self, const cstr_input_t[] in, size_t n) {
- cstr_append_n(self, in, n);
-}*/
STC_INLINE cstr_t*
cstr_push_back(cstr_t* self, char value) {
return cstr_append_n(self, &value, 1);
}
+
STC_INLINE void
cstr_pop_back(cstr_t* self) {
self->str[ --_cstr_size(*self) ] = '\0';
@@ -228,7 +233,7 @@ cstr_resize(cstr_t* self, size_t len, char fill) {
STC_API cstr_t
cstr_make_n(const char* str, size_t len) {
- if (len == 0) return cstr_init;
+ if (len == 0) return cstr_ini;
size_t *rep = (size_t *) malloc(_cstr_mem(len));
cstr_t s = {(char *) memcpy(rep + 2, str, len)};
s.str[rep[0] = len] = '\0';
@@ -245,7 +250,7 @@ cstr_from(const char* fmt, ...) {
# pragma warning(push)
# pragma warning(disable: 4996)
#endif
- cstr_t tmp = cstr_init;
+ cstr_t tmp = cstr_ini;
va_list args, args2;
va_start(args, fmt);
va_copy(args2, args);
diff --git a/stc/cvec.h b/stc/cvec.h
index 7a753b70..0e72b142 100644
--- a/stc/cvec.h
+++ b/stc/cvec.h
@@ -27,7 +27,7 @@
#include <string.h>
#include "cdefs.h"
-#define cvec_init {NULL}
+#define cvec_ini {NULL}
#define cvec_size(v) _cvec_safe_size((v).data)
#define cvec_capacity(v) _cvec_safe_capacity((v).data)
#define cvec_empty(v) (_cvec_safe_size((v).data) == 0)
@@ -55,7 +55,7 @@ typedef RawValue cvec_##tag##_rawvalue_t; \
typedef cvec_##tag##_rawvalue_t cvec_##tag##_input_t; \
\
STC_INLINE cvec_##tag \
-cvec_##tag##_init(void) {cvec_##tag v = cvec_init; return v;} \
+cvec_##tag##_init(void) {cvec_##tag v = cvec_ini; return v;} \
STC_INLINE bool \
cvec_##tag##_empty(cvec_##tag v) {return cvec_empty(v);} \
STC_INLINE size_t \
@@ -97,13 +97,13 @@ cvec_##tag##_value_compare(const Value* x, const Value* y); \
\
STC_INLINE cvec_##tag \
cvec_##tag##_with_size(size_t size, Value null_val) { \
- cvec_##tag x = cvec_init; \
+ cvec_##tag x = cvec_ini; \
cvec_##tag##_resize(&x, size, null_val); \
return x; \
} \
STC_INLINE cvec_##tag \
cvec_##tag##_with_capacity(size_t size) { \
- cvec_##tag x = cvec_init; \
+ cvec_##tag x = cvec_ini; \
cvec_##tag##_reserve(&x, size); \
return x; \
} \