cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=701f7b073761a19acb0ff37ef8ab7d6bda6d34b3

commit 701f7b073761a19acb0ff37ef8ab7d6bda6d34b3
Author: Srivardhan Hebbar <sri.heb...@samsung.com>
Date:   Mon Dec 22 15:08:41 2014 +0100

    eina: add an example to demonstrate different eina insert and sort 
functions.
    
    Summary:
    While going through eina for understanding, wrote  a program to understand
    he differences between different eina inarray functions. Thought, this might
    be useful for others too, so adding the same.
    
    Signed-off-by: Srivardhan Hebbar <sri.heb...@samsung.com>
    
    Reviewers: devilhorns
    
    Subscribers: cedric
    
    Differential Revision: https://phab.enlightenment.org/D1803
    
    Signed-off-by: Cedric BAIL <ced...@osg.samsung.com>
---
 doc/eina_examples.dox               |  2 ++
 src/examples/eina/.gitignore        |  1 +
 src/examples/eina/Makefile.am       |  2 ++
 src/examples/eina/Makefile.examples |  1 +
 src/examples/eina/eina_inarray_03.c | 63 +++++++++++++++++++++++++++++++++++++
 src/lib/eina/eina_inarray.h         | 32 +++++++++++++++++++
 6 files changed, 101 insertions(+)

diff --git a/doc/eina_examples.dox b/doc/eina_examples.dox
index 95f64fd..33e83de 100644
--- a/doc/eina_examples.dox
+++ b/doc/eina_examples.dox
@@ -17,6 +17,7 @@
  * @li @ref eina_hash_08.c
  * @li @ref eina_inarray_01.c
  * @li @ref eina_inarray_02.c
+ * @li @ref eina_inarray_03.c
  * @li @ref eina_inlist_01.c
  * @li @ref eina_inlist_02.c
  * @li @ref eina_inlist_03.c
@@ -73,6 +74,7 @@
  * @example eina_hash_08.c
  * @example eina_inarray_01.c
  * @example eina_inarray_02.c
+ * @example eina_inarray_03.c
  * @example eina_inlist_01.c
  * @example eina_inlist_02.c
  * @example eina_inlist_03.c
diff --git a/src/examples/eina/.gitignore b/src/examples/eina/.gitignore
index d744655..b35df8f 100644
--- a/src/examples/eina/.gitignore
+++ b/src/examples/eina/.gitignore
@@ -14,6 +14,7 @@
 /eina_hash_08
 /eina_inarray_01
 /eina_inarray_02
+/eina_inarray_03
 /eina_inlist_01
 /eina_inlist_02
 /eina_inlist_03
diff --git a/src/examples/eina/Makefile.am b/src/examples/eina/Makefile.am
index 46fa925..227dba9 100644
--- a/src/examples/eina/Makefile.am
+++ b/src/examples/eina/Makefile.am
@@ -46,6 +46,7 @@ eina_value_02.c \
 eina_value_03.c \
 eina_inarray_01.c \
 eina_inarray_02.c \
+eina_inarray_03.c \
 eina_magic_01.c \
 eina_xattr_01.c \
 eina_xattr_02.c
@@ -90,6 +91,7 @@ eina_value_02 \
 eina_value_03 \
 eina_inarray_01 \
 eina_inarray_02 \
+eina_inarray_03 \
 eina_xattr_01 \
 eina_xattr_02
 
diff --git a/src/examples/eina/Makefile.examples 
b/src/examples/eina/Makefile.examples
index 928dae4..e6614de 100644
--- a/src/examples/eina/Makefile.examples
+++ b/src/examples/eina/Makefile.examples
@@ -17,6 +17,7 @@ EXAMPLES= eina_accessor_01 \
           eina_hash_08 \
           eina_inarray_01 \
           eina_inarray_02 \
+          eina_inarray_03 \
           eina_inlist_01 \
           eina_inlist_02 \
           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 0000000..f0be8fd
