Skip to content

Commit

Permalink
Return enum
Browse files Browse the repository at this point in the history
  • Loading branch information
pelijah committed May 16, 2024
1 parent a3c1500 commit 9b1d238
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
6 changes: 3 additions & 3 deletions librz/include/rz_util/ht_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ RZ_API RZ_OWN HtName_(Ht) *Ht_(new_opt_size)(RZ_NONNULL HT_(Options) *opt, ut32
RZ_API void Ht_(free)(RZ_NULLABLE HtName_(Ht) *ht);
// Insert a new Key-Value pair into the hashtable. If the key already exists, returns false.
RZ_API bool Ht_(insert)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value);
RZ_API int Ht_(insert_ex)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value, RZ_OUT RZ_NULLABLE HT_(Kv) **out_kv);
RZ_API HtRetCode Ht_(insert_ex)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value, RZ_OUT RZ_NULLABLE HT_(Kv) **out_kv);
// Insert a new Key-Value pair into the hashtable, or updates the value if the key already exists.
RZ_API bool Ht_(update)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value);
RZ_API int Ht_(update_ex)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value, RZ_OUT RZ_NULLABLE HT_(Kv) **out_kv);
RZ_API HtRetCode Ht_(update_ex)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value, RZ_OUT RZ_NULLABLE HT_(Kv) **out_kv);
// Update the key of an element in the hashtable
RZ_API bool Ht_(update_key)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE old_key, const KEY_TYPE new_key);
// Delete a key from the hashtable.
Expand All @@ -192,4 +192,4 @@ RZ_API void Ht_(foreach)(RZ_NONNULL HtName_(Ht) *ht, RZ_NONNULL HT_(ForeachCallb

RZ_API RZ_BORROW HT_(Kv) *Ht_(find_kv)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, RZ_NULLABLE bool *found);
RZ_API bool Ht_(insert_kv)(RZ_NONNULL HtName_(Ht) *ht, RZ_NONNULL HT_(Kv) *kv, bool update);
RZ_API int Ht_(insert_kv_ex)(RZ_NONNULL HtName_(Ht) *ht, RZ_NONNULL HT_(Kv) *kv, bool update, RZ_OUT RZ_NULLABLE HT_(Kv) **out_kv);
RZ_API HtRetCode Ht_(insert_kv_ex)(RZ_NONNULL HtName_(Ht) *ht, RZ_NONNULL HT_(Kv) *kv, bool update, RZ_OUT RZ_NULLABLE HT_(Kv) **out_kv);
23 changes: 14 additions & 9 deletions librz/util/ht/ht_inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ static RZ_BORROW HT_(Kv) *reserve_kv(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE
* \brief Insert KV \p kv into hash table \p ht or replace an existing KV with \p kv,
* if hash table \p ht already contains a KV with the same key as \p kv
* \param ht Hash table
* \param kv KV; shallow copy is made when writing to a hash table
* \param kv KV; shallow copy is made when writing to the hash table
* \param update Update flag; if set to true, replacement of existing KV is allowed
* \return Returns true if insertion/replacement took place
*/
Expand All @@ -278,11 +278,13 @@ RZ_API bool Ht_(insert_kv)(RZ_NONNULL HtName_(Ht) *ht, RZ_NONNULL HT_(Kv) *kv, b
* \param kv KV; shallow copy is made when writing to the hash table
* \param update Update flag; if set to true, replacement of existing KV is allowed
* \param[out] out_kv Pointer to the inserted/updated KV
* or pointer to the KV that prevented insertion (if \p update set to false)
* or pointer to the KV that prevented insertion (only if \p update set to false)
* or NULL in case of error. Pointers are valid until the next modification of the hash table.
* \return Returns HtRetCode
* \return Returns HT_RC_INSERTED/HT_RC_UPDATED if KV was inserted/updated;
* returns HT_RC_EXISTING if key \p key already exists (only if \p update set to false);
* returns HT_RC_ERROR if out of memory.
*/
RZ_API int Ht_(insert_kv_ex)(RZ_NONNULL HtName_(Ht) *ht, RZ_NONNULL HT_(Kv) *kv, bool update, RZ_OUT RZ_NULLABLE HT_(Kv) **out_kv) {
RZ_API HtRetCode Ht_(insert_kv_ex)(RZ_NONNULL HtName_(Ht) *ht, RZ_NONNULL HT_(Kv) *kv, bool update, RZ_OUT RZ_NULLABLE HT_(Kv) **out_kv) {
rz_return_val_if_fail(ht && kv, HT_RC_ERROR);

HtRetCode rc;
Expand Down Expand Up @@ -342,10 +344,12 @@ RZ_API bool Ht_(insert)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TY
* \param value KV value; copy is made according to the options of \p ht
* \param[out] out_kv Pointer to the inserted KV
* or pointer to the KV that prevented insertion
* or NULL in case of error. Pointers are valid until the next modification of the hash table.
* \return Returns HtRetCode
* or NULL if out of memory. Pointers are valid until the next modification of the hash table.
* \return Returns HT_RC_INSERTED if KV was inserted;
* returns HT_RC_EXISTING if key \p key already exists;
* returns HT_RC_ERROR if out of memory.
*/
RZ_API int Ht_(insert_ex)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value, RZ_OUT RZ_NULLABLE HT_(Kv) **out_kv) {
RZ_API HtRetCode Ht_(insert_ex)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value, RZ_OUT RZ_NULLABLE HT_(Kv) **out_kv) {
rz_return_val_if_fail(ht, HT_RC_ERROR);
return insert_update(ht, key, value, false, out_kv);
}
Expand All @@ -372,9 +376,10 @@ RZ_API bool Ht_(update)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TY
* \param value KV value; copy is made according to the options of \p ht
* \param[out] out_kv Pointer to the inserted/updated KV or NULL in case of error.
* Pointers are valid until the next modification of the hash table.
* \return Returns HtRetCode
* \return Returns HT_RC_INSERTED/HT_RC_UPDATED if KV was inserted/updated;
* returns HT_RC_ERROR if out of memory.
*/
RZ_API int Ht_(update_ex)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value, RZ_OUT RZ_NULLABLE HT_(Kv) **out_kv) {
RZ_API HtRetCode Ht_(update_ex)(RZ_NONNULL HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value, RZ_OUT RZ_NULLABLE HT_(Kv) **out_kv) {
rz_return_val_if_fail(ht, HT_RC_ERROR);
return insert_update(ht, key, value, true, out_kv);
}
Expand Down

0 comments on commit 9b1d238

Please sign in to comment.