int/float versions of sort() hpsort()


roywang
04-26-2002, 07:13 PM
Hi, all.

Can someone tell me why only the double version
of sort() and hpsort() are given? Can I simply
copy the code and change the function header to
include Vec_IO_INT and Vec_IO_SP to implement
the integer and float versions of sort(), hpsort()?

I am in need of these two new types as my input data
are not always double. It is senseless to convert data types if
the code is generic with respect to datatype.


Roy.

Bill Press
05-01-2002, 02:45 PM
Hello, Roy.

Probably we should have templated the variable type that is sorted, but once we decided to avoid templating in the book (a complicated decision) there was no reason to provide anything except a DP version, since that is all that is used by other recipes.

Yes, in sort(), you can change the Vec_IO_DP to the corresponding int or float array types. You also have to change the type of the variable "a".

Similarly in hpsort(), where the variable "a" is in sift_down().

Good luck!