---
title: SortRadix
description: "向量基数排序，包含升序和降序。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2300/accel/kunpengaccel_hmpp_06_0172.html
sourcePath: /source/zh/kunpengboostkithistory/2300/accel/kunpengaccel_hmpp_06_0172.html
indexId: 569582dc5a27370e51a0e574391a33845495c94acac8f2e1de9949b0d2ab3cd375
---
# SortRadix

向量基数排序，包含升序和降序。

函数接口声明如下：- 辅助函数：
  HmppResult HMPPS_SortRadixInit(int32_t len, HmppDataType dataType, uint8_t **buffer);

  HmppResult HMPPS_SortRadixRelease(uint8_t* buffer);

- 整型数的升序排序：
  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);

- 浮点数的升序排序：
  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);

- 整型数的降序排序：
  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);

- 浮点数的降序排序：
  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);


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| srcDst | 指向原址操作向量的指针。 | 非空 | 输入/输出 |
| 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 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);
}
```

运行结果：

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