hash table REFACTOR unify reutrn values
diff --git a/src/hash_table.c b/src/hash_table.c
index ec51e28..0e4d512 100644
--- a/src/hash_table.c
+++ b/src/hash_table.c
@@ -686,7 +686,7 @@
int32_t i;
int first_matched = 0, r, ret;
- LY_CHECK_ERR_RET(lyht_find_first(ht, hash, &rec), LOGARG(NULL, hash), LY_EINVAL); /* hash not found */
+ LY_CHECK_ERR_RET(lyht_find_first(ht, hash, &rec), LOGARG(NULL, hash), LY_ENOTFOUND); /* hash not found */
if ((rec->hash == hash) && ht->val_equal(val_p, &rec->val, 1, ht->cb_data)) {
/* even the value matches */
@@ -720,8 +720,7 @@
rec->hits = -1;
} else {
/* value not found even in collisions */
- LOGINT(NULL);
- return LY_EINT;
+ return LY_ENOTFOUND;
}
/* check size & shrink if needed */
diff --git a/src/hash_table.h b/src/hash_table.h
index b6cf9bc..00593fa 100644
--- a/src/hash_table.h
+++ b/src/hash_table.h
@@ -195,7 +195,8 @@
* are pointers, \p val_p must be a pointer to a pointer.
* @param[in] hash Hash of the stored value.
* @param[out] match_p Pointer to the stored value, optional
- * @return LY_ERR value (LY_EEXIST if the value is already present).
+ * @return LY_SUCCESS on success,
+ * @return LY_EEXIST if the value is already present.
*/
LY_ERR lyht_insert(struct hash_table *ht, void *val_p, uint32_t hash, void **match_p);
@@ -210,7 +211,8 @@
* @param[in] hash Hash of the stored value.
* @param[in] resize_val_equal Val equal callback to use for resizing.
* @param[out] match_p Pointer to the stored value, optional
- * @return LY_ERR return value (LY_EEXIST if the value is already present).
+ * @return LY_SUCCESS on success,
+ * @return LY_EEXIST if the value is already present.
*/
LY_ERR lyht_insert_with_resize_cb(struct hash_table *ht, void *val_p, uint32_t hash, values_equal_cb resize_val_equal,
void **match_p);
@@ -222,7 +224,8 @@
* @param[in] value_p Pointer to value to be removed. Be careful, if the values stored in the hash table
* are pointers, \p value_p must be a pointer to a pointer.
* @param[in] hash Hash of the stored value.
- * @return LY_ERR return value (LY_EINVAL if value was not found).
+ * @return LY_SUCCESS on success,
+ * @return LY_ENOTFOUND if value was not found.
*/
LY_ERR lyht_remove(struct hash_table *ht, void *val_p, uint32_t hash);
diff --git a/tests/utests/test_hash_table.c b/tests/utests/test_hash_table.c
index 60d7bcd..12a946e 100644
--- a/tests/utests/test_hash_table.c
+++ b/tests/utests/test_hash_table.c
@@ -148,7 +148,7 @@
assert_int_equal(LY_SUCCESS, lyht_find(ht, &i, i, NULL));
assert_int_equal(LY_SUCCESS, lyht_remove(ht, &i, i));
assert_int_equal(LY_ENOTFOUND, lyht_find(ht, &i, i, NULL));
- assert_int_equal(LY_EINVAL, lyht_remove(ht, &i, i));
+ assert_int_equal(LY_ENOTFOUND, lyht_remove(ht, &i, i));
logbuf_assert("Invalid argument hash (lyht_remove()).");
lyht_free(ht);
@@ -190,7 +190,7 @@
/* removing not present data should fail */
for (i = 0; i < 2; ++i) {
logbuf_clean();
- assert_int_equal(LY_EINVAL, lyht_remove(ht, &i, i));
+ assert_int_equal(LY_ENOTFOUND, lyht_remove(ht, &i, i));
logbuf_assert("Invalid argument hash (lyht_remove()).");
}
/* removing present data, resize should happened