~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to raster/r.univar/sort.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2004-2007 by the GRASS Development Team
 
3
 *   Author(s): 1998, 1999 Sebastian Cyris
 
4
 *              2007 modified by Soeren Gebbert
 
5
 *
 
6
 *      This program is free software under the GNU General Public
 
7
 *      License (>=v2). Read the file COPYING that comes with GRASS
 
8
 *      for details.
 
9
 *
 
10
 */
 
11
 
 
12
#include "globals.h"
 
13
static void downheap_int(int *array, int n, int k);
 
14
static void downheap_float(float *array, int n, int k);
 
15
static void downheap_double(double *array, int n, int k);
 
16
 
 
17
/* *************************************************************** */
 
18
/* *************************************************************** */
 
19
/* *************************************************************** */
 
20
void downheap_int(int *array, int n, int k)
 
21
{
 
22
    int j, v;
 
23
 
 
24
    v = array[k];
 
25
    while (k <= n / 2) {
 
26
        j = k + k;
 
27
 
 
28
        if (j < n && array[j] < array[j + 1])
 
29
            j++;
 
30
        if (v >= array[j])
 
31
            break;
 
32
 
 
33
        array[k] = array[j];
 
34
        k = j;
 
35
    }
 
36
 
 
37
    array[k] = v;
 
38
}
 
39
 
 
40
/* *************************************************************** */
 
41
/* *************************************************************** */
 
42
/* *************************************************************** */
 
43
void downheap_float(float *array, int n, int k)
 
44
{
 
45
    int j;
 
46
    float v;
 
47
 
 
48
    v = array[k];
 
49
    while (k <= n / 2) {
 
50
        j = k + k;
 
51
 
 
52
        if (j < n && array[j] < array[j + 1])
 
53
            j++;
 
54
        if (v >= array[j])
 
55
            break;
 
56
 
 
57
        array[k] = array[j];
 
58
        k = j;
 
59
    }
 
60
 
 
61
    array[k] = v;
 
62
}
 
63
 
 
64
/* *************************************************************** */
 
65
/* *************************************************************** */
 
66
/* *************************************************************** */
 
67
void downheap_double(double *array, int n, int k)
 
68
{
 
69
    int j;
 
70
    double v;
 
71
 
 
72
    v = array[k];
 
73
    while (k <= n / 2) {
 
74
        j = k + k;
 
75
 
 
76
        if (j < n && array[j] < array[j + 1])
 
77
            j++;
 
78
        if (v >= array[j])
 
79
            break;
 
80
 
 
81
        array[k] = array[j];
 
82
        k = j;
 
83
    }
 
84
 
 
85
    array[k] = v;
 
86
}
 
87
 
 
88
/* *************************************************************** */
 
89
/* ****** heapsort for int arrays of size n ********************** */
 
90
/* *************************************************************** */
 
91
void heapsort_int(int *array, int n)
 
92
{
 
93
    int k, t;
 
94
 
 
95
    --n;
 
96
 
 
97
    for (k = n / 2; k >= 0; k--)
 
98
        downheap_int(array, n, k);
 
99
 
 
100
    while (n > 0) {
 
101
        t = array[0];
 
102
        array[0] = array[n];
 
103
        array[n] = t;
 
104
        downheap_int(array, --n, 0);
 
105
    }
 
106
    return;
 
107
}
 
108
 
 
109
 
 
110
/* *************************************************************** */
 
111
/* ****** heapsort for float arrays of size n ******************** */
 
112
/* *************************************************************** */
 
113
void heapsort_float(float *array, int n)
 
114
{
 
115
    int k;
 
116
    float t;
 
117
 
 
118
    --n;
 
119
 
 
120
    for (k = n / 2; k >= 0; k--)
 
121
        downheap_float(array, n, k);
 
122
 
 
123
    while (n > 0) {
 
124
        t = array[0];
 
125
        array[0] = array[n];
 
126
        array[n] = t;
 
127
        downheap_float(array, --n, 0);
 
128
    }
 
129
    return;
 
130
}
 
131
 
 
132
/* *************************************************************** */
 
133
/* ****** heapsort for double arrays of size n ******************* */
 
134
/* *************************************************************** */
 
135
void heapsort_double(double *array, int n)
 
136
{
 
137
    int k;
 
138
    double t;
 
139
 
 
140
    --n;
 
141
 
 
142
    for (k = n / 2; k >= 0; k--)
 
143
        downheap_double(array, n, k);
 
144
 
 
145
    while (n > 0) {
 
146
        t = array[0];
 
147
        array[0] = array[n];
 
148
        array[n] = t;
 
149
        downheap_double(array, --n, 0);
 
150
    }
 
151
    return;
 
152
}