Path: blob/devel/elmergrid/src/metis-5.1.0/libmetis/bucketsort.c
3206 views
/*1* Copyright 1997, Regents of the University of Minnesota2*3* bucketsort.c4*5* This file contains code that implement a variety of counting sorting6* algorithms7*8* Started 7/25/979* George10*11*/1213#include "metislib.h"14151617/*************************************************************************18* This function uses simple counting sort to return a permutation array19* corresponding to the sorted order. The keys are arsumed to start from20* 0 and they are positive. This sorting is used during matching.21**************************************************************************/22void BucketSortKeysInc(ctrl_t *ctrl, idx_t n, idx_t max, idx_t *keys,23idx_t *tperm, idx_t *perm)24{25idx_t i, ii;26idx_t *counts;2728WCOREPUSH;2930counts = iset(max+2, 0, iwspacemalloc(ctrl, max+2));3132for (i=0; i<n; i++)33counts[keys[i]]++;34MAKECSR(i, max+1, counts);3536for (ii=0; ii<n; ii++) {37i = tperm[ii];38perm[counts[keys[i]]++] = i;39}4041WCOREPOP;42}43444546