diff options
| -rw-r--r-- | docs/cbitset_api.md | 4 | ||||
| -rw-r--r-- | docs/clist_api.md | 4 | ||||
| -rw-r--r-- | docs/cmap_api.md | 36 | ||||
| -rw-r--r-- | docs/crandom_api.md | 4 | ||||
| -rw-r--r-- | docs/cset_api.md | 29 | ||||
| -rw-r--r-- | docs/cstr_api.md | 3 | ||||
| -rw-r--r-- | docs/cvec_api.md | 12 | ||||
| -rw-r--r-- | stc/cmap.h | 6 | ||||
| -rw-r--r-- | stc/cstr.h | 25 |
9 files changed, 51 insertions, 72 deletions
diff --git a/docs/cbitset_api.md b/docs/cbitset_api.md index d485f35a..59459b62 100644 --- a/docs/cbitset_api.md +++ b/docs/cbitset_api.md @@ -1,6 +1,4 @@ -# Introduction - -UNDER CONSTRUCTION! +# Container type cbitset This describes the API of string type **cbitset**. diff --git a/docs/clist_api.md b/docs/clist_api.md index 74ae44f5..2f8b03fc 100644 --- a/docs/clist_api.md +++ b/docs/clist_api.md @@ -1,6 +1,4 @@ -# Introduction - -UNDER CONSTRUCTION! +# Container type clist This describes the API of circular singly linked list type **clist**. diff --git a/docs/cmap_api.md b/docs/cmap_api.md index 3062bc07..109791f3 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -1,6 +1,4 @@ -# Introduction - -UNDER CONSTRUCTION! +# Container type cmap This describes the API of the unordered map type **cmap**. @@ -44,19 +42,20 @@ be replaced by `my` in all of the following documentation. | | ` uint8_t* _hashx;` | | | | ` ...;` | | | | `}` | | -| `cmap_X_key_t` | `Key` | The cmap key type | -| `cmap_X_mapped_t` | `Mapped` | cmap mapped type | -| `cmap_X_value_t` | `struct {` | The cmap value type | +| `cmap_X_rawkey_t` | `RawKey` | The raw key type | +| `cmap_X_rawval_t` | `RawMapped` | The raw mapped type | +| `cmap_X_key_t` | `Key` | The key type | +| `cmap_X_mapped_t` | `Mapped` | The mapped type | +| `cmap_X_value_t` | `struct {` | The value type | | | ` cmap_X_key_t first;` | | | | ` cmap_X_mapped_t second;` | | | | `}` | | -| `cmap_X_input_t` | `cmap_X_value_t` | cmap input type | -| `cmap_X_rawvalue_t` | `RawMapped` | cmap raw value type | +| `cmap_X_input_t` | `struct { ... }` | RawKey + RawVal type | | `cmap_X_result_t` | `struct {` | Result of insert/put/emplace | | | ` cmap_X_value_t* first;` | | | | ` bool second; /* inserted */` | | | | `}` | | -| `cmap_X_iter_t` | `struct {` | cmap iterator | +| `cmap_X_iter_t` | `struct {` | Iterator type | | | ` cmap_X_value_t* val;` | | | | ` ...;` | | | | `}` | | @@ -69,8 +68,7 @@ be replaced by `my` in all of the following documentation. | `cmap_empty(map)` | Test for empty map | | `cmap_size(map)` | Get map size | | `cmap_capacity(map)` | Get map capacity | -| `c_try_emplace(self, ctype, key, val) | Emplace if key exist | -| `c_insert_items(self, ctype, array)` | Insert literals list | +| `c_try_emplace(self, ctype, key, val)` | Emplace if key exist | ## Header file @@ -102,19 +100,19 @@ size_t cmap_X_capacity(cmap_X m); void cmap_X_push_n(cmap_X* self, const cmap_X_input_t in[], size_t size); -cmap_X_result_t cmap_X_emplace(cmap_X* self, RawKey rawKey, RawMapped rawVal); +cmap_X_result_t cmap_X_emplace(cmap_X* self, RawKey rkey, RawMapped rmapped); cmap_X_result_t cmap_X_insert(cmap_X* self, cmap_X_input_t in); -cmap_X_result_t cmap_X_insert_or_assign(cmap_X* self, RawKey rawKey, RawMapped rawVal); -cmap_X_result_t cmap_X_put(cmap_X* self, RawKey rawKey, RawMapped rawVal); -cmap_X_result_t cmap_X_putv(cmap_X* self, RawKey rawKey, Mapped mapped); -cmap_X_mapped_t* cmap_X_at(const cmap_X* self, RawKey rawKey); +cmap_X_result_t cmap_X_insert_or_assign(cmap_X* self, RawKey rkey, RawMapped rmapped); +cmap_X_result_t cmap_X_put(cmap_X* self, RawKey rkey, RawMapped rmapped); +cmap_X_result_t cmap_X_putv(cmap_X* self, RawKey rkey, Mapped mapped); +cmap_X_mapped_t* cmap_X_at(const cmap_X* self, RawKey rkey); -size_t cmap_X_erase(cmap_X* self, RawKey rawKey); +size_t cmap_X_erase(cmap_X* self, RawKey rkey); void cmap_X_erase_entry(cmap_X* self, cmap_X_value_t* val); cmap_X_iter_t cmap_X_erase_at(cmap_X* self, cmap_X_iter_t pos); -cmap_X_value_t* cmap_X_find(const cmap_X* self, RawKey rawKey); -bool cmap_X_contains(const cmap_X* self, RawKey rawKey); +cmap_X_value_t* cmap_X_find(const cmap_X* self, RawKey rkey); +bool cmap_X_contains(const cmap_X* self, RawKey rkey); cmap_X_iter_t cmap_X_begin(cmap_X* self); cmap_X_iter_t cmap_X_end(cmap_X* self); diff --git a/docs/crandom_api.md b/docs/crandom_api.md index 59389d5e..84865a26 100644 --- a/docs/crandom_api.md +++ b/docs/crandom_api.md @@ -1,6 +1,4 @@ -# Introduction - -UNDER CONSTRUCTION! +# Random number generators This describes the API of module **crandom**. diff --git a/docs/cset_api.md b/docs/cset_api.md index 5e24a56e..92d6afe4 100644 --- a/docs/cset_api.md +++ b/docs/cset_api.md @@ -1,6 +1,4 @@ -# Introduction
-
-UNDER CONSTRUCTION!
+# Container type cset
This describes the API of the unordered set type **cset**.
@@ -32,15 +30,15 @@ be replaced by `my` in all of the following documentation. | | ` uint8_t* _hashx;` | |
| | ` ...;` | |
| | `}` | |
-| `cset_X_key_t` | `Key` | The cset key type |
-| `cset_X_mapped_t` | `Mapped` | cset mapped type |
-| `cset_X_value_t` | `Key` | The cset value type |
+| `cset_X_rawkey_t` | `RawKey` | The raw key type |
+| `cset_X_key_t` | `Key` | The key type |
+| `cset_X_value_t` | `Key` | The value type |
| `cset_X_result_t` | `struct {` | Result of insert/emplace |
| | ` cset_X_value_t* first;` | |
| | ` bool second; /* inserted */` | |
| | `}` | |
-| `cset_X_input_t` | `cset_X_value_t` | cset input type |
-| `cset_X_iter_t` | `struct {` | cset iterator |
+| `cset_X_input_t` | `cset_X_rawkey_t` | The input type (rawkey) |
+| `cset_X_iter_t` | `struct {` | Iterator type |
| | ` cset_X_value_t* val;` | |
| | ` ...;` | |
| | `}` | |
@@ -54,14 +52,13 @@ be replaced by `my` in all of the following documentation. | `cset_size(set)` | Get set size |
| `cset_capacity(set)` | Get set capacity |
| `c_try_emplace(self, ctype, key, val)` | Emplace if key exist |
-| `c_insert_items(self, ctype, array)` | Insert literals list |
## Header file
All cset definitions and prototypes may be included in your C source file by including a single header file.
```c
-#include "stc/cset.h" or "stc/cmap.h"
+#include "stc/cset.h"
```
## Methods
@@ -86,22 +83,22 @@ size_t cset_X_capacity(cset_X m); void cset_X_push_n(cset_X* self, const cset_X_input_t in[], size_t size);
-cset_X_result_t cset_X_emplace(cset_X* self, cset_X_rawkey_t rawKey);
-cset_X_result_t cset_X_insert(cset_X* self, cset_X_rawkey_t rawKey);
+cset_X_result_t cset_X_emplace(cset_X* self, RawKey rkey);
+cset_X_result_t cset_X_insert(cset_X* self, RawKey rkey);
-size_t cset_X_erase(cset_X* self, cset_X_rawkey_t rawKey);
+size_t cset_X_erase(cset_X* self, RawKey rkey);
void cset_X_erase_entry(cset_X* self, cset_X_key_t* key);
cset_X_iter_t cset_X_erase_at(cset_X* self, cset_X_iter_t pos);
-cset_X_value_t* cset_X_find(const cset_X* self, cset_X_rawkey_t rawKey);
-bool cset_X_contains(const cset_X* self, cset_X_rawkey_t rawKey);
+cset_X_value_t* cset_X_find(const cset_X* self, RawKey rkey);
+bool cset_X_contains(const cset_X* self, RawKey rkey);
cset_X_iter_t cset_X_begin(cset_X* self);
cset_X_iter_t cset_X_end(cset_X* self);
void cset_X_next(cset_X_iter_t* it);
cset_X_mapped_t* cset_X_itval(cset_X_iter_t it);
-cset_bucket_t cset_X_bucket(const cset_X* self, const cset_X_rawkey_t* rawKeyPtr);
+cset_bucket_t cset_X_bucket(const cset_X* self, const cset_X_rawkey_t* rkeyPtr);
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/cstr_api.md b/docs/cstr_api.md index c3f6765d..d1941dd1 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -1,4 +1,4 @@ -# Introduction +# String type cstr_t This describes the API of string type **cstr_t**. @@ -14,6 +14,7 @@ This describes the API of string type **cstr_t**. | Name | Value | |:---------------------------|:-----------------| +| `cstr_inits` | `{...}` | | `cstr_npos` | `-1ull` | ## Header file diff --git a/docs/cvec_api.md b/docs/cvec_api.md index 1d521b55..7c8039ed 100644 --- a/docs/cvec_api.md +++ b/docs/cvec_api.md @@ -1,6 +1,4 @@ -# Introduction - -UNDER CONSTRUCTION! +# Container type cvec This describes the API of vector type **cvec**. @@ -27,10 +25,10 @@ be replaced by `my` in all of the following documentation. | Type name | Type definition | Used to represent... | |:---------------------|:---------------------------------------|:------------------------------------| | `cvec_X` | `struct { cvec_X_value_t* data; }` | The cvec type | -| `cvec_X_value_t` | `Value` | The cvec element type | -| `cvec_X_input_t` | `cvec_X_value_t` | cvec input type | -| `cvec_X_rawvalue_t` | `RawValue` | cvec raw value type | -| `cvec_X_iter_t` | `struct { cvec_X_value_t* val; }` | cvec iterator | +| `cvec_X_value_t` | `Value` | The cvec value type | +| `cvec_X_input_t` | `cvec_X_value_t` | The input type | +| `cvec_X_rawvalue_t` | `RawValue` | The raw value type | +| `cvec_X_iter_t` | `struct { cvec_X_value_t* val; }` | The iterator | ## Constants and macros @@ -66,12 +66,6 @@ int main(void) { if (__r.second) __r.first->second = val; \
} while (0)
-#define c_insert_items(self, ctype, ...) do { \
- const ctype##_input_t __arr[] = __VA_ARGS__; \
- for (size_t __i=0;__i<sizeof __arr/sizeof *__arr; ++__i) \
- ctype##_insert(self, __arr[__i]); \
-} while (0)
-
/* https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction */
#define chash_reduce(x, N) ((uint32_t) (((uint64_t) (x) * (N)) >> 32))
#define chash_entry_index(h, entryPtr) ((entryPtr) - (h).table)
@@ -40,8 +40,6 @@ typedef char cstr_value_t; #define cstr_npos ((size_t) (-1))
STC_API cstr_t
-cstr_init(void);
-STC_API cstr_t
cstr_from_n(const char* str, size_t len);
STC_API cstr_t
cstr_from_fmt(const char* fmt, ...);
@@ -81,6 +79,12 @@ c_istrnfind(const char* s, const char* needle, size_t nmax); #define _cstr_mem(size) ((((size) + 24) >> 4) * 16 + 8)
/* gives true string capacity: 7, 23, 39, ... */
#define _cstr_cap(size) ((((size) + 24) >> 4) * 16 - 9)
+static size_t _cstr_nullrep[3] = {0, 0, 0};
+
+static const cstr_t cstr_inits = {(char* ) &_cstr_nullrep[2]};
+
+STC_INLINE cstr_t
+cstr_init() { return cstr_inits; }
STC_INLINE void
cstr_del(cstr_t* self) {
@@ -90,13 +94,13 @@ cstr_del(cstr_t* self) { STC_INLINE cstr_t
cstr_with_capacity(size_t cap) {
- cstr_t s = cstr_init();
+ cstr_t s = cstr_inits;
cstr_reserve(&s, cap);
return s;
}
STC_INLINE cstr_t
cstr_with_size(size_t len, char fill) {
- cstr_t s = cstr_init();
+ cstr_t s = cstr_inits;
cstr_resize(&s, len, fill);
return s;
}
@@ -144,7 +148,7 @@ cstr_take(cstr_t* self, cstr_t s) { STC_INLINE cstr_t
cstr_move(cstr_t* self) {
cstr_t tmp = *self;
- *self = cstr_init();
+ *self = cstr_inits;
return tmp;
}
@@ -251,13 +255,6 @@ STC_INLINE uint32_t cstr_hash_raw(const char* const* spp, size_t ignored) { #if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
-STC_DEF cstr_t
-cstr_init() {
- static size_t nullrep[3] = {0, 0, 0};
- static cstr_t init = {(char* ) &nullrep[2]};
- return init;
-}
-
STC_DEF size_t
cstr_reserve(cstr_t* self, size_t cap) {
size_t len = cstr_size(*self), oldcap = cstr_capacity(*self);
@@ -280,7 +277,7 @@ cstr_resize(cstr_t* self, size_t len, char fill) { STC_DEF cstr_t
cstr_from_n(const char* str, size_t len) {
- if (len == 0) return cstr_init();
+ if (len == 0) return cstr_inits;
size_t *rep = (size_t *) c_malloc(_cstr_mem(len));
cstr_t s = {strncpy((char *) &rep[2], str, len)};
s.str[rep[0] = len] = '\0';
@@ -315,7 +312,7 @@ cstr_fmt(cstr_t* self, const char* fmt, ...) { STC_DEF cstr_t
cstr_from_fmt(const char* fmt, ...) {
- cstr_t ret = cstr_init();
+ cstr_t ret = cstr_inits;
va_list args; va_start(args, fmt);
cstr_vfmt(&ret, fmt, args);
va_end(args);
|
