我要评分
获取效率
正确性
完整性
易理解

SortRadix

Sorts vectors in ascending or descending order by using the radix sorting algorithm.

The function interface declaration is as follows:
  • Auxiliary functions:

    HmppResult HMPPS_SortRadixInit(int32_t len, HmppDataType dataType, uint8_t **buffer);

    HmppResult HMPPS_SortRadixRelease(uint8_t* buffer);

  • Sorting of integers in ascending order:

    HmppResult HMPPS_SortRadixAscend_8u_I(uint8_t *srcDst, int32_t len, uint8_t* buffer);

    HmppResult HMPPS_SortRadixAscend_16u_I(uint16_t *srcDst, int32_t len, uint8_t* buffer);

    HmppResult HMPPS_SortRadixAscend_16s_I(int16_t *srcDst, int32_t len, uint8_t* buffer);

    HmppResult HMPPS_SortRadixAscend_32u_I(uint32_t *srcDst, int32_t len, uint8_t* buffer);

    HmppResult HMPPS_SortRadixAscend_32s_I(int32_t *srcDst, int32_t len, uint8_t* buffer);

    HmppResult HMPPS_SortRadixAscend_64u_I(uint64_t *srcDst, int32_t len, uint8_t* buffer);

    HmppResult HMPPS_SortRadixAscend_64s_I(int64_t *srcDst, int32_t len, uint8_t* buffer);

  • Sorting of floating-point numbers in ascending order:

    HmppResult HMPPS_SortRadixAscend_32f_I(float *srcDst, int32_t len, uint8_t* buffer);

    HmppResult HMPPS_SortRadixAscend_64f_I(double *srcDst, int32_t len, uint8_t* buffer);

  • Sorting of integers in descending order:

    HmppResult HMPPS_SortRadixDescend_8u_I(uint8_t *srcDst, int32_t len, uint8_t* buffer);

    HmppResult HMPPS_SortRadixDescend_16u_I(uint16_t *srcDst, int32_t len, uint8_t* buffer);

    HmppResult HMPPS_SortRadixDescend_16s_I(int16_t *srcDst, int32_t len, uint8_t* buffer);

    HmppResult HMPPS_SortRadixDescend_32u_I(uint32_t *srcDst, int32_t len, uint8_t* buffer);

    HmppResult HMPPS_SortRadixDescend_32s_I(int32_t *srcDst, int32_t len, uint8_t* buffer);

    HmppResult HMPPS_SortRadixDescend_64u_I(uint64_t *srcDst, int32_t len, uint8_t* buffer);

    HmppResult HMPPS_SortRadixDescend_64s_I(int64_t *srcDst, int32_t len, uint8_t* buffer);

  • Sorting of floating-point numbers in descending order:

    HmppResult HMPPS_SortRadixDescend_32f_I(float *srcDst, int32_t len, uint8_t* buffer);

    HmppResult HMPPS_SortRadixDescend_64f_I(double *srcDst, 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

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 9
void Sort_Example() {
    uint8_t src[BUFFER_SIZE_T] = {255, 0, 254, 0, 253, 1, 252, 2, 251};
    int32_t i;
    uint8_t *buffer;
    HMPPS_SortRadixInit(BUFFER_SIZE_T, HMPP8U, &buffer);
    HmppResult result = HMPPS_SortRadixAscend_8u_I(src, BUFFER_SIZE_T, buffer);
    if (result == HMPP_STS_NO_ERR) {
        printf("result = %d\n", result);
        printf("dst = ");
        for (i = 0; i < BUFFER_SIZE_T; i++) {
            printf("%d ", src[i]);
        }
        printf("\n");
    }
    HMPPS_SortRadixRelease(buffer);
}

Output:

result = 0
dst = 0 0 1 2 251 252 253 254 255