Rate This Document
Findability
Accuracy
Completeness
Readability

SortIndex

Sorts vectors and their indexes in ascending or descending order. If the elements in the vector to be sorted contain the same values, indexes corresponding to those values are not sorted, that is, the sorting algorithm is unstable. For those same values, the index sequence after the sorting is different from that before the sorting.

The function interface declaration is as follows:
  • Sorting of integers in ascending order:

    HmppResult HMPPS_SortIndexAscend_8u_I(uint8_t* srcDst, int32_t dstIdx, int32_t len);

    HmppResult HMPPS_SortIndexAscend_16u_I(uint16_t* srcDst, int32_t dstIdx, int32_t len);

    HmppResult HMPPS_SortIndexAscend_16s_I(int16_t* srcDst, int32_t dstIdx, int32_t len);

    HmppResult HMPPS_SortIndexAscend_32s_I(int32_t* srcDst, int32_t dstIdx, int32_t len);

  • Sorting of floating-point numbers in ascending order:

    HmppResult HMPPS_SortIndexAscend_32f_I(float* srcDst, int32_t dstIdx, int32_t len);

    HmppResult HMPPS_SortIndexAscend_64f_I(double* srcDst, int32_t dstIdx, int32_t len);

  • Sorting of integers in descending order:

    HmppResult HMPPS_SortIndexDescend_8u_I(uint8_t* srcDst, int32_t dstIdx, int32_t len);

    HmppResult HMPPS_SortIndexDescend_16u_I(uint16_t* srcDst, int32_t dstIdx, int32_t len);

    HmppResult HMPPS_SortIndexDescend_16s_I(int16_t* srcDst, int32_t dstIdx, int32_t len);

    HmppResult HMPPS_SortIndexDescend_32s_I(int32_t* srcDst, int32_t dstIdx, int32_t len);

  • Sorting of floating-point numbers in descending order:

    HmppResult HMPPS_SortIndexDescend_32f_I(float* srcDst, int32_t dstIdx, int32_t len);

    HmppResult HMPPS_SortIndexDescend_64f_I(double* srcDst, int32_t dstIdx, int32_t len);

Parameters

Parameter

Description

Value Range

Input/Output

srcDst

Pointer to the source vector for in-place operations

The value cannot be NULL.

Input/Output

dstIdx

Pointer to the index after sorting

The value cannot be NULL.

Output

len

Vector length

(0, INT_MAX]

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 is NULL.

HMPP_STS_SIZE_ERR

The value of len is less than or equal to 0.

Example

#define BUFFER_SIZE_T 9
void Sort_Example() {
    uint8_t src[BUFFER_SIZE_T] = {255, 5, 254, 0, 253, 1, 252, 2, 251};
    int32_t *dstIdx = HMPPS_Malloc_32s(BUFFER_SIZE_T);
    int32_t i;
    HmppResult result = HMPPS_SortAscend_8u_I(src, dstIdx ,BUFFER_SIZE_T);
    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");
        printf("dstIdx = ");
        for (i = 0; i < BUFFER_SIZE_T; i++) {
            printf("%d ", dstIdx[i]);
        }
        printf("\n");
    }
    HMPPS_Free(dstIdx);
}

Output:

result = 0
dst = 0 1 2 5 251 252 253 254 255
dstIdx = 3 5 7 1 8 6 4 2 0