summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--docs/clist_api.md9
-rw-r--r--docs/cmap_api.md123
-rw-r--r--docs/cvec_api.md16
-rw-r--r--stc/cmap.h24
4 files changed, 149 insertions, 23 deletions
diff --git a/docs/clist_api.md b/docs/clist_api.md
index 34314d32..268fe7bd 100644
--- a/docs/clist_api.md
+++ b/docs/clist_api.md
@@ -16,10 +16,11 @@ This describes the API of circular singly linked list type **clist**.
valueFromRaw=c_default_from_raw)
```
The macro `using_clist()` can be instantiated with 2, 3, 4, or 7 arguments in the global scope.
-Defaults are given above for args not specified. Note that `z` can be any name, it's a tag and
-will affect the names of all clist types and methods, e.g. for `using_clist(my, int);` `$` should
-be replaced by `my` in all of the following documentation. `using_clist_str()` is a predefined
-macro for `using_clist(str, cstr_t, ...)`.
+Default values are given above for args not specified. `$` is a type tag name and
+will affect the names of all clist types and methods. E.g. declaring `using_clist(my, int);`, `$` should
+be replaced by `my` in all of the following documentation.
+
+`using_clist_str()` is a predefined macro for `using_clist(str, cstr_t, ...)`.
## Types
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
new file mode 100644
index 00000000..0b9cd6a7
--- /dev/null
+++ b/docs/cmap_api.md
@@ -0,0 +1,123 @@
+# Introduction
+
+UNDER CONSTRUCTION!
+
+This describes the API of circular singly linked list type **cmap**.
+
+## Declaration
+
+```c
+#define using_cmap_str()
+
+#define using_cmap_strkey(Mapped, mappedDestroy=c_default_del)
+
+#define using_cmap_strval($, Key, keyEquals=c_default_equals,
+ keyHash=c_default_hash16,
+ keyDestroy=c_default_del,
+ RawKey=Key,
+ keyToRaw=c_default_to_raw,
+ keyFromRaw=c_default_from_raw)
+
+#define using_cmap($, Key, Mapped, mappedDestroy=c_default_del,
+ keyEqualsRaw=c_default_equals,
+ keyHashRaw=c_default_hash16,
+ keyDestroy=c_default_del,
+ RawKey=Key,
+ keyToRaw=c_default_to_raw,
+ keyFromRaw=c_default_from_raw,
+ RawMapped=Mapped,
+ mappedFromRaw=c_default_from_raw)
+```
+The macro `using_cmap()` can be instantiated with 3, 4, 6, 10, or 12 arguments in the global scope.
+Default values are given above for args not specified. `$` is a type tag name and
+will affect the names of all cmap types and methods. E.g. declaring `using_cmap(my, int);`, `$` should
+be replaced by `my` in all of the following documentation.
+
+`using_cmap_str()` is a predefined macro for `using_cmap(str, cstr_t, ...)`.
+
+## Types
+
+| Type name | Type definition | Used to represent... |
+|:---------------------|:--------------------------------------|:-----------------------------------|
+| `cmap_$` | `struct {` | The cmap type |
+| | ` cmap_$_value_t* table; | |
+| | ` uint8_t* _hashx;` | |
+| | ` ...;` | |
+| | `}` | |
+| `cmap_$_key_t` | `Key` | The cmap key type |
+| `cmap_$_mapped_t` | `Mapped` | cmap mapped type |
+| `cmap_$_value_t` | `struct {` | The cmap value type |
+| | ` cmap_$_key_t first; | |
+| | ` cmap_$_mapped_t second;` | |
+| | `}` | |
+| `cmap_$_input_t` | `cmap_$_value_t` | cmap input type |
+| `cmap_$_rawvalue_t` | `RawMapped` | cmap raw value type |
+| `cmap_$_iter_t` | `struct {` | cmap iterator |
+| | ` cmap_$_value_t* val;` | |
+| | ` ...;` | |
+| | `}` | |
+
+## Constants and macros
+
+| Name | Value |
+|:---------------------------|:-----------------|
+| `cmap_inits` | `{...}` |
+| `cmap_empty(map)` | `true` if empty |
+| `cmap_size(map)` | |
+| `cmap_capacity(map)` | |
+
+
+## Header file
+
+All cmap definitions and prototypes may be included in your C source file by including a single header file.
+
+```c
+#include "stc/cmap.h"
+```
+## Methods
+
+### Construction
+
+The interfaces to create a cmap_$ object:
+```c
+cmap_$ cmap_$_init(void);
+cmap_$ cmap_$_with_capacity(size_t cap);
+void cmap_$_set_load_factors(cmap_$* self, float max, float shrink);
+
+void cmap_$_clear(cmap_$* self);
+void cmap_$_reserve(cmap_$* self, size_t size);
+void cmap_$_swap(cmap_$* a, cmap_$* b);
+
+void cmap_$_del(cmap_$* self);
+
+bool cmap_$_empty(cmap_$ m);
+size_t cmap_$_size(cmap_$ m);
+size_t cmap_$_bucket_count(cmap_$ m);
+size_t cmap_$_capacity(cmap_$ m);
+
+void cmap_$_push_n(cmap_$* self, const cmap_$_input_t in[], size_t size);
+
+cmap_$_result_t cmap_$_emplace(cmap_$* self, RawKey rawKey RawMapped rawVal);
+cmap_$_result_t cmap_$_insert(cmap_$* self, cmap_$_input_t in);
+cmap_$_result_t cmap_$_insert_or_assign(cmap_$* self, RawKey rawKey, RawMapped rawVal);
+cmap_$_result_t cmap_$_put(cmap_$* self, RawKey rawKey, RawMapped rawVal);
+cmap_$_result_t cmap_$_putv(cmap_$* self, RawKey rawKey, Mapped mapped);
+cmap_$_mapped_t* cmap_$_at(const cmap_$* self, RawKey rawKey);
+
+size_t cmap_$_erase(cmap_$* self, RawKey rawKey)
+void cmap_$_erase_entry(cmap_$* self, cmap_$_value_t* val);
+cmap_$_iter_t cmap_$_erase_at(cmap_$* self, cmap_$_iter_t pos);
+
+cmap_$_value_t* cmap_$_find(const cmap_$* self, RawKey rawKey);
+bool cmap_$_contains(const cmap_$* self, RawKey rawKey);
+
+cmap_$_iter_t cmap_$_begin(cmap_$* self);
+cmap_$_iter_t cmap_$_end(cmap_$* self)
+void cmap_$_next(cmap_$_iter_t* it);
+cmap_$_mapped_t* cmap_$_itval(cmap_$_iter_t it);
+
+cmap_bucket_t cmap_$_bucket(const cmap_$* self, const cmap_$_rawkey_t* rawKeyPtr);
+
+uint32_t c_default_hash16(const void *data, size_t len);
+uint32_t c_default_hash32(const void* data, size_t len);
+```
diff --git a/docs/cvec_api.md b/docs/cvec_api.md
index 79c143ee..34d055c2 100644
--- a/docs/cvec_api.md
+++ b/docs/cvec_api.md
@@ -16,10 +16,11 @@ This describes the API of vector type **cvec**.
valueFromRaw=c_default_from_raw)
```
The macro `using_cvec()` can be instantiated with 2, 3, 4, or 7 arguments in the global scope.
-Defaults are given above for args not specified. Note that `z` can be any name, it's a tag and
-will affect the names of all cvec types and methods, e.g. for `using_cvec(my, int);` `$` should
-be replaced by `my` in all of the following documentation. `using_cvec_str()` is a predefined
-macro for `using_cvec(str, cstr_t, ...)`.
+Defaults values are given above for args not specified. `$` is a type tag name and
+will affect the names of all cvec types and methods. E.g. declaring `using_cvec(my, int);`, `$` should
+be replaced by `my` in all of the following documentation.
+
+`using_cvec_str()` is a predefined macro for `using_cvec(str, cstr_t, ...)`.
## Types
@@ -36,9 +37,10 @@ macro for `using_cvec(str, cstr_t, ...)`.
| Name | Value |
|:---------------------------|:-----------------|
| `cvec_inits` | `{NULL}` |
-| `cvec_size(v) | |
-| `cvec_capacity(v)` | |
-| `cvec_empty(v)` | |
+| `cvec_empty(vec)` | |
+| `cvec_size(vec)` | |
+| `cvec_capacity(vec)` | |
+
## Header file
diff --git a/stc/cmap.h b/stc/cmap.h
index e9a4bc72..f538a2b9 100644
--- a/stc/cmap.h
+++ b/stc/cmap.h
@@ -98,9 +98,9 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
keyDestroy, RawKey, keyToRaw, keyFromRaw, Mapped, c_default_from_raw)
#define using_cmap_12(X, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
- keyDestroy, RawKey, keyToRaw, keyFromRaw, RawVal, valueFromRaw) \
+ keyDestroy, RawKey, keyToRaw, keyFromRaw, RawMapped, mappedFromRaw) \
_c_typedef_CHASH(X, cmap, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
- keyDestroy, RawKey, keyToRaw, keyFromRaw, RawVal, valueFromRaw)
+ keyDestroy, RawKey, keyToRaw, keyFromRaw, RawMapped, mappedFromRaw)
/* cset: */
#define using_cset(...) \
@@ -166,11 +166,11 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
/* CHASH full: use 'void' for Mapped if ctype is cset */
#define _c_typedef_CHASH(X, ctype, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
- keyDestroy, RawKey, keyToRaw, keyFromRaw, RawVal, valueFromRaw) \
+ keyDestroy, RawKey, keyToRaw, keyFromRaw, RawMapped, mappedFromRaw) \
typedef Key ctype##_##X##_key_t; \
typedef Mapped ctype##_##X##_mapped_t; \
typedef RawKey ctype##_##X##_rawkey_t; \
- typedef RawVal ctype##_##X##_rawval_t; \
+ typedef RawMapped ctype##_##X##_rawval_t; \
\
typedef CSET_ONLY_##ctype( ctype##_##X##_key_t ) \
CMAP_ONLY_##ctype( struct {ctype##_##X##_key_t first; \
@@ -242,9 +242,9 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
ctype##_##X##_bucket(const ctype##_##X* self, const ctype##_##X##_rawkey_t* rawKeyPtr); \
\
STC_INLINE ctype##_##X##_result_t \
- ctype##_##X##_emplace(ctype##_##X* self, RawKey rawKey CMAP_ONLY_##ctype(, RawVal rawVal)) { \
+ ctype##_##X##_emplace(ctype##_##X* self, RawKey rawKey CMAP_ONLY_##ctype(, RawMapped rawVal)) { \
ctype##_##X##_result_t res = ctype##_##X##_insert_key_(self, rawKey); \
- CMAP_ONLY_##ctype( if (res.second) res.first->second = valueFromRaw(rawVal); ) \
+ CMAP_ONLY_##ctype( if (res.second) res.first->second = mappedFromRaw(rawVal); ) \
return res; \
} \
STC_INLINE ctype##_##X##_result_t \
@@ -255,10 +255,10 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
\
CMAP_ONLY_##ctype( \
STC_INLINE ctype##_##X##_result_t \
- ctype##_##X##_insert_or_assign(ctype##_##X* self, RawKey rawKey, RawVal rawVal) { \
+ ctype##_##X##_insert_or_assign(ctype##_##X* self, RawKey rawKey, RawMapped rawVal) { \
ctype##_##X##_result_t res = ctype##_##X##_insert_key_(self, rawKey); \
if (!res.second) valueDestroy(&res.first->second); \
- res.first->second = valueFromRaw(rawVal); return res; \
+ res.first->second = mappedFromRaw(rawVal); return res; \
} \
STC_INLINE ctype##_##X##_mapped_t* \
ctype##_##X##_at(const ctype##_##X* self, RawKey rawKey) { \
@@ -267,7 +267,7 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
return &self->table[b.idx].second; \
} \
STC_INLINE ctype##_##X##_result_t \
- ctype##_##X##_put(ctype##_##X* self, RawKey rawKey, RawVal rawVal) { \
+ ctype##_##X##_put(ctype##_##X* self, RawKey rawKey, RawMapped rawVal) { \
return ctype##_##X##_insert_or_assign(self, rawKey, rawVal); \
} \
STC_INLINE ctype##_##X##_result_t \
@@ -312,14 +312,14 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t;
STC_API uint32_t c_default_hash32(const void* data, size_t len); \
\
_c_implement_CHASH(X, ctype, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
- keyDestroy, RawKey, keyToRaw, keyFromRaw, RawVal, valueFromRaw) \
+ keyDestroy, RawKey, keyToRaw, keyFromRaw, RawMapped, mappedFromRaw) \
typedef ctype##_##X ctype##_##X##_t
/* -------------------------- IMPLEMENTATION ------------------------- */
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
#define _c_implement_CHASH(X, ctype, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
- keyDestroy, RawKey, keyToRaw, keyFromRaw, RawVal, valueFromRaw) \
+ keyDestroy, RawKey, keyToRaw, keyFromRaw, RawMapped, mappedFromRaw) \
STC_DEF ctype##_##X \
ctype##_##X##_with_capacity(size_t cap) { \
ctype##_##X h = ctype##_inits; \
@@ -458,7 +458,7 @@ STC_DEF uint32_t c_default_hash32(const void* data, size_t len) {
#else
#define _c_implement_CHASH(X, ctype, Key, Mapped, valueDestroy, keyEqualsRaw, keyHashRaw, \
- keyDestroy, RawKey, keyToRaw, keyFromRaw, RawVal, valueFromRaw)
+ keyDestroy, RawKey, keyToRaw, keyFromRaw, RawMapped, mappedFromRaw)
#endif
#endif