summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--doc/eina_examples.dox2
-rw-r--r--src/examples/eina/.gitignore1
-rw-r--r--src/examples/eina/Makefile.am2
-rw-r--r--src/examples/eina/Makefile.examples1
-rw-r--r--src/examples/eina/eina_inarray_03.c63
-rw-r--r--src/lib/eina/eina_inarray.h32
6 files changed, 101 insertions, 0 deletions
diff --git a/doc/eina_examples.dox b/doc/eina_examples.dox
index 95f64fd408..33e83de465 100644
--- a/doc/eina_examples.dox
+++ b/doc/eina_examples.dox
@@ -17,6 +17,7 @@
17 * @li @ref eina_hash_08.c 17 * @li @ref eina_hash_08.c
18 * @li @ref eina_inarray_01.c 18 * @li @ref eina_inarray_01.c
19 * @li @ref eina_inarray_02.c 19 * @li @ref eina_inarray_02.c
20 * @li @ref eina_inarray_03.c
20 * @li @ref eina_inlist_01.c 21 * @li @ref eina_inlist_01.c
21 * @li @ref eina_inlist_02.c 22 * @li @ref eina_inlist_02.c
22 * @li @ref eina_inlist_03.c 23 * @li @ref eina_inlist_03.c
@@ -73,6 +74,7 @@
73 * @example eina_hash_08.c 74 * @example eina_hash_08.c
74 * @example eina_inarray_01.c 75 * @example eina_inarray_01.c
75 * @example eina_inarray_02.c 76 * @example eina_inarray_02.c
77 * @example eina_inarray_03.c
76 * @example eina_inlist_01.c 78 * @example eina_inlist_01.c
77 * @example eina_inlist_02.c 79 * @example eina_inlist_02.c
78 * @example eina_inlist_03.c 80 * @example eina_inlist_03.c
diff --git a/src/examples/eina/.gitignore b/src/examples/eina/.gitignore
index d744655a07..b35df8fb52 100644
--- a/src/examples/eina/.gitignore
+++ b/src/examples/eina/.gitignore
@@ -14,6 +14,7 @@
14/eina_hash_08 14/eina_hash_08
15/eina_inarray_01 15/eina_inarray_01
16/eina_inarray_02 16/eina_inarray_02
17/eina_inarray_03
17/eina_inlist_01 18/eina_inlist_01
18/eina_inlist_02 19/eina_inlist_02
19/eina_inlist_03 20/eina_inlist_03
diff --git a/src/examples/eina/Makefile.am b/src/examples/eina/Makefile.am
index 46fa925535..227dba90b1 100644
--- a/src/examples/eina/Makefile.am
+++ b/src/examples/eina/Makefile.am
@@ -46,6 +46,7 @@ eina_value_02.c \
46eina_value_03.c \ 46eina_value_03.c \
47eina_inarray_01.c \ 47eina_inarray_01.c \
48eina_inarray_02.c \ 48eina_inarray_02.c \
49eina_inarray_03.c \
49eina_magic_01.c \ 50eina_magic_01.c \
50eina_xattr_01.c \ 51eina_xattr_01.c \
51eina_xattr_02.c 52eina_xattr_02.c
@@ -90,6 +91,7 @@ eina_value_02 \
90eina_value_03 \ 91eina_value_03 \
91eina_inarray_01 \ 92eina_inarray_01 \
92eina_inarray_02 \ 93eina_inarray_02 \
94eina_inarray_03 \
93eina_xattr_01 \ 95eina_xattr_01 \
94eina_xattr_02 96eina_xattr_02
95 97
diff --git a/src/examples/eina/Makefile.examples b/src/examples/eina/Makefile.examples
index 928dae41d7..e6614de053 100644
--- a/src/examples/eina/Makefile.examples
+++ b/src/examples/eina/Makefile.examples
@@ -17,6 +17,7 @@ EXAMPLES= eina_accessor_01 \
17 eina_hash_08 \ 17 eina_hash_08 \
18 eina_inarray_01 \ 18 eina_inarray_01 \
19 eina_inarray_02 \ 19 eina_inarray_02 \
20 eina_inarray_03 \
20 eina_inlist_01 \ 21 eina_inlist_01 \
21 eina_inlist_02 \ 22 eina_inlist_02 \
22 eina_inlist_03 \ 23 eina_inlist_03 \
diff --git a/src/examples/eina/eina_inarray_03.c b/src/examples/eina/eina_inarray_03.c
new file mode 100644
index 0000000000..f0be8fdf07
--- /dev/null
+++ b/src/examples/eina/eina_inarray_03.c
@@ -0,0 +1,63 @@
1//Compile with:
2//gcc -g eina_inarray_03.c -o eina_inarray_03 `pkg-config --cflags --libs eina`
3
4#include <Eina.h>
5
6int
7cmp(const void *a, const void *b)
8{
9 return *(int*)a > *(int*)b;
10}
11
12int main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
13{
14 Eina_Inarray *iarr;
15 char ch, *ch2;
16 int a, *b, pos;
17
18 eina_init();
19 iarr = eina_inarray_new(sizeof(int), 0);
20
21 a = 1;
22 eina_inarray_push(iarr, &a);
23 a = 9;
24 eina_inarray_push(iarr, &a);
25 a = 6;
26 eina_inarray_push(iarr, &a);
27 a = 4;
28 eina_inarray_push(iarr, &a);
29 a = 10;
30 eina_inarray_push(iarr, &a);
31
32 printf("Inline array of integers with %d elements:\n", eina_inarray_count(iarr));
33 EINA_INARRAY_FOREACH(iarr, b)
34 printf("int: %d(pointer: %p)\n", *b, b);
35
36 a = 8;
37 eina_inarray_insert(iarr, &a, cmp);
38 printf("Inserting %d to inline array using eina_inarray_insert.\n", a);
39 EINA_INARRAY_FOREACH(iarr, b)
40 printf("int: %d(pointer: %p)\n", *b, b);
41
42 eina_inarray_remove(iarr, &a);
43 printf("Removed %d from inline array using eina_inarray_remove.\n", a);
44 EINA_INARRAY_FOREACH(iarr, b)
45 printf("int: %d(pointer: %p)\n", *b, b);
46
47 eina_inarray_insert_sorted(iarr, &a, cmp);
48 printf("Inserting %d to inline array using eina_inarray_insert_sorted.\n",a);
49 EINA_INARRAY_FOREACH(iarr, b)
50 printf("int: %d(pointer: %p)\n", *b, b);
51
52 printf("Position of element %d in the inline array is %d\n", a, eina_inarray_search(iarr, &a, cmp));
53
54 eina_inarray_sort(iarr, cmp);
55 printf("Sorted inline array:\n");
56 EINA_INARRAY_FOREACH(iarr, b)
57 printf("int: %d(pointer: %p)\n", *b, b);
58
59 printf("Position of element %d in the sorted inline array is %d\n", a, eina_inarray_search_sorted(iarr, &a, cmp));
60
61 eina_inarray_free(iarr);
62 eina_shutdown();
63}
diff --git a/src/lib/eina/eina_inarray.h b/src/lib/eina/eina_inarray.h
index 34e7380841..2f95665049 100644
--- a/src/lib/eina/eina_inarray.h
+++ b/src/lib/eina/eina_inarray.h
@@ -149,6 +149,38 @@
149 */ 149 */
150 150
151/** 151/**
152 * @page eina_inarray_example_03 Eina inline array insert, sort and search
153 * @dontinclude eina_inarray_03.c
154 *
155 * This example creates an inline array of integers, and demonstrates the
156 * difference between eina_inarray_insert and eina_inarray_sort, and
157 * eina_inarray_search and eina_inarray_search_sort.
158 * @ref eina_inarray_example_01.
159 *
160 * We start with some variable declarations and eina initialization:
161 * @skip int
162 * @until eina_init
163 *
164 * We then create the array much like we did on @ref eina_inarray_example_01 :
165 * @until inarray_new
166 *
167 * We then add element using eina_inarray_insert and print. Then remove that
168 * element and add again using eina_inarray_insert_sorted and prints. This
169 * shows the 2 different positions the elment gets added. Then searches an
170 * element in the unsorted array using eina_inarray_search, then sorts the
171 * array and then searches the same element using eina_inarray_search_sorted.
172 * @until }
173 *
174 * The source for this example: @ref eina_inarray_03_c
175 */
176
177/**
178 * @page eina_inarray_03_c eina_inarray_03.c
179 * @include eina_inarray_03.c
180 * @example eina_inarray_03.c
181 */
182
183/**
152 * @defgroup Eina_Inline_Array_Group Inline Array 184 * @defgroup Eina_Inline_Array_Group Inline Array
153 * @ingroup Eina_Containers_Group 185 * @ingroup Eina_Containers_Group
154 * @since 1.2 186 * @since 1.2