Eina inline array insert, sort and search

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. Eina inline array usage.

We start with some variable declarations and eina initialization:

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;
int a, *b;

We then create the array much like we did on Eina inline array usage :

iarr = eina_inarray_new(sizeof(int), 0);

We then add an element using eina_inarray_insert and print. Then remove that element and add it again using eina_inarray_insert_sorted and print. This shows the 2 different positions the element gets added. Then search for 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.

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));
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);
printf("int: %d(pointer: %p)\n", *b, b);
printf("Removed %d from inline array using eina_inarray_remove.\n", a);
printf("int: %d(pointer: %p)\n", *b, b);
printf("Inserting %d to inline array using eina_inarray_insert_sorted.\n",a);
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");
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));
}

The source for this example: eina_inarray_03.c