diff options
| author | Tyge Løvset <[email protected]> | 2020-12-31 10:15:59 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-12-31 10:15:59 +0100 |
| commit | eb77562a0d74062cd046bdca45d937360c96697c (patch) | |
| tree | ef76bf7fe71906397c21e63e73568af56df5f9f6 | |
| parent | 5c86a9ec884598c1ceb6f4b564248de99d6e05d7 (diff) | |
| download | STC-modified-eb77562a0d74062cd046bdca45d937360c96697c.tar.gz STC-modified-eb77562a0d74062cd046bdca45d937360c96697c.zip | |
More doc fixing.
| -rw-r--r-- | README.md | 45 | ||||
| -rw-r--r-- | benchmarks/cmap_benchmark.cpp | 2 | ||||
| -rw-r--r-- | docs/cdeq_api.md | 4 | ||||
| -rw-r--r-- | docs/clist_api.md | 2 | ||||
| -rw-r--r-- | docs/cvec_api.md | 4 |
5 files changed, 29 insertions, 28 deletions
@@ -1,30 +1,30 @@ -STC - Standard Template Containers for C99
-==========================================
+STC - Standard Template Containers for C
+========================================
Introduction
------------
An modern, fully typesafe, generic, customizable, user-friendly, consistent, and very fast standard container library for C99. This is a small headers only library with the most used container components, and a few algorithms:
-- [***cstr*** - Powerful and compact **string** type](docs/cstr_api.md)
-- [***crand*** - An extremely efficent modern **random number generator**](docs/crand_api.md)
-- [***clist*** - Templated **std::forward_list** alike type](docs/clist_api.md)
-- [***cmap*** - Templated **std::unordered_map** alike type](docs/cmap_api.md)
-- [***cset*** - Templated **std::unordered_set** alike type](docs/cset_api.md)
+- [***cstr*** - A **std::string** alike type](docs/cstr_api.md)
- [***cvec*** - Templated **std::vector** alike type](docs/cvec_api.md)
- [***cdeq*** - Templated **std::dequeue** alike type](docs/cdeq_api.md)
+- [***cmap*** - Templated **std::unordered_map** alike type](docs/cmap_api.md)
+- [***cset*** - Templated **std::unordered_set** alike type](docs/cset_api.md)
- [***cstack*** - Templated **std::stack** alike adapter type](docs/cstack_api.md)
- [***cqueue*** - Templated **std::queue** alike adapter type](docs/cqueue_api.md)
- [***cpque*** - Templated **std::priority_queue** alike adapter type](docs/cpque_api.md)
+- [***clist*** - Templated **std::forward_list** alike type](docs/clist_api.md)
+- [***cbitset*** - A **std::bitset** / **boost::dynamic_bitset* alike type](docs/cbitset_api.md)
- [***carray*** - Templated **multi-dimensional array** type](docs/carray_api.md)
- [***cptr*** - Container pointers and **std::shared_ptr** alike support](docs/cptr_api.md)
-- [***cbitset*** - A **std::bitset** / **boost::dynamic_bitset* alike type](docs/cbitset_api.md)
-- [***copt*** - Implements *copt_get()*, a **getopt_long** alike function](docs/copt_api.md)
+- [***crand*** - A very efficent modern **pseudo-random number generator**](docs/crand_api.md)
+- [***copt*** - Implements ***copt_get()***, similar to posix **getopt_long()**](docs/copt_api.md)
- [***ccommon*** - General definitions](docs/ccommon_api.md)
The usage of the containers is similar to the C++ standard containers, so it should be easy if you are familiar with them.
All containers mentioned above, except cstr_t and cbitset_t, are generic and therefore typesafe (similar to templates in C++). No casting is used. A simple example:
-```C
+```c
#include <stc/cvec.h>
using_cvec(i, int);
@@ -38,8 +38,8 @@ int main(void) { cvec_i_del(&vec);
}
```
-Using containers with complex element types is simple:
-```C
+Containers with struct element types:
+```c
#include <stc/cstr.h>
#include <stc/cvec.h>
@@ -48,26 +48,27 @@ typedef struct { int id;
} User;
-void User_del(User* u)
- { cstr_del(&u->name); }
-int User_compare(User* u, User* v)
- { int c = strcmp(u->name.str, v->name.str); return c != 0 ? c : u->id - v->id; }
+int User_compare(User* a, User* b)
+ { int c = strcmp(a->name.str, b->name.str); return c != 0 ? c : a->id - b->id; }
+void User_del(User* user)
+ { cstr_del(&user->name); }
-using_cvec(u, User, User_del, User_compare);
+using_cvec(u, User, User_compare, User_del);
int main(void) {
cvec_u vec = cvec_u_init();
- cvec_u_push_back(&vec, (User) {cstr_from("admin"), 0}); // cstr_from() allocates string memory
- cvec_u_push_back(&vec, (User) {cstr_from("usera"), 1});
+ cvec_u_push_back(&vec, (User) {cstr_from("admin"), 0});
+ cvec_u_push_back(&vec, (User) {cstr_from("joe"), 1});
+
c_foreach (i, cvec_u, vec)
printf("%s: %d\n", i.ref->name.str, i.ref->id);
- cvec_u_del(&vec); // free everything
+ cvec_u_del(&vec); // cleanup
}
```
Motivation
----------
-The aim of this project was to create a small **Standard Template library for the C language**. It should
+The aim is to make a small **Standard Template Containers library for C**. It should
- be easy to use, have intuitive naming and consistency across the library.
- be type safe. Have minimal usage of casting and void* pointers.
- be highly efficient. Both in speed and memory usage.
@@ -81,7 +82,7 @@ Installation Because it is headers only, files can simply be included in your program. The functions will be inlined by default. You may add the project folder to CPATH environment variable, to let gcc, clang, and tinyc locate the headers.
If containers are extensively used accross many translation 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 option, and put all the instantiations of the containers used in one C file, like this:
-```C
+```c
#define STC_IMPLEMENTATION
#include <stc/cstr.h>
#include <stc/cmap.h>
diff --git a/benchmarks/cmap_benchmark.cpp b/benchmarks/cmap_benchmark.cpp index d9b6d1ad..2aa96a3a 100644 --- a/benchmarks/cmap_benchmark.cpp +++ b/benchmarks/cmap_benchmark.cpp @@ -129,7 +129,7 @@ stc64_t rng; #define SMAP_DTOR(X) UMAP_DTOR(X)
enum {
- FAC = 2,
+ FAC = 3,
N1 = 10000000 * FAC,
N2 = 10000000 * FAC,
N3 = 10000000 * FAC,
diff --git a/docs/cdeq_api.md b/docs/cdeq_api.md index 259d02b1..746b585a 100644 --- a/docs/cdeq_api.md +++ b/docs/cdeq_api.md @@ -17,9 +17,9 @@ Defaults values are given above for args not specified. `X` is a type tag name a will affect the names of all cdeq types and methods. E.g. declaring `using_cdeq(my, int);`, `X` should be replaced by `my` in all of the following documentation. -`using_cdeq_str()` is a shorthand, expands to: +`using_cdeq_str()` is a shorthand for: ``` -using_cdeq(str, cstr_t, cstr_del, cstr_compare_raw, const char*, cstr_to_raw, cstr_from) +using_cdeq(str, cstr_t, cstr_compare_raw, cstr_del, const char*, cstr_to_raw, cstr_from) ``` ## Types diff --git a/docs/clist_api.md b/docs/clist_api.md index e3673492..e305ed48 100644 --- a/docs/clist_api.md +++ b/docs/clist_api.md @@ -18,7 +18,7 @@ Default values are given above for args not specified. `X` is a type tag name an will affect the names of all clist types and methods. E.g. declaring `using_clist(my, int);`, `X` should be replaced by `my` in all of the following documentation. `using_clist_str()` is a shorthand for ```c -using_clist(str, cstr_t, cstr_del, cstr_compare_raw, const char*, cstr_to_raw, cstr_from) +using_clist(str, cstr_t, cstr_compare_raw, cstr_del, const char*, cstr_to_raw, cstr_from) ``` ## Types diff --git a/docs/cvec_api.md b/docs/cvec_api.md index 8b6f751f..3afe7581 100644 --- a/docs/cvec_api.md +++ b/docs/cvec_api.md @@ -17,9 +17,9 @@ Defaults values are given above for args not specified. `X` is a type tag name a will affect the names of all cvec types and methods. E.g. declaring `using_cvec(my, int);`, `X` should be replaced by `my` in all of the following documentation. -`using_cvec_str()` is a shorthand, expands to: +`using_cvec_str()` is a shorthand for: ``` -using_cvec(str, cstr_t, cstr_del, cstr_compare_raw, const char*, cstr_to_raw, cstr_from) +using_cvec(str, cstr_t, cstr_compare_raw, cstr_del, const char*, cstr_to_raw, cstr_from) ``` ## Types |
