中文
注册
我要评分
文档获取效率
文档正确性
内容完整性
文档易理解
在线提单
论坛求助

SortRadixIndex

向量基数排序,包括升序和降序,输出排序后的索引。

函数接口声明如下:
  • 辅助函数:

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

    HmppResult HMPPS_SortRadixIndexRelease(uint8_t* buffer);

  • 整型数的升序排序:

    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);

  • 浮点数的升序排序:

    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);

  • 整型数的降序排序:

    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);

  • 浮点数的降序排序:

    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);

参数

参数名

描述

取值范围

输入/输出

srcDst

指向原址操作向量的指针。

非空。

输入/输出

srcStrideBytes

两个源向量之间的距离,单位字节。

大于等于sizeof(T),其中T为数据类型。

输入

len

向量长度。

(0, INT_MAX]

输入

buffer

指向申请空间的指针。

非空。

输入

dataType

数据类型。

枚举类型HmppDataType。

输入

返回值

  • 成功:返回HMPP_STS_NO_ERR
  • 失败:返回错误码。

错误码

错误码

描述

HMPP_STS_NULL_PTR_ERR

srcDst、buffer中存在空指针。

HMPP_STS_SIZE_ERR

len小于或等于0。

HMPP_STS_DATA_TYPE_ERR

数据类型错误。

HMPP_STS_MALLOC_FAILED

内存申请失败。

示例

#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);
}

运行结果:

result1 = 0
idx1 = 3 1 2 0
result2 = 0
idx2 = 0 1 2 3