summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2022-07-11 23:53:06 +0200
committerTyge Lovset <[email protected]>2022-07-11 23:53:06 +0200
commit839efba934c8623f2dea31e7f8bb2857624c6908 (patch)
tree218e165ae2b65f6c2be41ea8169fb71432b4e68e
parent5082397444550d9486783fe498629524a64d564e (diff)
downloadSTC-modified-839efba934c8623f2dea31e7f8bb2857624c6908.tar.gz
STC-modified-839efba934c8623f2dea31e7f8bb2857624c6908.zip
Fixed documentation changes for size, capacity, empty. Minor changes in some ex. and map shootout.
-rw-r--r--benchmarks/shootout_hashmaps.cpp7
-rw-r--r--docs/clist_api.md4
-rw-r--r--docs/cmap_api.md2
-rw-r--r--docs/cqueue_api.md4
-rw-r--r--docs/csmap_api.md2
-rw-r--r--docs/csset_api.md4
-rw-r--r--examples/box.c14
-rw-r--r--examples/box2.c8
-rw-r--r--include/stc/clist.h6
9 files changed, 26 insertions, 25 deletions
diff --git a/benchmarks/shootout_hashmaps.cpp b/benchmarks/shootout_hashmaps.cpp
index a01f62a1..2ae4bf11 100644
--- a/benchmarks/shootout_hashmaps.cpp
+++ b/benchmarks/shootout_hashmaps.cpp
@@ -32,6 +32,7 @@ KHASH_MAP_INIT_INT64(ii, int64_t)
#define i_key int64_t
#define i_val int64_t
#define i_tag ii
+#define i_hash(x) (*x * 0xc6a4a7935bd1e99d) // optional
#include <stc/cmap.h>
#define SEED(s) rng = stc64_new(s)
@@ -67,7 +68,7 @@ KHASH_MAP_INIT_INT64(ii, int64_t)
#define UMAP_EMPLACE(X, key, val) map.emplace(key, val).first->second
#define UMAP_FIND(X, key) int(map.find(key) != map.end())
#define UMAP_ERASE(X, key) map.erase(key)
-#define UMAP_FOR(X, i) for (auto i: map)
+#define UMAP_FOR(X, i) for (const auto& i: map)
#define UMAP_ITEM(X, i) i.second
#define UMAP_SIZE(X) map.size()
#define UMAP_BUCKETS(X) map.bucket_count()
@@ -268,7 +269,7 @@ int main(int argc, char* argv[])
unsigned n_mill = argc >= 2 ? atoi(argv[1]) : DEFAULT_N_MILL;
unsigned keybits = argc >= 3 ? atoi(argv[2]) : DEFAULT_KEYBITS;
unsigned n = n_mill * 1000000;
- unsigned N0 = n, N1 = n/2, N2 = n/2, N3 = n, N4 = n, N5 = n;
+ unsigned N0 = n, N1 = n/2, N2 = n/2, N3 = n, N4 = n, N5 = n/2;
stc64_t rng;
size_t seed = time(NULL);
@@ -283,7 +284,7 @@ int main(int argc, char* argv[])
"DMAP = https://github.com/martinus/unordered_dense\n"
"EMAP = https://github.com//ktprime/emhash\n"
"UMAP = std::unordered_map\n\n");
-
+
printf("Usage %s [n-million=%d key-bits=%d]\n", argv[0], DEFAULT_N_MILL, DEFAULT_KEYBITS);
printf("N-base = %d. Random keys are in range [0, 2^%d). Seed = %" PRIuMAX ":\n", n_mill, keybits, seed);
diff --git a/docs/clist_api.md b/docs/clist_api.md
index 9cd950bb..17ee3fa8 100644
--- a/docs/clist_api.md
+++ b/docs/clist_api.md
@@ -45,8 +45,8 @@ void clist_X_clear(clist_X* self);
void clist_X_copy(clist_X* self, const clist_X* other);
void clist_X_drop(clist_X* self); // destructor
-bool clist_X_empty(clist_X list);
-size_t clist_X_count(clist_X list); // size() in O(n) time
+bool clist_X_empty(const clist_X* list);
+size_t clist_X_count(const clist_X* list); // size() in O(n) time
clist_X_value* clist_X_front(const clist_X* self);
clist_X_value* clist_X_back(const clist_X* self);
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
index 5804112f..a624cfea 100644
--- a/docs/cmap_api.md
+++ b/docs/cmap_api.md
@@ -56,7 +56,7 @@ void cmap_X_swap(cmap_X* a, cmap_X* b);
void cmap_X_drop(cmap_X* self); // destructor
size_t cmap_X_size(const cmap_X* self);
-size_t cmap_X_capacity(const cmap_X self); // buckets * max_load_factor
+size_t cmap_X_capacity(const cmap_X* self); // buckets * max_load_factor
bool cmap_X_empty(const cmap_X* self );
size_t cmap_X_bucket_count(const cmap_X* self); // num. of allocated buckets
diff --git a/docs/cqueue_api.md b/docs/cqueue_api.md
index 1f5469d6..a8be9e86 100644
--- a/docs/cqueue_api.md
+++ b/docs/cqueue_api.md
@@ -30,8 +30,8 @@ void cqueue_X_clear(cqueue_X* self);
void cqueue_X_copy(cqueue_X* self, const cqueue_X* other);
void cqueue_X_drop(cqueue_X* self); // destructor
-size_t cqueue_X_size(cqueue_X q);
-bool cqueue_X_empty(cqueue_X q);
+size_t cqueue_X_size(const cqueue_X* self);
+bool cqueue_X_empty(const cqueue_X* self);
cqueue_X_value* cqueue_X_front(const cqueue_X* self);
cqueue_X_value* cqueue_X_back(const cqueue_X* self);
diff --git a/docs/csmap_api.md b/docs/csmap_api.md
index b3cf668b..01b77cb4 100644
--- a/docs/csmap_api.md
+++ b/docs/csmap_api.md
@@ -51,7 +51,7 @@ void csmap_X_copy(csmap_X* self, const csmap_X* other);
void csmap_X_swap(csmap_X* a, csmap_X* b);
void csmap_X_drop(csmap_X* self); // destructor
-size_t csmap_X_size(const csmap_X self);
+size_t csmap_X_size(const csmap_X* self);
bool csmap_X_empty(const csmap_X* self);
bool csmap_X_capacity(const csmap_X* self);
diff --git a/docs/csset_api.md b/docs/csset_api.md
index 66ce8505..30e57ca4 100644
--- a/docs/csset_api.md
+++ b/docs/csset_api.md
@@ -34,8 +34,8 @@ void csset_X_copy(csset_X* self, const csset_X* other);
void csset_X_swap(csset_X* a, csset_X* b);
void csset_X_drop(csset_X* self); // destructor
-size_t csset_X_size(csset_X set);
-bool csset_X_empty(csset_X set);
+size_t csset_X_size(const csset_X* self);
+bool csset_X_empty(const csset_X* self);
const csset_X_value* csset_X_get(const csset_X* self, i_keyraw rkey); // const get
csset_X_value* csset_X_get_mut(csset_X* self, i_keyraw rkey); // return NULL if not found
diff --git a/examples/box.c b/examples/box.c
index 70b0ab08..ef2ff28b 100644
--- a/examples/box.c
+++ b/examples/box.c
@@ -48,19 +48,19 @@ int main()
printf("orig: %s %s\n", cstr_str(&p.get->name), cstr_str(&p.get->last));
printf("copy: %s %s\n", cstr_str(&q.get->name), cstr_str(&q.get->last));
- Persons_push_back(&vec, PBox_make(Person_new("Dale", "Cooper")));
- Persons_push_back(&vec, PBox_make(Person_new("Audrey", "Home")));
-
+ Persons_push(&vec, PBox_make(Person_new("Dale", "Cooper")));
+ Persons_push(&vec, PBox_make(Person_new("Audrey", "Home")));
+
// NB! Clone p and q to the vector using emplace_back()
- c_apply(v, Persons_push_back(&vec, PBox_clone(*v)), PBox, {p, q});
+ c_apply(v, Persons_push(&vec, PBox_clone(*v)), PBox, {p, q});
c_foreach (i, Persons, vec)
printf("%s %s\n", cstr_str(&i.ref->get->name), cstr_str(&i.ref->get->last));
puts("");
-
- // Look-up Audrey! Use a (fake) temporary PBox for lookup.
+
+ // Look-up Audrey! Create a temporary Person for lookup.
c_autovar (Person a = Person_new("Audrey", "Home"), Person_drop(&a)) {
- const PBox *v = Persons_get(&vec, a);
+ const PBox *v = Persons_get(&vec, a); // lookup
if (v) printf("found: %s %s\n", cstr_str(&v->get->name), cstr_str(&v->get->last));
}
puts("");
diff --git a/examples/box2.c b/examples/box2.c
index c44802d3..0896388e 100644
--- a/examples/box2.c
+++ b/examples/box2.c
@@ -10,7 +10,7 @@ struct {
double y;
} typedef Point;
-// A Rectangle can be specified by where its top left and bottom right
+// A Rectangle can be specified by where its top left and bottom right
// corners are in space
struct {
Point top_left;
@@ -27,7 +27,7 @@ struct {
// Box in box:
#define i_val_arcbox cbox_Point // NB: use i_val_arcbox when value is a cbox or carc!
- // it will auto-set i_valdrop, i_valfrom, i_cmp for you.
+ // it will auto define i_valdrop, i_valfrom, and i_cmp.
#define i_opt c_no_cmp
#define i_tag BoxPoint
#include <stc/cbox.h> // cbox_BoxPoint
@@ -43,7 +43,6 @@ cbox_Point boxed_origin(void) {
int main(void) {
- // (all the type annotations are superfluous)
// Stack allocated variables
Point point = origin();
Rectangle rectangle = (Rectangle){
@@ -51,11 +50,12 @@ int main(void) {
.bottom_right = (Point){ .x=3.0, .y=-4.0 }
};
- // Heap allocated rectangle
+ // Declare auto-deleted box objects
c_auto (cbox_Rectangle, boxed_rectangle)
c_auto (cbox_Point, boxed_point)
c_auto (cbox_BoxPoint, box_in_a_box)
{
+ // Heap allocated rectangle
boxed_rectangle = cbox_Rectangle_make((Rectangle){
.top_left = origin(),
.bottom_right = (Point){ .x=3.0, .y=-4.0 }
diff --git a/include/stc/clist.h b/include/stc/clist.h
index 0fbf01ae..229db32c 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -145,10 +145,10 @@ STC_INLINE _cx_value* _cx_memb(_front)(const _cx_self* self) { return &self->l
STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self) { return &self->last->value; }
STC_INLINE size_t
-_cx_memb(_count)(_cx_self cx) {
- size_t n = 1; const _cx_node *node = cx.last;
+_cx_memb(_count)(const _cx_self* self) {
+ size_t n = 1; const _cx_node *node = self->last;
if (!node) return 0;
- while ((node = node->next) != cx.last) ++n;
+ while ((node = node->next) != self->last) ++n;
return n;
}