CountInRange
Counts the number of elements in a specific range in a vector.
If the vector element satisfies lowerBound < src[n] < upperBound, pCounts = pCounts + 1.
The function interface declaration is as follows:
HmppResult HMPPS_CountInRange_32s(const int32_t *src, int32_t len, int32_t *counts, int32_t lowerBound, int32_t upperBound);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the source vector |
The value cannot be NULL. |
Input |
len |
Vector length |
(0, INT_MAX] |
Input |
counts |
Pointer to the statistics result |
The value cannot be NULL. |
Output |
lowerBound |
Lower bound of the range |
[INT_MIN, INT_MAX] |
Input |
upperBound |
Upper bound of the range |
[INT_MIN, 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 src or counts is NULL. |
HMPP_STS_SIZE_ERR |
The value of len is less than or equal to 0. |
Example
#define BUFFER_SIZE_T 10
void CountInRangeExample(void)
{
int32_t src[BUFFER_SIZE_T] = {3, 5, 9, 9, 11, 10, 0, -7, -3, 1};
int32_t lower =0;
int32_t upper =10;
int32_t count;
HmppResult result = HMPPS_CountInRange_32s(src, BUFFER_SIZE_T, &count, lower, upper);
printf("result = %d ", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
printf("countInRange = %d\n", count);
}
Output:
result = 0 countInRange = 5