summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorsub.mohanty@samsung.com <sub.mohanty@samsung.com>2019-08-26 08:06:51 -0400
committerMike Blumenkrantz <zmike@samsung.com>2019-08-26 08:31:08 -0400
commit5bd95c9850df0fa914dde04761065515b9d3f7e4 (patch)
tree1fffb3ff4e1cf24361f16db00333d068c86b85bb /src/lib/eina
parentc6b52d4f09841e24f03150c457705ffe57b320db (diff)
eina/array: added eina_array_find() api to eina_array.
Summary: updated test suite for testing the api. Reviewers: zmike, Hermet, cedric, segfaultxavi Reviewed By: zmike, segfaultxavi Subscribers: segfaultxavi, ProhtMeyhet, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9734
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_array.h17
-rw-r--r--src/lib/eina/eina_inline_array.x18
2 files changed, 35 insertions, 0 deletions
diff --git a/src/lib/eina/eina_array.h b/src/lib/eina/eina_array.h
index 09d8290..c6e62ad 100644
--- a/src/lib/eina/eina_array.h
+++ b/src/lib/eina/eina_array.h
@@ -412,6 +412,23 @@ static inline unsigned int eina_array_count_get(const Eina_Array *array) EINA_AR
412static inline unsigned int eina_array_count(const Eina_Array *array) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT; 412static inline unsigned int eina_array_count(const Eina_Array *array) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
413 413
414/** 414/**
415 * @brief Search for the given data in an array.
416 *
417 * @param[in] array The array.
418 * @param[in] data need to be found.
419 * @param[out] out_idx The position of the data in the array if found.
420 * @return EINA_TRUE if found otherwise returns EINA_FALSE.
421 *
422 * This function searches for the data pointer @p data inside @p array, returning @c EINA_TRUE if found.
423 * The exact position where the pointer is found can be retrieved through @p out_idx.
424 * Please note that only the pointer is compared, not the actual data pointed by it.
425 *
426 * @since 1.23
427 */
428static inline Eina_Bool eina_array_find(const Eina_Array *array,
429 const void *data,
430 unsigned int *out_idx) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
431/**
415 * @brief Gets a new iterator associated with an array. 432 * @brief Gets a new iterator associated with an array.
416 * 433 *
417 * @param[in] array The array. 434 * @param[in] array The array.
diff --git a/src/lib/eina/eina_inline_array.x b/src/lib/eina/eina_inline_array.x
index 40a6e0d..f3c11f6 100644
--- a/src/lib/eina/eina_inline_array.x
+++ b/src/lib/eina/eina_inline_array.x
@@ -93,6 +93,24 @@ eina_array_count(const Eina_Array *array)
93} 93}
94 94
95static inline Eina_Bool 95static inline Eina_Bool
96eina_array_find(const Eina_Array *array, const void *data, unsigned int *out_idx)
97{
98 if (!array) return EINA_FALSE;
99
100 unsigned int i = 0;
101 for (; i < array->count; i++)
102 {
103 if (array->data[i] == data)
104 {
105 if (out_idx) *out_idx = i;
106
107 return EINA_TRUE;
108 }
109 }
110 return EINA_FALSE;
111}
112
113static inline Eina_Bool
96eina_array_foreach(Eina_Array *array, Eina_Each_Cb cb, void *fdata) 114eina_array_foreach(Eina_Array *array, Eina_Each_Cb cb, void *fdata)
97{ 115{
98 void *data; 116 void *data;