File: qsort-test.c

package info (click to toggle)
glib2.0 2.58.3-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, buster-proposed-updates
  • size: 48,744 kB
  • sloc: ansic: 452,196; xml: 16,781; python: 6,149; makefile: 3,776; sh: 1,499; perl: 1,140; cpp: 9
file content (33 lines) | stat: -rw-r--r-- 589 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#undef G_DISABLE_ASSERT
#undef G_LOG_DOMAIN

#include <glib.h>

#define SIZE 100000

guint32 array[SIZE];

static gint
sort (gconstpointer a, gconstpointer b, gpointer user_data)
{
  return *(guint32*)a < *(guint32*)b ? -1 : 1;
}

int
main (int argc, char **argv)
{
  int i;

  for (i = 0; i < SIZE; i++)
    array[i] = g_random_int ();

  g_qsort_with_data (array, SIZE, sizeof (guint32), sort, NULL);

  for (i = 0; i < SIZE - 1; i++)
    g_assert (array[i] <= array[i+1]);

  /* 0 elements is a valid case */
  g_qsort_with_data (array, 0, sizeof (guint32), sort, NULL);

  return 0;
}