--- /dev/null
+++ b/src/examples/eina/eina_inarray_03.c
@@ -0,0 +1,63 @@
+//Compile with:
+//gcc -g eina_inarray_03.c -o eina_inarray_03 `pkg-config --cflags --libs eina`
+
+#include <Eina.h>
+
+int
+cmp(const void *a, const void *b)
+{
+   return *(int*)a > *(int*)b;
+}
+
+int main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
+{
+   Eina_Inarray *iarr;
+   char ch, *ch2;
+   int a, *b, pos;
+
+   eina_init();
+   iarr = eina_inarray_new(sizeof(int), 0);
+
+   a = 1;
+   eina_inarray_push(iarr, &a);
+   a = 9;
+   eina_inarray_push(iarr, &a);
+   a = 6;
+   eina_inarray_push(iarr, &a);
+   a = 4;
+   eina_inarray_push(iarr, &a);
+   a = 10;
+   eina_inarray_push(iarr, &a);
+
+   printf("Inline array of integers with %d elements:\n", 
eina_inarray_count(iarr));
+   EINA_INARRAY_FOREACH(iarr, b)
+     printf("int: %d(pointer: %p)\n", *b, b);
+
+   a = 8;
+   eina_inarray_insert(iarr, &a, cmp);
+   printf("Inserting %d to inline array using eina_inarray_insert.\n", a);
+   EINA_INARRAY_FOREACH(iarr, b)
+     printf("int: %d(pointer: %p)\n", *b, b);
+
+   eina_inarray_remove(iarr, &a);
+   printf("Removed %d from inline array using eina_inarray_remove.\n", a);
+   EINA_INARRAY_FOREACH(iarr, b)
+     printf("int: %d(pointer: %p)\n", *b, b);
+
+   eina_inarray_insert_sorted(iarr, &a, cmp);
+   printf("Inserting %d to inline array using 
eina_inarray_insert_sorted.\n",a);
+   EINA_INARRAY_FOREACH(iarr, b)
+     printf("int: %d(pointer: %p)\n", *b, b);
+
+   printf("Position of element %d in the inline array is %d\n", a, 
eina_inarray_search(iarr, &a, cmp));
+
+   eina_inarray_sort(iarr, cmp);
+   printf("Sorted inline array:\n");
+   EINA_INARRAY_FOREACH(iarr, b)
+     printf("int: %d(pointer: %p)\n", *b, b);
+
+   printf("Position of element %d in the sorted inline array is %d\n", a, 
eina_inarray_search_sorted(iarr, &a, cmp));
+
+   eina_inarray_free(iarr);
+   eina_shutdown();
+}
diff --git a/src/lib/eina/eina_inarray.h b/src/lib/eina/eina_inarray.h
index 34e7380..2f95665 100644
--- a/src/lib/eina/eina_inarray.h
+++ b/src/lib/eina/eina_inarray.h
@@ -149,6 +149,38 @@
  */
 
 /**
+ * @page eina_inarray_example_03 Eina inline array insert, sort and search
+ * @dontinclude eina_inarray_03.c
+ *
+ * This example creates an inline array of integers, and demonstrates the
+ * difference between eina_inarray_insert and eina_inarray_sort, and
+ * eina_inarray_search and eina_inarray_search_sort.
+ * @ref eina_inarray_example_01.
+ *
+ * We start with some variable declarations and eina initialization:
+ * @skip int
+ * @until eina_init
+ *
+ * We then create the array much like we did on @ref eina_inarray_example_01 :
+ * @until inarray_new
+ *
+ * We then add element using eina_inarray_insert and print. Then remove that
+ * element and add again using eina_inarray_insert_sorted and prints. This
+ * shows the 2 different positions the elment gets added. Then searches an
+ * element in the unsorted array using eina_inarray_search, then sorts the
+ * array and then searches the same element using eina_inarray_search_sorted.
+ * @until }
+ *
+ * The source for this example: @ref eina_inarray_03_c
+ */
+
+/**
+ * @page eina_inarray_03_c eina_inarray_03.c
+ * @include eina_inarray_03.c
+ * @example eina_inarray_03.c
+ */
+
+/**
  * @defgroup Eina_Inline_Array_Group Inline Array
  * @ingroup Eina_Containers_Group
  * @since 1.2

-- 


Reply via email to