Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
HeapToplistTest.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Bernd Machenschalk
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20/**
21 * \file
22 * \ingroup lalpulsar_bin_Fstatistic
23 * \author Bernd Machenschalk
24 */
25
26#include <stdio.h>
27#include <stdlib.h>
28
29#include <lal/HeapToplist.h>
30
31#define elem_t float
32
33static int smaller( const void *a, const void *b )
34{
35 if ( *( ( const elem_t * )a ) < * ( ( const elem_t * )b ) ) {
36 return ( 1 );
37 } else if ( *( ( const elem_t * )a ) > *( ( const elem_t * )b ) ) {
38 return ( -1 );
39 } else {
40 return ( 0 );
41 }
42}
43
44static void print_elem( void *e )
45{
46 printf( "%f ", *( ( elem_t * )e ) );
47}
48
49int main( int argc, char **argv )
50{
52 int i, n, m;
53 toplist_t *l;
54
55 if ( argc < 2 ) {
56 n = 20;
57 } else {
58 n = atoi( argv[1] );
59 }
60
61 if ( argc < 3 ) {
62 m = 10;
63 } else {
64 m = atoi( argv[2] );
65 }
66
67 create_toplist( &l, m, sizeof( elem_t ), smaller );
68 for ( i = 0; i < n; i++ ) {
69 elem = rand() / ( double )RAND_MAX;
72 printf( "\n" );
73 }
76 printf( "\n" );
79 printf( "\n" );
80 free_toplist( &l );
81}
int create_toplist(toplist_t **list, size_t length, size_t size, int(*smaller)(const void *, const void *))
Definition: HeapToplist.c:101
void free_toplist(toplist_t **list)
Definition: HeapToplist.c:139
void qsort_toplist(toplist_t *list, int(*compare)(const void *, const void *))
Definition: HeapToplist.c:241
void qsort_toplist_r(toplist_t *list, int(*compare)(const void *, const void *))
Definition: HeapToplist.c:249
int insert_into_toplist(toplist_t *list, void *element)
Definition: HeapToplist.c:151
void go_through_toplist(toplist_t *list, void(*handle)(void *))
Definition: HeapToplist.c:177
int main(int argc, char **argv)
#define elem_t
static void print_elem(void *e)
static int smaller(const void *a, const void *b)
int l
double e
static const INT4 m
static const INT4 a
n