summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-07-27 17:59:41 +0200
committerTyge Løvset <[email protected]>2020-07-27 18:02:19 +0200
commit68b24637318464a949a9008d7f42ba55c2fda221 (patch)
tree164841568173d25aec1194dd3163723d0ce044b0 /examples
parentbdd322f4c7d30a3cba1aa0c6ff3106b2045fb879 (diff)
downloadSTC-modified-68b24637318464a949a9008d7f42ba55c2fda221.tar.gz
STC-modified-68b24637318464a949a9008d7f42ba55c2fda221.zip
API CHANGES: Made types all lower case. E.g.: CMap_<tag> => cmap_<tag>, CList_<tag> => clist_<tag>. Note: CStr => cstr_t, CBitset => cbitset_t
Diffstat (limited to 'examples')
-rw-r--r--examples/README.md14
-rw-r--r--examples/advanced.c16
-rw-r--r--examples/benchmark.c4
-rw-r--r--examples/bits.c4
-rw-r--r--examples/complex.c18
-rw-r--r--examples/demos.c38
-rw-r--r--examples/geek1.c6
-rw-r--r--examples/geek2.c12
-rw-r--r--examples/geek3.c8
-rw-r--r--examples/geek4.c20
-rw-r--r--examples/geek5.c14
-rw-r--r--examples/geek6.c4
-rw-r--r--examples/geek7.c12
-rw-r--r--examples/heap.c6
-rw-r--r--examples/inits.c16
-rw-r--r--examples/list.c4
-rw-r--r--examples/mapmap.c8
-rw-r--r--examples/prime.c2
-rw-r--r--examples/priority.c6
-rw-r--r--examples/rngbirthday.c10
20 files changed, 111 insertions, 111 deletions
diff --git a/examples/README.md b/examples/README.md
index 4d43a7d2..e222f8bc 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -6,7 +6,7 @@ Contains various examples and benchmarks.
advanced.c Example
------------------
-This demonstrates how to customize hash **CMap** with a user-defined key-type. You need to define two things:
+This demonstrates how to customize hash **cmap** with a user-defined key-type. You need to define two things:
1. A hash function; calculates the hash value given an object of the key-type.
@@ -40,8 +40,8 @@ int vikingvw_equals(const VikingVw* x, const VikingVw* y) {
And the Viking data struct:
```
typedef struct Viking {
- CStr name;
- CStr country;
+ cstr_t name;
+ cstr_t country;
} Viking;
@@ -58,9 +58,9 @@ Viking viking_fromVw(VikingVw vw) {
}
```
-With this in place, we use the full declare_CMap() macro to define {Viking -> int} hash map type:
+With this in place, we use the full 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_defaultDestroy, 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.
@@ -68,13 +68,13 @@ Finally, the demo:
```
int main()
{
- CMap_vk vikings = cmap_init;
+ cmap_vk vikings = cmap_init;
// emplace constructs the keys
cmap_vk_put(&vikings, (VikingVw) {"Einar", "Norway"}, 20);
cmap_vk_put(&vikings, (VikingVw) {"Olaf", "Denmark"}, 24);
cmap_vk_put(&vikings, (VikingVw) {"Harald", "Iceland"}, 12);
- CMapEntry_vk* e = cmap_vk_get(&vikings, (VikingVw) {"Einar", "Norway"});
+ cmapentry_vk* e = cmap_vk_get(&vikings, (VikingVw) {"Einar", "Norway"});
e->value += 5; // update
c_foreach (k, cmap_vk, vikings) {
diff --git a/examples/advanced.c b/examples/advanced.c
index 68ddc9ef..b5481f94 100644
--- a/examples/advanced.c
+++ b/examples/advanced.c
@@ -1,5 +1,5 @@
/*
- * To be able to use CMap with a user-defined key-type, you need to define two things:
+ * To be able to use cmap with a user-defined key-type, you need to define two things:
* 1. A hash function; this must be a function that calculates the hash value given
* an object of the key-type.
* 2. A comparison function for equality.
@@ -34,8 +34,8 @@ int vikingvw_equals(const VikingVw* x, const VikingVw* y) {
// Viking data struct -----------------------
typedef struct Viking {
- CStr name;
- CStr country;
+ cstr_t name;
+ cstr_t country;
} Viking;
@@ -52,25 +52,25 @@ 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,
+// Using the full declare_cmap() macro to define [Viking -> int] hash map type:
+declare_cmap(vk, Viking, int, c_defaultDestroy, 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 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.
// Main ----------------------------
int main()
{
- CMap_vk vikings = cmap_init;
+ cmap_vk vikings = cmap_init;
c_push(&vikings, cmap_vk, c_items(
{{"Einar", "Norway"}, 20},
{{"Olaf", "Denmark"}, 24},
{{"Harald", "Iceland"}, 12},
));
- CMapEntry_vk* e = cmap_vk_find(&vikings, (VikingVw) {"Einar", "Norway"});
+ cmapentry_vk* e = cmap_vk_find(&vikings, (VikingVw) {"Einar", "Norway"});
e->value += 5; // update
c_foreach (k, cmap_vk, vikings) {
diff --git a/examples/benchmark.c b/examples/benchmark.c
index c9a82d6d..8b9f33c2 100644
--- a/examples/benchmark.c
+++ b/examples/benchmark.c
@@ -14,7 +14,7 @@
// 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_defaultDestroy, c_defaultEquals, c_fibonacciHash64);
KHASH_MAP_INIT_INT64(ii, uint64_t)
@@ -26,7 +26,7 @@ crandom64_t rng;
#define RAND(N) (crandom64(&rng) & ((1 << N) - 1))
-#define CMAP_SETUP(tag, Key, Value) CMap_##tag map = cmap_init \
+#define CMAP_SETUP(tag, Key, Value) cmap_##tag map = cmap_init \
; cmap_##tag##_setLoadFactors(&map, maxLoadFactor, 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)
diff --git a/examples/bits.c b/examples/bits.c
index 16adaf96..7c048c80 100644
--- a/examples/bits.c
+++ b/examples/bits.c
@@ -2,7 +2,7 @@
#include <stc/cbitset.h>
int main() {
- CBitset set = cbitset_make(23, true);
+ cbitset_t set = cbitset_make(23, true);
printf("count %zu, %zu\n", cbitset_count(set), set.size);
cbitset_reset(&set, 9);
cbitset_resize(&set, 43, false);
@@ -21,7 +21,7 @@ int main() {
printf("%d", cbitset_test(set, i));
puts("");
- CBitset s2 = cbitset_from(set);
+ cbitset_t s2 = cbitset_from(set);
cbitset_flipAll(&s2);
cbitset_set(&s2, 16);
cbitset_set(&s2, 17);
diff --git a/examples/complex.c b/examples/complex.c
index 40dc9722..87caaa4e 100644
--- a/examples/complex.c
+++ b/examples/complex.c
@@ -5,22 +5,22 @@
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_CMap(il, int, CList_t2, clist_t2_destroy);
-declare_CMap_str(sm, CMap_il, cmap_il_destroy);
+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_cmap(il, int, clist_t2, clist_t2_destroy);
+declare_cmap_str(sm, cmap_il, cmap_il_destroy);
int main() {
int xdim = 4, ydim = 6;
int x = 1, y = 5, tableKey = 42;
const char* strKey = "first";
- CMap_sm theMap = cmap_init;
+ cmap_sm theMap = cmap_init;
{ // Construct.
- CArray2f table = carray2f_make(ydim, xdim, 0.f);
+ carray2f table = carray2f_make(ydim, xdim, 0.f);
printf("table: (%zu, %zu)\n", carray2_ydim(table), carray2_xdim(table));
- CList_t2 tableList = clist_init;
- CMap_il listMap = cmap_init;
+ clist_t2 tableList = clist_init;
+ cmap_il listMap = cmap_init;
// Put in some data.
carray2f_data(table, y)[x] = 3.1415927; // table[y][x]
@@ -29,7 +29,7 @@ int main() {
cmap_sm_put(&theMap, strKey, listMap);
}
{ // Access the data entry
- CArray2f table = clist_back(cmap_il_find(&cmap_sm_find(&theMap, strKey)->value, tableKey)->value);
+ carray2f table = clist_back(cmap_il_find(&cmap_sm_find(&theMap, strKey)->value, tableKey)->value);
printf("value (%d, %d) is: %f\n", y, x, carray2f_value(table, y, x));
}
diff --git a/examples/demos.c b/examples/demos.c
index 03d8a21d..3a29f7d6 100644
--- a/examples/demos.c
+++ b/examples/demos.c
@@ -8,7 +8,7 @@
void stringdemo1()
{
printf("\nSTRINGDEMO1\n");
- CStr cs = cstr_make("one-nine-three-seven-five");
+ cstr_t cs = cstr_make("one-nine-three-seven-five");
printf("%s.\n", cs.str);
cstr_insert(&cs, 3, "-two");
@@ -33,12 +33,12 @@ void stringdemo1()
}
-declare_CVec(ix, int64_t); // ix is just an example tag name.
+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_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);
@@ -54,12 +54,12 @@ void vectordemo1()
-declare_CVec(cs, CStr, cstr_destroy, cstr_compare); // supply inline destructor of values
+declare_cvec(cs, cstr_t, cstr_destroy, cstr_compare); // supply inline destructor of values
void vectordemo2()
{
printf("\nVECTORDEMO2\n");
- CVec_cs names = cvec_init;
+ 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"));
@@ -72,12 +72,12 @@ void vectordemo2()
cvec_cs_destroy(&names);
}
-declare_CList(ix, int);
+declare_clist(ix, int);
void listdemo1()
{
printf("\nLISTDEMO1\n");
- CList_ix nums = clist_init, nums2 = clist_init;
+ clist_ix nums = clist_init, nums2 = clist_init;
for (int i = 0; i < 10; ++i)
clist_ix_pushBack(&nums, i);
for (int i = 100; i < 110; ++i)
@@ -99,12 +99,12 @@ void listdemo1()
clist_ix_destroy(&nums);
}
-declare_CSet(i, int);
+declare_cset(i, int);
void setdemo1()
{
printf("\nSETDEMO1\n");
- CSet_i nums = cset_init;
+ cset_i nums = cset_init;
cset_i_put(&nums, 8);
cset_i_put(&nums, 11);
@@ -114,12 +114,12 @@ void setdemo1()
}
-declare_CMap(ii, int, int);
+declare_cmap(ii, int, int);
void mapdemo1()
{
printf("\nMAPDEMO1\n");
- CMap_ii nums = cmap_init;
+ cmap_ii nums = cmap_init;
cmap_ii_put(&nums, 8, 64);
cmap_ii_put(&nums, 11, 121);
@@ -128,12 +128,12 @@ void mapdemo1()
}
-declare_CMap_str(si, int); // Shorthand macro for the general declare_CMap expansion.
+declare_cmap_str(si, int); // Shorthand macro for the general declare_cmap expansion.
void mapdemo2()
{
printf("\nMAPDEMO2\n");
- CMap_si nums = cmap_init;
+ cmap_si nums = cmap_init;
cmap_si_put(&nums, "Hello", 64);
cmap_si_put(&nums, "Groovy", 121);
cmap_si_put(&nums, "Groovy", 200); // overwrite previous
@@ -150,16 +150,16 @@ void mapdemo2()
}
-declare_CMap_str(ss, CStr, cstr_destroy);
+declare_cmap_str(ss, cstr_t, cstr_destroy);
void mapdemo3()
{
printf("\nMAPDEMO3\n");
- CMap_ss table = cmap_init;
+ cmap_ss table = cmap_init;
cmap_ss_put(&table, "Map", cstr_make("test"));
cmap_ss_put(&table, "Make", cstr_make("my"));
cmap_ss_put(&table, "Sunny", cstr_make("day"));
- CMapEntry_ss *e = cmap_ss_find(&table, "Make");
+ cmapentry_ss *e = cmap_ss_find(&table, "Make");
c_foreach (i, cmap_ss, table)
printf("entry: %s: %s\n", i.item->key.str, i.item->value.str);
printf("size %zu: remove: Make: %s\n", cmap_size(table), e->value.str);
@@ -173,14 +173,14 @@ void mapdemo3()
}
-declare_CArray(f, float);
+declare_carray(f, float);
void arraydemo1()
{
printf("\nARRAYDEMO1\n");
- CArray3f a3 = carray3f_make(30, 20, 10, 0.f);
+ carray3f a3 = carray3f_make(30, 20, 10, 0.f);
carray3f_data(a3, 5, 4)[3] = 10.2f; // a3[5][4][3]
- CArray2f a2 = carray3f_at(a3, 5); // sub-array reference (no data copy).
+ carray2f a2 = carray3f_at(a3, 5); // sub-array reference (no data copy).
printf("a3: %zu: (%zu, %zu, %zu) = %zu\n", sizeof(a3), carray3_xdim(a3), carray3_ydim(a3), carray3_zdim(a3), carray3_size(a3));
printf("a2: %zu: (%zu, %zu) = %zu\n", sizeof(a2), carray2_xdim(a2), carray2_ydim(a2), carray2_size(a2));
diff --git a/examples/geek1.c b/examples/geek1.c
index f8471122..1df74024 100644
--- a/examples/geek1.c
+++ b/examples/geek1.c
@@ -12,14 +12,14 @@ int a[] = { 1, 2, 2, 3, 2, 4, 10 };
#include <stdio.h>
#include <stc/cmap.h>
-declare_CMap(ii, int, int);
+declare_cmap(ii, int, int);
// Function to maximize the number of pairs
int findMaximumPairs(int a[], int n, int k)
{
// Hash-table
- CMap_ii hash = cmap_init;
+ cmap_ii hash = cmap_init;
for (int i = 0; i < n; i++) {
cmap_ii_insert(&hash, a[i] % k, 0)->value++;
}
@@ -38,7 +38,7 @@ int findMaximumPairs(int a[], int n, int k)
int first = it.item->key;
int second = k - it.item->key;
- CMapEntry_ii *hf = cmap_ii_find(&hash, first),
+ cmapentry_ii *hf = cmap_ii_find(&hash, first),
*hs = cmap_ii_insert(&hash, second, 0);
// Check for minimal occurrence
if (hf->value < hs->value) {
diff --git a/examples/geek2.c b/examples/geek2.c
index 1c2f0c05..988f1f98 100644
--- a/examples/geek2.c
+++ b/examples/geek2.c
@@ -3,15 +3,15 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-declare_CMap_str(ss, CStr, cstr_destroy);
-declare_CSet_str();
+declare_cmap_str(ss, cstr_t, cstr_destroy);
+declare_cset_str();
int main()
{
// Lets use an explicit type signature (which would
- // be `CMap<String, String>` in this example).
- CMap_ss book_reviews = cmap_init;
- CSet_str set = cset_init;
+ // be `cmap<String, String>` in this example).
+ cmap_ss book_reviews = cmap_init;
+ cset_str set = cset_init;
cset_str_put(&set, "Hello");
cset_str_put(&set, "You");
cset_str_put(&set, "Tube");
@@ -50,7 +50,7 @@ int main()
// Look up the values associated with some keys.
const char* to_find[] = {"Pride and Prejudice", "Alice's Adventure in Wonderland", NULL};
for (const char** book = to_find; *book; ++book) {
- CMapEntry_ss* review = cmap_ss_find(&book_reviews, *book);
+ cmapentry_ss* review = cmap_ss_find(&book_reviews, *book);
if (review) printf("%s: %s\n", *book, review->value.str);
else printf("%s is unreviewed.\n", *book);
}
diff --git a/examples/geek3.c b/examples/geek3.c
index f6f8942a..b8de97c8 100644
--- a/examples/geek3.c
+++ b/examples/geek3.c
@@ -3,12 +3,12 @@
#include <stc/cmap.h>
#include <stc/cstr.h>
-declare_CMap_str(si, int);
-declare_CMap_str(ss, CStr, cstr_destroy);
+declare_cmap_str(si, int);
+declare_cmap_str(ss, cstr_t, cstr_destroy);
int main ()
{
- CMap_si mymap = cmap_init;
+ cmap_si mymap = cmap_init;
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_init;
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 e7522bb3..87f9b919 100644
--- a/examples/geek4.c
+++ b/examples/geek4.c
@@ -37,19 +37,19 @@ Efficient Approach: For all the words of the first sentence, we can check if it
#include <stc/cvec.h>
#include <stc/cstr.h>
-declare_CVec_str();
-declare_CMap_str(sb, bool);
-declare_CVec(sb, CMapEntry_sb, cmapentry_sb_destroy, c_noCompare);
+declare_cvec_str();
+declare_cmap_str(sb, bool);
+declare_cvec(sb, cmapentry_sb, cmapentry_sb_destroy, c_noCompare);
// Function to return the count of common words
// in all the sentences
-int commonWords(CVec_str S)
+int commonWords(cvec_str S)
{
int m, n, i, j;
// To store all the words of first string
- CVec_sb ans = cvec_init;
+ cvec_sb ans = cvec_init;
// 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 word = cstr_init;
- CMapEntry_sb tmp = {cstr_init, false};
+ cstr_t 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]);
@@ -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_init;
i = 0;
while (i < cstr_size(S.data[j])) {
- CStr word = cstr_init;
+ cstr_t word = cstr_init;
while (i < cstr_size(S.data[j]) && S.data[j].str[i] != ' ') {
cstr_pushBack(&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_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"));
diff --git a/examples/geek5.c b/examples/geek5.c
index 546cb278..b1e2f2b9 100644
--- a/examples/geek5.c
+++ b/examples/geek5.c
@@ -21,24 +21,24 @@ Output: 0
#include <stc/cvec.h>
#include <stc/cstr.h>
-declare_CVec(i, int);
-declare_CMap_str(sv, CVec_i, cvec_i_destroy);
+declare_cvec(i, int);
+declare_cmap_str(sv, cvec_i, cvec_i_destroy);
// Function to return the number of occurrences of
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_init;
for (int i = 0; i < n; i++) {
const char* temp = arr[i];
- CMapEntry_sv* it = cmap_sv_find(&M, temp);
+ cmapentry_sv* it = cmap_sv_find(&M, temp);
// If current string doesn't
// have an entry in the map
// then create the entry
if (it == NULL) {
- CVec_i A = cvec_init;
+ cvec_i A = cvec_init;
cvec_i_pushBack(&A, i + 1);
cmap_sv_put(&M, temp, A);
}
@@ -47,7 +47,7 @@ int NumOccurrences(const char* arr[], int n, const char* str, int L, int R)
}
}
- CMapEntry_sv* it = cmap_sv_find(&M, str);
+ cmapentry_sv* it = cmap_sv_find(&M, str);
// If the given string is not
// present in the array
@@ -56,7 +56,7 @@ int NumOccurrences(const char* arr[], int n, const char* str, int L, int R)
// If the given string is present
// in the array
- CVec_i A = it->value;
+ cvec_i A = it->value;
int y = 0, x = 0;
for (; y < cvec_size(A); ++y) if (A.data[y] > R) break;
for (; x < cvec_size(A); ++x) if (A.data[x] > L - 1) break;
diff --git a/examples/geek6.c b/examples/geek6.c
index 6b70dd5e..4689d934 100644
--- a/examples/geek6.c
+++ b/examples/geek6.c
@@ -30,14 +30,14 @@ operation in almost O(1) time complexity.
#include <stdio.h>
#include <stc/cmap.h>
-declare_CSet(i, int);
+declare_cset(i, int);
// Function to find the smallest positive
// missing number
int missingNumber(int a[], int n)
{
// Declaring an unordered_map
- CSet_i mp = cset_init;
+ cset_i mp = cset_init;
// if array value is positive
// store it in map
diff --git a/examples/geek7.c b/examples/geek7.c
index e304718d..88cfa33c 100644
--- a/examples/geek7.c
+++ b/examples/geek7.c
@@ -26,9 +26,9 @@ After inserting all the elements excluding the ones which are to be deleted, Pop
#include <stc/cmap.h>
#include <stc/cvecpq.h>
-declare_CMap(ii, int, int);
-declare_CVec(i, int);
-declare_CVec_priority_queue(i, >);
+declare_cmap(ii, int, int);
+declare_cvec(i, int);
+declare_cvec_priority_queue(i, >);
// Find k minimum element from arr[0..m-1] after deleting
// elements from del[0..n-1]
@@ -36,19 +36,19 @@ 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_init;
for (int i = 0; i < n; ++i) {
// Increment the count of del[i]
cmap_ii_insert(&mp, del[i], 0)->value++;
}
- CVec_i heap = cvec_init;
+ cvec_i heap = cvec_init;
for (int i = 0; i < m; ++i) {
// Search if the element is present
- CMapEntry_ii *e = cmap_ii_find(&mp, arr[i]);
+ cmapentry_ii *e = cmap_ii_find(&mp, arr[i]);
if (e != NULL) {
// Decrement its frequency
diff --git a/examples/heap.c b/examples/heap.c
index e4e91544..94409371 100644
--- a/examples/heap.c
+++ b/examples/heap.c
@@ -3,15 +3,15 @@
#include "stc/cvecpq.h"
#include "stc/crandom.h"
-declare_CVec(f, float);
-declare_CVec_priority_queue(f, >);
+declare_cvec(f, float);
+declare_cvec_priority_queue(f, >);
int main()
{
uint32_t seed = time(NULL);
crandom32_t pcg = crandom32_init(seed);
int N = 30000000, M = 100;
- CVec_f vec = cvec_init;
+ cvec_f vec = cvec_init;
clock_t start = clock();
for (int i=0; i<N; ++i)
cvec_f_pushBack(&vec, crandom32(&pcg));
diff --git a/examples/inits.c b/examples/inits.c
index 240ce5c9..5f8563c7 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -4,17 +4,17 @@
#include <stc/cvec.h>
#include <stc/clist.h>
-declare_CMap(id, int, CStr, cstr_destroy); // Map of int -> CStr
-declare_CMap_str(cnt, int);
+declare_cmap(id, int, cstr_t, cstr_destroy); // Map of int -> cstr_t
+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_defaultDestroy, c_memCompare);
+declare_clist(ip, ipair_t, c_defaultDestroy, c_memCompare);
int main(void) {
int year = 2020;
- CMap_id idnames = cmap_init;
+ cmap_id idnames = cmap_init;
c_push(&idnames, cmap_id, c_items(
{100, cstr_make("Hello")},
{110, cstr_make("World")},
@@ -27,7 +27,7 @@ int main(void) {
// ------------------
- CMap_cnt countries = cmap_init;
+ cmap_cnt countries = cmap_init;
cmap_cnt_insert(&countries, "Greenland", 0)->value += 20;
c_push(&countries, cmap_cnt, c_items(
@@ -46,7 +46,7 @@ int main(void) {
// ------------------
- CVec_ip pairs1 = cvec_init;
+ cvec_ip pairs1 = cvec_init;
c_push(&pairs1, cvec_ip, c_items(
{1, 2},
{3, 4},
@@ -61,7 +61,7 @@ int main(void) {
// ------------------
- CList_ip pairs2 = clist_init;
+ clist_ip pairs2 = clist_init;
c_push(&pairs2, clist_ip, c_items(
{1, 2},
{3, 4},
diff --git a/examples/list.c b/examples/list.c
index 53b8711f..2eb1f4c0 100644
--- a/examples/list.c
+++ b/examples/list.c
@@ -2,10 +2,10 @@
#include <time.h>
#include <stc/clist.h>
#include <stc/crandom.h>
-declare_CList(ix, uint64_t);
+declare_clist(ix, uint64_t);
int main() {
- CList_ix list = clist_init;
+ clist_ix list = clist_init;
crandom32_t pcg = crandom32_init(time(NULL));
int n;
for (int i=0; i<10000000; ++i) // ten million
diff --git a/examples/mapmap.c b/examples/mapmap.c
index 67672dee..b349e8d3 100644
--- a/examples/mapmap.c
+++ b/examples/mapmap.c
@@ -6,12 +6,12 @@ static void test_destr(int* x) {
printf("destroy int: %d\n", *x);
}
-declare_CMap(ii, int, int, test_destr);
-declare_CMap(im, int, CMap_ii, cmap_ii_destroy);
+declare_cmap(ii, int, int, test_destr);
+declare_cmap(im, int, cmap_ii, cmap_ii_destroy);
int main(void) {
- CMap_im m = cmap_init;
- CMap_ii ini = cmap_init;
+ cmap_im m = cmap_init;
+ cmap_ii ini = cmap_init;
cmap_ii_put(&cmap_im_insert(&m, 100, ini)->value, 2000, 200);
cmap_ii_put(&cmap_im_insert(&m, 100, ini)->value, 2001, 201);
cmap_ii_put(&cmap_im_insert(&m, 100, ini)->value, 2000, 400); // update
diff --git a/examples/prime.c b/examples/prime.c
index 05ef4d57..611690ac 100644
--- a/examples/prime.c
+++ b/examples/prime.c
@@ -10,7 +10,7 @@
static inline void sieveOfEratosthenes(size_t n)
{
- CBitset prime = cbitset_make(n + 1, true);
+ cbitset_t 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/examples/priority.c b/examples/priority.c
index c1890f8c..37e7be60 100644
--- a/examples/priority.c
+++ b/examples/priority.c
@@ -5,12 +5,12 @@
#include <stc/cmap.h>
#include <stc/crandom.h>
-declare_CVec(i, uint32_t);
-declare_CVec_priority_queue(i, >); // min-heap (increasing values)
+declare_cvec(i, uint32_t);
+declare_cvec_priority_queue(i, >); // min-heap (increasing values)
int main() {
crandom32_t pcg = crandom32_init(time(NULL));
- CVec_i heap = cvec_init;
+ cvec_i heap = cvec_init;
// Push ten million random numbers to queue
for (int i=0; i<10000000; ++i)
diff --git a/examples/rngbirthday.c b/examples/rngbirthday.c
index 1e6178aa..5e77fe43 100644
--- a/examples/rngbirthday.c
+++ b/examples/rngbirthday.c
@@ -7,7 +7,7 @@
#include <stc/cvec.h>
#include <stc/cstr.h>
-declare_CMap(ic, uint64_t, uint8_t);
+declare_cmap(ic, uint64_t, uint8_t);
const static uint64_t seed = 1234;
const static uint64_t N = 1ull << 27;
@@ -16,7 +16,7 @@ const static uint64_t mask = (1ull << 52) - 1;
void repeats(void)
{
crandom64_t rng = crandom64_init(seed);
- CMap_ic m = cmap_init;
+ cmap_ic m = cmap_init;
cmap_ic_reserve(&m, N);
clock_t now = clock();
for (size_t i = 0; i < N; ++i) {
@@ -29,14 +29,14 @@ void repeats(void)
}
-declare_CMap(x, uint32_t, uint64_t);
-declare_CVec(x, uint64_t);
+declare_cmap(x, uint32_t, uint64_t);
+declare_cvec(x, uint64_t);
void distribution(void)
{
crandom32_t rng = crandom32_init(seed); // time(NULL), time(NULL));
const size_t N = 1ull << 28, M = 1ull << 9; // 1ull << 10;
- CMap_x map = cmap_x_make(M);
+ cmap_x map = cmap_x_make(M);
clock_t now = clock();
for (size_t i = 0; i < N; ++i) {
++cmap_x_insert(&map, crandom32b(&rng, M), 0)->value;