TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcstatist
sort.c
Go to the documentation of this file.
1
4
/*****************************************************************************/
5
#include "tpcclibConfig.h"
6
/*****************************************************************************/
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <math.h>
10
#include <string.h>
11
/*****************************************************************************/
12
#include "
tpcextensions.h
"
13
/*****************************************************************************/
14
#include "
tpcstatist.h
"
15
/*****************************************************************************/
16
17
/*****************************************************************************/
19
/* Local functions */
20
static
int
statIntCompAsc(
const
void
*i,
const
void
*j)
21
{
22
return
( *(
int
*)i - *(
int
*)j);
23
}
24
static
int
statIntCompDesc(
const
void
*i,
const
void
*j)
25
{
26
return
( *(
int
*)j - *(
int
*)i);
27
}
28
static
int
statUnsignedCompAsc(
const
void
*i,
const
void
*j)
29
{
30
const
unsigned
int
*ui = (
const
unsigned
int
*)i;
31
const
unsigned
int
*uj = (
const
unsigned
int
*)j;
32
if
(*ui<*uj)
return
(-1);
33
else
if
(*ui>*uj)
return
(+1);
34
else
return
(0);
35
}
36
static
int
statUnsignedCompDesc(
const
void
*i,
const
void
*j)
37
{
38
const
unsigned
int
*ui = (
const
unsigned
int
*)i;
39
const
unsigned
int
*uj = (
const
unsigned
int
*)j;
40
if
(*ui<*uj)
return
(+1);
41
else
if
(*ui>*uj)
return
(-1);
42
else
return
(0);
43
}
44
static
int
statDoubleCompAsc(
const
void
*i,
const
void
*j)
45
{
46
const
double
*di = (
const
double
*)i;
47
const
double
*dj = (
const
double
*)j;
48
return
(*di > *dj) - (*di < *dj);
49
}
50
static
int
statDoubleCompDesc(
const
void
*i,
const
void
*j)
51
{
52
const
double
*di = (
const
double
*)i;
53
const
double
*dj = (
const
double
*)j;
54
return
(*di < *dj) - (*di > *dj);
55
}
57
/*****************************************************************************/
58
59
/*****************************************************************************/
63
void
statSortInt
(
65
int
*data,
67
unsigned
int
n,
69
int
order
70
) {
71
if
(n<2 || data==NULL)
return
;
72
if
(order==0) qsort(data, n,
sizeof
(
int
), statIntCompAsc);
73
else
qsort(data, n,
sizeof
(
int
), statIntCompDesc);
74
}
75
/*****************************************************************************/
76
77
/*****************************************************************************/
81
void
statSortUnsigned
(
83
unsigned
int
*data,
85
unsigned
int
n,
87
int
order
88
) {
89
if
(n<2 || data==NULL)
return
;
90
if
(order==0) qsort(data, n,
sizeof
(
unsigned
int
), statUnsignedCompAsc);
91
else
qsort(data, n,
sizeof
(
unsigned
int
), statUnsignedCompDesc);
92
}
93
/*****************************************************************************/
94
95
/*****************************************************************************/
99
void
statSortDouble
(
101
double
*data,
103
unsigned
int
n,
105
int
order
106
) {
107
if
(n<2 || data==NULL)
return
;
108
if
(order==0) qsort(data, n,
sizeof
(
double
), statDoubleCompAsc);
109
else
qsort(data, n,
sizeof
(
double
), statDoubleCompDesc);
110
}
111
/*****************************************************************************/
112
113
/*****************************************************************************/
statSortUnsigned
void statSortUnsigned(unsigned int *data, unsigned int n, int order)
Definition
sort.c:81
statSortInt
void statSortInt(int *data, unsigned int n, int order)
Definition
sort.c:63
statSortDouble
void statSortDouble(double *data, unsigned int n, int order)
Definition
sort.c:99
tpcextensions.h
Header file for library libtpcextensions.
tpcstatist.h
Header file for libtpcstatist.
Generated on
for TPCCLIB by
1.17.0