SortRadixIndex
Sorts vectors in ascending or descending order by using the radix sorting algorithm, and outputs the indexes after sorting.
- Auxiliary functions:
HmppResult HMPPS_SortRadixIndexInit(int32_t len, HmppDataType dataType, uint8_t **buffer);
HmppResult HMPPS_SortRadixIndexRelease(uint8_t* buffer);
- Sorting of integers in ascending order:
HmppResult HMPPS_SortRadixIndexAscend_8u(const uint8_t *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
HmppResult HMPPS_SortRadixIndexAscend_16u(const uint16_t *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
HmppResult HMPPS_SortRadixIndexAscend_16s(const int16_t *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
HmppResult HMPPS_SortRadixIndexAscend_32u(const uint32_t *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
HmppResult HMPPS_SortRadixIndexAscend_32s(const int32_t *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
HmppResult HMPPS_SortRadixIndexAscend_64u(const uint64_t *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
HmppResult HMPPS_SortRadixIndexAscend_64s(const int64_t *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
- Sorting of floating-point numbers in ascending order:
HmppResult HMPPS_SortRadixIndexAscend_32f(const float *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
HmppResult HMPPS_SortRadixIndexAscend_64f(const double *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
- Sorting of integers in descending order:
HmppResult HMPPS_SortRadixIndexDescend_8u(const uint8_t *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
HmppResult HMPPS_SortRadixIndexDescend_16u(const uint16_t *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
HmppResult HMPPS_SortRadixIndexDescend_16s(const int16_t *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
HmppResult HMPPS_SortRadixIndexDescend_32u(const uint32_t *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
HmppResult HMPPS_SortRadixIndexDescend_32s(const int32_t *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
HmppResult HMPPS_SortRadixIndexDescend_64u(const uint64_t *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
HmppResult HMPPS_SortRadixIndexDescend_64s(const int64_t *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
- Sorting of floating-point numbers in descending order:
HmppResult HMPPS_SortRadixIndexDescend_32f(const float *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
HmppResult HMPPS_SortRadixIndexDescend_64f(const double *src, int32_t srcStrideBytes, int32_t *dstIdx, int32_t len, uint8_t* buffer);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
srcDst |
Pointer to the source vector for in-place operations |
The value cannot be NULL. |
Input/Output |
srcStrideBytes |
Distance between two source vectors, in bytes |
The value is greater than or equal to the value obtained by calling the sizeof(T) function. T indicates the data type. |
Input |
len |
Vector length |
(0, INT_MAX] |
Input |
buffer |
Pointer to the allocated space |
The value cannot be NULL. |
Input |
dataType |
Data type |
Enumeration type HmppDataType |
Input |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
The value of srcDst or buffer is NULL. |
HMPP_STS_SIZE_ERR |
The value of len is less than or equal to 0. |
HMPP_STS_DATA_TYPE_ERR |
Incorrect data type |
HMPP_STS_MALLOC_FAILED |
Memory allocation failed. |
Example
#define BUFFER_SIZE_T 4
struct C{
uint8_t key1;
uint8_t key2;
float data;
}C;
void Sort_Example() {
struct C c_array[BUFFER_SIZE_T] = {{0,2,1.0f}, {1,3,2.0f}, {1,4,3.0f}, {8,2,10.0f}};
uint8_t *buffer1,*buffer2;
int32_t idx1[BUFFER_SIZE_T], idx2[BUFFER_SIZE_T];
int32_t i;
HMPPS_SortRadixIndexInit(BUFFER_SIZE_T, HMPP8U, &buffer1);
HmppResult result1 = HMPPS_SortRadixIndexDescend_8u(&c_array[0].key1, sizeof(C), idx1, BUFFER_SIZE_T, buffer1);
if (result1 == HMPP_STS_NO_ERR) {
printf("result1 = %d\n", result1);
printf("idx1 = ");
for (i = 0; i < BUFFER_SIZE_T; i++) {
printf("%d ", idx1[i]);
}
printf("\n");
}
HMPPS_SortRadixIndexRelease(buffer1);
HMPPS_SortRadixIndexInit(BUFFER_SIZE_T, HMPP32F, &buffer2);
HmppResult result2 = HMPPS_SortRadixIndexAscend_32f(&c_array[0].data, sizeof(C), idx2, BUFFER_SIZE_T, buffer2);
if (result2 == HMPP_STS_NO_ERR) {
printf("result2 = %d\n", result2);
printf("idx2 = ");
for (i = 0; i < BUFFER_SIZE_T; i++) {
printf("%d ", idx2[i]);
}
printf("\n");
}
HMPPS_SortRadixIndexRelease(buffer2);
}
Output:
result1 = 0 idx1 = 3 1 2 0 result2 = 0 idx2 = 0 1 2 3