blob: 14aa2135f053cf042e5a183682a89c9d61279786 (
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
40
41
42
43
|
/*
* Copyright 1997, Regents of the University of Minnesota
*
* bucketsort.c
*
* This file contains code that implement a variety of counting sorting
* algorithms
*
* Started 7/25/97
* George
*
* $Id: bucketsort.c,v 1.1 2003/07/16 15:55:00 karypis Exp $
*
*/
#include <metis.h>
/*************************************************************************
* This function uses simple counting sort to return a permutation array
* corresponding to the sorted order. The keys are assumed to start from
* 0 and they are positive. This sorting is used during matching.
**************************************************************************/
void BucketSortKeysInc(int n, int max, idxtype *keys, idxtype *tperm, idxtype *perm)
{
int i, ii;
idxtype *counts;
counts = idxsmalloc(max+2, 0, "BucketSortKeysInc: counts");
for (i=0; i<n; i++)
counts[keys[i]]++;
MAKECSR(i, max+1, counts);
for (ii=0; ii<n; ii++) {
i = tperm[ii];
perm[counts[keys[i]]++] = i;
}
free(counts);
}
|