Rate This Document
Findability
Accuracy
Completeness
Readability

FindNearestOne

Finds the element that is nearest to the specified value in the table. The found element and its index are stored in outVal and outIndex 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(|inVal -table[n]|).

The function interface declaration is as follows:

HmppResult HMPPS_FindNearestOne_16u(uint16_t inVal, uint16_t *outVal, int32_t *outIndex, const uint16_t *table, int32_t tblLen);

Parameters

Parameter

Description

Value Range

Input/Output

inVal

Specified element

(0, UINT16_MAX]

Input

outVal

Value of the result element

(0, UINT16_MAX]

Output

outIndex

Index of the result element

[0, tblLen-1]

Output

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

A null pointer exists in the table.

HMPP_STS_SIZE_ERR

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

Example

#define  BUFFER_SIZE_T 11
void FindNearestOneExample()
{
    uint16_t table[BUFFER_SIZE_T] = {32, 545, 766, 876, 1222, 1334, 1687, 3452, 4556, 32452, 45422};
    uint16_t inVal = 4559;
    uint16_t outVal;
    int32_t outIndex;
    HmppResult result = HMPPS_FindNearestOne_16u(inVal, &outVal, &outIndex, table, BUFFER_SIZE_T );
    if (result == HMPP_STS_NO_ERR) {
        printf("outVal = %d\n", outVal);
        printf("outIndex = %d\n", outIndex);
    }
}

Output:

outVal = 4556
outIndex = 8