summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-02-24 19:08:21 +0100
committerTyge Løvset <[email protected]>2021-02-24 19:08:21 +0100
commit1745da92874e1799c7d60f6e6810b398e9ab9f15 (patch)
treee2fcb84239a7e6a0711304fdf28618344cf7507e
parent46552181642b8ee52bc1a6e426c31b5c65aea499 (diff)
downloadSTC-modified-1745da92874e1799c7d60f6e6810b398e9ab9f15.tar.gz
STC-modified-1745da92874e1799c7d60f6e6810b398e9ab9f15.zip
More docs and some file renames.
-rw-r--r--README.md12
-rw-r--r--benchmarks/shootout1_cmap.cpp (renamed from benchmarks/cmap_benchmark2.cpp)0
-rw-r--r--benchmarks/shootout2_cmap.cpp (renamed from benchmarks/cmap_benchmark3.cpp)0
-rw-r--r--docs/ccommon_api.md21
-rw-r--r--docs/cstr_api.md5
-rw-r--r--examples/crandom_ex.c2
-rw-r--r--examples/demos.c2
-rw-r--r--examples/ex_gauss1.c2
-rw-r--r--examples/ex_gauss2.c2
-rw-r--r--examples/random.c2
-rw-r--r--examples/replace.c4
11 files changed, 25 insertions, 27 deletions
diff --git a/README.md b/README.md
index 310a38a8..9e6960ba 100644
--- a/README.md
+++ b/README.md
@@ -40,7 +40,7 @@ has noticable faster lookup than *std::map*'s typical red-black tree implementat
create a flatter structure (more balanced) than red-black trees. **cvec** is only slightly slower than *std::vector*.
Notes:
-- The barchart shows average test times from three platforms: Win-Clang++ v11, Mingw64 g++ 9.20, VC19. CPU: Ryzen 7 2700X CPU @4Ghz.
+- The barchart shows average test times over three platforms: Win-Clang++ v11, Mingw64 g++ 9.20, VC19. CPU: Ryzen 7 2700X CPU @4Ghz.
- Containers uses value types `uint64_t` and pairs of `uint64_t`for the maps.
- Black bars indicates performance variation between various platforms/compilers.
- Iterations are repeated 4 times over n elements.
@@ -82,7 +82,7 @@ int main(void) {
cvec_i_del(&vec);
}
```
-And with multiple containers...
+With six different containers:
```c
#include <stc/cset.h>
#include <stc/cvec.h>
@@ -207,8 +207,8 @@ elements using dynamic memory.
| push_front() | emplace_front() | cvec, cdeq, clist |
| insert_after() | emplace_after() | clist |
-***Note***: For integral or trivial element types, **emplace** and corresponding non-emplace methods are
-identical, so the following does not apply for containers of such types.
+***Note***: For containers of integral or trivial element types, **emplace** and corresponding non-emplace methods are
+identical, so the following does not apply for those.
The **emplace** methods ***constructs*** or ***clones*** their own copy of the element to be added.
In contrast, the non-emplace methods requires elements to be explicitly constructed or cloned before adding them.
@@ -233,7 +233,7 @@ cstr_del(&s);
cvec_del(&vec);
```
This is made possible because the **using**-declarations may be given an optional
-convertion/"rawvalue"-type as template parameter, along with a back and forth convertion
+conversion/"rawvalue"-type as template parameter, along with a back and forth conversion
methods to the container value type. By default, *rawvalue has the same type as value*.
Rawvalues are also beneficial for **find()** and *map insertions*. The **emplace()** methods constructs
@@ -265,7 +265,7 @@ Memory efficiency
- **clist**: Type size: one pointer. Each node allocates block storing value and next pointer.
- **cdeq**: Type size: two pointers. Otherwise like *cvec*.
- **cmap**: Type size: 4 pointers. *cmap* uses one table of keys+value, and one table of precomputed hash-value/used bucket, which occupies only one byte per bucket. The closed hashing has a default max load factor of 85%, and hash table scales by 1.5x when reaching that.
-- **csmap**: Type size: 1 pointer. *csmap* manages its own array of tree-nodes for allocation efficiency. Each node uses two 32-bit words by default for left/right childs, and one byte for `level`. *csmap* can be configured to allow more than 2^32 elements, ie. 2^64, but it will double the overhead per node.
+- **csmap**: Type size: 1 pointer. *csmap* manages its own array of tree-nodes for allocation efficiency. Each node uses two 32-bit words by default for left/right child, and one byte for `level`. *csmap* can be configured to allow more than 2^32 elements, ie. 2^64, but it will double the overhead per node.
- **carray**: carray1, carray2 and carray3. Type size: One pointer plus one, two, or three size_t variables to store dimensions. Arrays are allocated as one contiguous block of heap memory.
- **csptr**: a shared-pointer uses two pointers, one for the data and one for the reference counter.
diff --git a/benchmarks/cmap_benchmark2.cpp b/benchmarks/shootout1_cmap.cpp
index e16d4f41..e16d4f41 100644
--- a/benchmarks/cmap_benchmark2.cpp
+++ b/benchmarks/shootout1_cmap.cpp
diff --git a/benchmarks/cmap_benchmark3.cpp b/benchmarks/shootout2_cmap.cpp
index 13905a3f..13905a3f 100644
--- a/benchmarks/cmap_benchmark3.cpp
+++ b/benchmarks/shootout2_cmap.cpp
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index ed8ae3d4..4c40c998 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -1,6 +1,6 @@
# STC [ccommon](../stc/ccommon.h): Common definitions and handy macros
-The following handy macros are completely safe to use, i.e. they have no side-effects.
+The following handy macros are safe to use, i.e. have no side-effects.
### c_init, c_emplace_items
**c_init** declares and initializes any container with an array of elements. **c_emplace_items** adds elements to any existing container:
@@ -50,27 +50,26 @@ c_foreach (i, csset_x, it, csset_x_end(&set)) printf(" %d", *i.ref);
```
### c_withfile, c_breakwith
-Simplifies reading a file. Use **c_breakwith** if you need to break out of the block. Example:
+Simplifies reading a file. Use only **c_breakwith** to break out of the block if needed. Example:
```c
-// Put each line of a text file into a vector of strings
+// Load each line of a text file into a vector of strings
#include <errno.h>
#include <stc/cstr.h>
#include <stc/cvec.h>
using_cvec_str();
-cvec_str // on return, check global errno variable for errors
-readFile(const char* name) {
+cvec_str readFile(const char* name) {
cvec_str vec = cvec_str_init();
- // Next line handles declaring, opening, and closing a FILE*
- c_withfile (f, fopen(name, "r")) {
- cstr_t line = cstr_inits;
- while (cstr_getline(&line, f))
+ // Next line declares, opens, and closes the FILE*
+ c_withfile (fp, fopen(name, "r")) {
+ cstr_t line = cstr_init();
+ while (cstr_getline(&line, fp))
cvec_str_emplace_back(&vec, line.str);
cstr_del(&line);
}
- return vec;
+ return vec; // receiver should check errno variable
}
```
@@ -94,4 +93,4 @@ Memory allocator for the entire library. Macros can be overloaded by the user.
### c_swap, c_arraylen
- **c_swap(type, x, y)**: Simple macro for swapping internals of two objects.
-- **c_arraylen(array)**: Return number of elements in an array, e.g. `int array[] = {1, 2, 3, 4};
+- **c_arraylen(array)**: Return number of elements in an array, e.g. `int array[] = {1, 2, 3, 4};`
diff --git a/docs/cstr_api.md b/docs/cstr_api.md
index de20e89e..11cd1214 100644
--- a/docs/cstr_api.md
+++ b/docs/cstr_api.md
@@ -91,7 +91,7 @@ Helper methods, used by other container types.
| Type name | Type definition | Used to represent... |
|:------------------|:---------------------------------|:-------------------------|
-| `cstr, cstr_t` | `struct { const char *str; }` | The string type |
+| `cstr` | `struct { const char *str; }` | The string type |
| `cstr_value_t` | `char` | The string element type |
| `cstr_iter_t` | `struct { cstr_value_t *ref; }` | cstr iterator |
@@ -99,8 +99,7 @@ Helper methods, used by other container types.
| Name | Value |
|:------------------|:-----------------|
-| `cstr_inits` | `{...}` |
-| `cstr_npos` | `-1ull` |
+| `cstr_npos` | `(-1ull)` |
## Example
```c
diff --git a/examples/crandom_ex.c b/examples/crandom_ex.c
index c923debd..4fa1d487 100644
--- a/examples/crandom_ex.c
+++ b/examples/crandom_ex.c
@@ -22,7 +22,7 @@ int main()
sum += n;
if (n >= 0 && n < R) ++hist[n];
}
- cstr_t bar = cstr_inits;
+ cstr bar = cstr_init();
c_forrange (i, int, R) {
cstr_resize(&bar, hist[i] * 25ull * R / N2, '*');
printf("%3d %s\n", i, bar.str);
diff --git a/examples/demos.c b/examples/demos.c
index f60355e2..4eac761c 100644
--- a/examples/demos.c
+++ b/examples/demos.c
@@ -8,7 +8,7 @@
void stringdemo1()
{
printf("\nSTRINGDEMO1\n");
- cstr_t cs = cstr_from("one-nine-three-seven-five");
+ cstr cs = cstr_from("one-nine-three-seven-five");
printf("%s.\n", cs.str);
cstr_insert(&cs, 3, "-two");
diff --git a/examples/ex_gauss1.c b/examples/ex_gauss1.c
index 8ef08694..6536527d 100644
--- a/examples/ex_gauss1.c
+++ b/examples/ex_gauss1.c
@@ -41,7 +41,7 @@ int main()
cvec_e_sort(&vhist);
// Print the gaussian bar chart
- cstr_t bar = cstr_init();
+ cstr bar = cstr_init();
c_foreach (i, cvec_e, vhist) {
size_t n = (size_t) (i.ref->second * StdDev * Scale * 2.5 / N);
if (n > 0) {
diff --git a/examples/ex_gauss2.c b/examples/ex_gauss2.c
index e20c1768..616d7071 100644
--- a/examples/ex_gauss2.c
+++ b/examples/ex_gauss2.c
@@ -28,7 +28,7 @@ int main()
}
// Print the gaussian bar chart
- cstr_t bar = cstr_init();
+ cstr bar = cstr_init();
c_foreach (i, csmap_i, mhist) {
size_t n = (size_t) (i.ref->second * StdDev * Scale * 2.5 / N);
if (n > 0) {
diff --git a/examples/random.c b/examples/random.c
index c923debd..4fa1d487 100644
--- a/examples/random.c
+++ b/examples/random.c
@@ -22,7 +22,7 @@ int main()
sum += n;
if (n >= 0 && n < R) ++hist[n];
}
- cstr_t bar = cstr_inits;
+ cstr bar = cstr_init();
c_forrange (i, int, R) {
cstr_resize(&bar, hist[i] * 25ull * R / N2, '*');
printf("%3d %s\n", i, bar.str);
diff --git a/examples/replace.c b/examples/replace.c
index 53e916fc..fdf5a7df 100644
--- a/examples/replace.c
+++ b/examples/replace.c
@@ -11,9 +11,9 @@ int main ()
// replace signatures used in the same order as described above:
// Ustring positions: 0123456789*123456789*12345
- cstr_t s = cstr_from(base); // "this is a test string."
+ cstr s = cstr_from(base); // "this is a test string."
- cstr_t m = cstr_clone(s);
+ cstr m = cstr_clone(s);
cstr_append(&m, m.str);
cstr_append(&m, m.str);
printf("%s\n", m.str);