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

FindNearest

Finds the set of elements that are nearest to elements in the specified vector/specified vector elements in the table. The found element and its index are stored in outVals and outIndexes of the vector, respectively.

The elements in the table must meet the following condition: table[n] ≤ table[n+1]. By "nearest", it means the value closest to min(|inVals[k] -table[n]|).

The function interface declaration is as follows:

HmppResult HMPPS_FindNearest_16u(const uint16_t *inVals, uint16_t *outVals, int32_t *outIndexes, int32_t len, const uint16_t *table, int32_t tblLen);

Parameters

Parameter

Description

Value Range

Input/Output

inVals

Pointer to the vector containing specified elements

The value cannot be NULL.

Input

outVals

Pointer to the vector containing result elements

The value cannot be NULL.

Output

outIndexes

Pointer to the vector containing indexes of result elements

The value cannot be NULL.

Output

len

Length of the inVals vector

(0, INT_MAX]

Input

table

Points to the monotonic non-decreasing vector table.

The value cannot be NULL.

Input

tblLen

Length of the vector table

(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 table, inVals, outVals, or outIndexes is NULL.

HMPP_STS_SIZE_ERR

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

Example

#define  TABLE_SIZE_T 13
#define  BUFFER_SIZE_T 11
void FindNearestExample()
{
    uint16_t table[TABLE_SIZE_T] = {32, 434, 486, 545, 766, 976, 1222, 1534, 1687, 3452, 8556, 32452, 56422};
    uint16_t inVals[BUFFER_SIZE_T] = {32, 545, 766, 876, 1222, 1334, 1687, 3452, 4556, 32452, 45422};
    uint16_t outVals[BUFFER_SIZE_T];
    int32_t outIndexes[BUFFER_SIZE_T];
    HmppResult result = HMPPS_FindNearest_16u(inVals, outVals, outIndexes, BUFFER_SIZE_T, table, TABLE_SIZE_T);
    if (result == HMPP_STS_NO_ERR) {
        printf("outVals :");
        for (int i = 0; i < BUFFER_SIZE_T; i++) {
            printf(" %d", outVals[i]);
        }
        printf("\n");
        printf("outIndexes:");
        for (int i = 0; i < BUFFER_SIZE_T; i++) {
            printf(" %d", outIndexes[i]);
        }
        printf("\n");
    }
}

Output:

outVals : 32 545 766 976 1222 1222 1687 3452 3452 32452 56422
outIndexes: 0 3 4 5 6 6 8 9 9 11 12