File: heap.c

package info (click to toggle)
telepathy-glib 0.24.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 34,628 kB
  • sloc: ansic: 124,643; xml: 34,410; sh: 11,299; python: 3,520; makefile: 1,727; cpp: 16
file content (41 lines) | stat: -rw-r--r-- 770 bytes parent folder | download | duplicates (4)
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
40
41
#include "config.h"

#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;
}