diff options
| author | Tyge Løvset <[email protected]> | 2021-09-06 22:46:26 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-09-06 22:46:26 +0200 |
| commit | fe498c3f4518d4946ecb31aa3c56553d1901634a (patch) | |
| tree | 563a13d06d42db410aaad9aa98d14623bc3f018b /include | |
| parent | bf0bbb610c0efb1d832cf33d325a77b1ad6c1c54 (diff) | |
| download | STC-modified-fe498c3f4518d4946ecb31aa3c56553d1901634a.tar.gz STC-modified-fe498c3f4518d4946ecb31aa3c56553d1901634a.zip | |
cmap: put() and at() was accidentally deleted. Restored.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/cmap.h | 21 | ||||
| -rw-r--r-- | include/stc/test_new_map.c | 3 |
2 files changed, 18 insertions, 6 deletions
diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 3853bb74..71c9b718 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -118,10 +118,7 @@ STC_API void cx_memb(_reserve)(Self* self, size_t capacity); STC_API chash_bucket_t cx_memb(_bucket_)(const Self* self, const cx_rawkey_t* rkeyptr);
STC_API cx_result_t cx_memb(_insert_entry_)(Self* self, i_KEYRAW rkey);
STC_API void cx_memb(_erase_entry)(Self* self, cx_value_t* val);
-cx_MAP_ONLY(
- STC_API cx_result_t cx_memb(_insert_or_assign)(Self* self, i_KEY _key, i_VAL _mapped);
- STC_API cx_result_t cx_memb(_emplace_or_assign)(Self* self, i_KEYRAW rkey, i_VALRAW rmapped);
-)
+
STC_INLINE Self cx_memb(_init)(void) { return c_make(Self)_cmap_inits; }
STC_INLINE void cx_memb(_shrink_to_fit)(Self* self) { cx_memb(_reserve)(self, self->size); }
STC_INLINE void cx_memb(_max_load_factor)(Self* self, float ml) {self->max_load_factor = ml; }
@@ -134,6 +131,22 @@ STC_INLINE void cx_memb(_swap)(Self *map1, Self *map2) {c_swap(Self, *ma STC_INLINE bool cx_memb(_contains)(const Self* self, i_KEYRAW rkey)
{ return self->size && self->_hashx[cx_memb(_bucket_)(self, &rkey).idx]; }
+cx_MAP_ONLY(
+ STC_API cx_result_t cx_memb(_insert_or_assign)(Self* self, i_KEY _key, i_VAL _mapped);
+ STC_API cx_result_t cx_memb(_emplace_or_assign)(Self* self, i_KEYRAW rkey, i_VALRAW rmapped);
+
+ STC_INLINE cx_result_t /* short-form, like operator[]: */
+ cx_memb(_put)(Self* self, i_KEY key, i_VAL mapped) {
+ return cx_memb(_insert_or_assign)(self, key, mapped);
+ }
+
+ STC_INLINE cx_mapped_t*
+ cx_memb(_at)(const Self* self, i_KEYRAW rkey) {
+ chash_bucket_t b = cx_memb(_bucket_)(self, &rkey);
+ return &self->table[b.idx].second;
+ }
+)
+
STC_INLINE void
cx_memb(_value_clone)(cx_value_t* _dst, cx_value_t* _val) {
*cx_keyref(_dst) = i_KEYFROM(i_KEYTO(cx_keyref(_val)));
diff --git a/include/stc/test_new_map.c b/include/stc/test_new_map.c index 4c1c7a0a..5dfca14e 100644 --- a/include/stc/test_new_map.c +++ b/include/stc/test_new_map.c @@ -18,7 +18,7 @@ int point_compare(const Point* a, const Point* b) { int c = c_default_compare(&a->x, &b->x);
return c ? c : c_default_compare(&a->y, &b->y);
}
-#define f_TAG pnt
+#define f_TAG pnt // f=forward declared
#define i_KEY Point
#define i_VAL int
#define i_CMP point_compare
@@ -28,7 +28,6 @@ int point_compare(const Point* a, const Point* b) { #define i_VAL_str
#include "cmap.h"
-
#define i_KEY_str
#include "cset.h"
|
