From b8d9fbae8c4960b30f5114f864e65aa0b4d6c5b5 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Fri, 17 Jul 2020 12:04:39 +0200 Subject: Fixed README's. --- README.md | 46 +++++++++++++++++++++++----------------------- examples/README.md | 8 ++++---- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index d874f45b..6a895dd7 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ The usage of the containers is similar to the C++ standard containers, so it sho All containers mentioned above, except for CStr are generic (similar to templates in C++). A simple example: ``` -#include +#include declare_CVec(i, int); int main(void) { @@ -46,8 +46,8 @@ Installation Because it is headers only, files can simply be included in your program. The functions will be inlined by default. If containers are extensively used accross many tranlation units with common instantiated container types, it is recommended to build as a library, to minimize executable size. To enable this mode, specify **-DSTC_HEADER** as compiler argument, and put all the instantiations of the containers used in one C file, e.g. ``` #define STC_IMPLEMENTATION -#include -#include +#include +#include declare_CMap(ii, int, int); // map declare_CMap(ix, int64_t); // set @@ -57,9 +57,9 @@ declare_CVec(i, int); Performance ----------- -This library is very efficent. Containers have templated intrusive elements. One of the most performance critical containers is the **CMap map / CMap set**. Thankfully, CMap is among the fastest C/C++ map implementations available: **examples/benchmark.c** compiled with g++ v9.2.0 -O3 on windows (the results are similar with VC++ and g++ on linux): +This library is very efficent. Containers have templated intrusive elements. One of the most performance critical containers is the **CMap / CSet**. Luckily, CMap is among the fastest C/C++ map implementations available: **examples/benchmark.c** compiled with g++ v9.2.0 -O3 on windows (the results are similar with VC++ and g++ on linux): -**CMAP**=*CMap map*, KMAP=*khash*, UMAP=*std::unordered_map*, BMAP=*ska::bytell_hash_map*, FMAP=*ska::flat_hash_map*, RMAP=*robin_hood::unordered_map* +**CMAP**=*CMap*, KMAP=*khash*, UMAP=*std::unordered_map*, BMAP=*ska::bytell_hash_map*, FMAP=*ska::flat_hash_map*, RMAP=*robin_hood::unordered_map* ``` Random keys are in range [0, 2^20): map: 7000000 repeats of Insert random key + (try to) remove a different random key: @@ -134,14 +134,14 @@ The first example has a very complex nested container type, which demonstrates t 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/cstring.h" -#include "stc/chash.h" -#include "stc/clist.h" -#include "stc/carray.h" +#include +#include +#include +#include -void check_destroy(float* v) {printf("destroy %g\n", *v);} +void verify_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_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_CMap(il, int, CList_t2, clist_t2_destroy); declare_CMap_str(sm, CMap_il, cmap_il_destroy); @@ -172,7 +172,7 @@ int main() { ``` **CStr** ``` -#include "stc/cstring.h" +#include int main() { CStr s1 = cstr_make("one-nine-three-seven-five"); @@ -200,7 +200,7 @@ int main() { ``` **CVec** of *int64_t* ``` -#include "stc/cvector.h" +#include declare_CVec(ix, int64_t); // ix is just an example tag name, use anything without underscore. int main() { @@ -218,8 +218,8 @@ int main() { ``` **CVec** of *CStr* ``` -#include "stc/cstring.h" -#include "stc/cvector.h" +#include +#include declare_CVec_str(cs); int main() { @@ -235,7 +235,7 @@ int main() { **CMap** of *int -> int* ``` #include -#include "stc/chash.h" +#include declare_CMap(ii, int, int); int main() { @@ -249,8 +249,8 @@ int main() { ``` **CSet** of *CStr* ``` -#include "stc/cstring.h" -#include "stc/chash.h" +#include +#include declare_CSet_str(s); // CStr set. See the discussion above. int main() { @@ -267,8 +267,8 @@ int main() { ``` **CMap** of *CStr -> CStr*. Temporary CStr values are created by *cstr_make()*, and moved into the container ``` -#include "stc/cstring.h" -#include "stc/chash.h" +#include +#include declare_CMap_str(ss, CStr, cstr_destroy); int main() { @@ -286,8 +286,8 @@ int main() { ``` #include #include -#include "stc/clist.h" -#include "stc/crandom.h" +#include +#include declare_CList(i, uint64_t); int main() { @@ -312,7 +312,7 @@ int main() { **CArray**. 1D, 2D and 3D arrays, heap allocated in one memory block. *CArray3* can have sub-array "views" of *CArray2* and *CArray1* etc., as shown in the following example. ``` #include -#include "stc/carray.h" +#include declare_CArray(f, float); int main() diff --git a/examples/README.md b/examples/README.md index cd6ac4ff..e98ae59d 100644 --- a/examples/README.md +++ b/examples/README.md @@ -16,10 +16,10 @@ When your key type consists of several members, you will usually have the hash f If your key-type stores dynamic memory (e.g. CStr as we will use), it is smart to define a plain-old-data "view" of the your key struct first: ``` #include -#include -#include +#include +#include -// Viking view struct ----------------------- +// Viking view struct typedef struct VikingVw { const char* name; @@ -37,7 +37,7 @@ int vikingvw_equals(const VikingVw* x, const VikingVw* y) { } ``` -And then the Viking data struct: +And the Viking data struct: ``` typedef struct Viking { CStr name; -- cgit v1.2.3