diff options
| author | Tyge Løvset <[email protected]> | 2022-04-22 12:20:31 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-04-22 12:20:31 +0200 |
| commit | 8f57f3d331de4cb4aa7d06862c2de3424eb1ba5b (patch) | |
| tree | 1a730578475e4d6e260948578cd0c2a5fd4463f4 /docs/cmap_api.md | |
| parent | 182099800f230f876fb46dac9f1f49a4fe3c3981 (diff) | |
| download | STC-modified-8f57f3d331de4cb4aa7d06862c2de3424eb1ba5b.tar.gz STC-modified-8f57f3d331de4cb4aa7d06862c2de3424eb1ba5b.zip | |
Readded push()/emplace() to all containers missing them. Made _hash function required for i_key_bind, _eq is derived from _cmp.
Diffstat (limited to 'docs/cmap_api.md')
| -rw-r--r-- | docs/cmap_api.md | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/docs/cmap_api.md b/docs/cmap_api.md index 69257779..645b0bd0 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -67,11 +67,10 @@ cmap_X_iter cmap_X_find(const cmap_X* self, i_keyraw rkey); cmap_X_result cmap_X_insert(cmap_X* self, i_key key, i_val mapped); // no change if key in map cmap_X_result cmap_X_insert_or_assign(cmap_X* self, i_key key, i_val mapped); // always update mapped -cmap_X_result cmap_X_put(cmap_X* self, i_key key, i_val mapped); // alias for insert_or_assign +cmap_X_result cmap_X_push(cmap_X* self, i_key key, i_val mapped); // alias for insert cmap_X_result cmap_X_emplace(cmap_X* self, i_keyraw rkey, i_valraw rmapped); // no change if rkey in map cmap_X_result cmap_X_emplace_or_assign(cmap_X* self, i_keyraw rkey, i_valraw rmapped); // always update rmapped -cmap_X_result cmap_X_put_raw(cmap_X* self, i_keyraw rkey, i_valraw rmapped); // alias for emplace_or_assign size_t cmap_X_erase(cmap_X* self, i_keyraw rkey); // return 0 or 1 cmap_X_iter cmap_X_erase_at(cmap_X* self, cmap_X_iter it); // return iter after it @@ -276,8 +275,9 @@ typedef struct { #define Viking_init() ((Viking){cstr_null, cstr_null}) -static inline bool Viking_eq(const Viking* a, const Viking* b) { - return cstr_equals_s(a->name, b->name) && cstr_equals_s(a->country, b->country); +static inline int Viking_cmp(const Viking* a, const Viking* b) { + int c = cstr_cmp(&a->name, &b->name); + return c ? c : cstr_cmp(&a->country, &b->country); } static inline uint32_t Viking_hash(const Viking* a, int ignored) { @@ -298,7 +298,7 @@ static inline void Viking_drop(Viking* vk) { #define i_key_bind Viking #define i_val int // i_key_bind auto-binds: -// #define i_eq Viking_eq +// #define i_cmp Viking_cmp // #define i_hash Viking_hash // #define i_keyfrom Viking_clone // #define i_keydrop Viking_drop @@ -361,8 +361,10 @@ static inline uint64_t RViking_hash(const RViking* raw, size_t ignore) { uint64_t hash = c_strhash(raw->name) ^ (c_strhash(raw->country) >> 15); return hash; } -static inline bool RViking_eq(const RViking* rx, const RViking* ry) { - return strcmp(rx->name, ry->name) == 0 && strcmp(rx->country, ry->country) == 0; + +static inline int RViking_cmp(const RViking* rx, const RViking* ry) { + int c = strcmp(rx->name, ry->name); + return c ? c : strcmp(rx->country, ry->country); } static inline Viking Viking_from(RViking raw) { @@ -379,7 +381,7 @@ static inline RViking Viking_toraw(const Viking* vk) { #define i_keyraw RViking // i_key_bind macro will make these functions auto-bind: // #define i_hash RViking_hash -// #define i_eq RViking_eq +// #define i_cmp RViking_cmp // #define i_keyfrom Viking_from // uses _from because i_keyraw is defined // #define i_keyto Viking_toraw // #define i_keydrop Viking_drop |
