summaryrefslogtreecommitdiff
path: root/tests/heap.c
blob: 2bf6e7d9f896ee652621e03bbe3c912309415470 (plain)
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
34
35
36
37
38
39
#include <telepathy-glib/intset.h>
#include <telepathy-glib/heap.h>

#include <stdlib.h>
#include <time.h>
#include <stdio.h>

static gint comparator_fn (gconstpointer a, gconstpointer b)
{
    return (a < b) ? -1 : (a == b) ? 0 : 1;
}

int
main (int argc,
      char **argv)
{
  TpHeap *heap = tp_heap_new (comparator_fn, NULL);
  guint prev = 0;
  guint i;

  srand (time (NULL));

  for (i=0; i<10000; i++)
    {
      tp_heap_add (heap, GUINT_TO_POINTER (rand ()));
    }

  while (tp_heap_size (heap))
    {
      guint elem = GPOINTER_TO_INT (tp_heap_peek_first (heap));
      g_assert (elem == GPOINTER_TO_UINT (tp_heap_extract_first (heap)));
      g_assert (prev <= elem);
      prev = elem;
    }

  tp_heap_destroy (heap);

  return 0;
}