diff options
| author | Tyge Løvset <[email protected]> | 2020-09-21 21:40:49 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-09-21 21:40:49 +0200 |
| commit | 778c56781c1ebbcc03738418f1875ad62a4714e5 (patch) | |
| tree | e698a45b90278867c33a1cfd04bf3b10a30494ee | |
| parent | 861b674701c2aaf9f837e39eed8d74d6e7c688f3 (diff) | |
| download | STC-modified-778c56781c1ebbcc03738418f1875ad62a4714e5.tar.gz STC-modified-778c56781c1ebbcc03738418f1875ad62a4714e5.zip | |
Update README.md
| -rw-r--r-- | README.md | 92 |
1 files changed, 59 insertions, 33 deletions
@@ -141,50 +141,26 @@ Example usages --------------
The examples folder contains further examples.
-**cstr** string example.
-```C
-#include <stc/cstr.h>
-
-int main() {
- cstr_t s1 = cstr("one-nine-three-seven-five");
- printf("%s.\n", s1.str);
-
- cstr_insert(&s1, 3, "-two");
- printf("%s.\n", s1.str);
-
- cstr_erase(&s1, 7, 5); // -nine
- printf("%s.\n", s1.str);
-
- cstr_replace(&cs, cstr_find(&cs, "seven"), 5, "four");
- printf("%s.\n", s1.str);
-
- // reassign:
- cstr_assign(&s1, "one two three four five six seven");
- cstr_append(&s1, " eight");
- printf("append: %s\n", s1.str);
-
- cstr_t full_path = cstr_from("%s/%s.%s", "directory", "filename", "ext");
- printf("%s\n", full_path.str);
-
- c_del(cstr, &s1, &full_path);
-}
-```
**cvec** of *int64_t*.
```C
#include <stc/cvec.h>
+#include <stdio.h>
using_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_reserve(&bignums, 100);
- c_forrange (i, 100)
+ cvec_ix_reserve(&bignums, 50);
+
+ c_forrange (i, 50)
cvec_ix_push_back(&bignums, i * i * i);
- cvec_ix_pop_back(&bignums); // erase the last
- uint64_t value;
+ cvec_ix_pop_back(&bignums); // erase the last
c_forrange (i, cvec_ix_size(bignums))
- value = bignums.data[i];
+ bignums.data[i] /= i; // make them smaller
+
+ c_foreach (i, cvec_ix, bignums)
+ printf(" %d", *i.get);
cvec_ix_del(&bignums);
}
```
@@ -211,6 +187,34 @@ int main() { cvec_str_del(&names);
}
```
+**cstr** string example.
+```C
+#include <stc/cstr.h>
+
+int main() {
+ cstr_t s1 = cstr("one-nine-three-seven-five");
+ printf("%s.\n", s1.str);
+
+ cstr_insert(&s1, 3, "-two");
+ printf("%s.\n", s1.str);
+
+ cstr_erase(&s1, 7, 5); // -nine
+ printf("%s.\n", s1.str);
+
+ cstr_replace(&cs, cstr_find(&cs, "seven"), 5, "four");
+ printf("%s.\n", s1.str);
+
+ // reassign:
+ cstr_assign(&s1, "one two three four five six seven");
+ cstr_append(&s1, " eight");
+ printf("append: %s\n", s1.str);
+
+ cstr_t full_path = cstr_from("%s/%s.%s", "directory", "filename", "ext");
+ printf("%s\n", full_path.str);
+
+ c_del(cstr, &s1, &full_path);
+}
+```
**cmap** of *int => int*, and **cmap** of *cstr_t* => *cstr_t*
```C
#include <stdio.h>
@@ -324,6 +328,28 @@ int main() cpqueue_i_del(&heap);
}
```
+**cqueue** adapter container. Uses singly linked list as representation.
+```C
+#include <stc/cqueue.h>
+#include <stdio.h>
+
+using_clist(i, int);
+using_cqueue(i, clist_i);
+
+int main() {
+ cqueue_i queue = cqueue_i_init();
+
+ // push_front() / push_back() interleaved.
+ c_forrange (i, 20) {
+ if (i & 1) cqueue_i_push_front(&queue, i);
+ else cqueue_i_push_back(&queue, i);
+ }
+ c_foreach (i, cqueue_i, queue) {
+ printf(" %d\n", *i.get);
+
+ cqueue_i_del(&queue);
+}
+```
**carray**. 1d, 2d and 3d arrays, allocated from heap in one memory block. *carray3* may have sub-array "views" of *carray2* and *carray1* etc., as shown in the following example:
```C
#include <stdio.h>
|
