dfe219b649
wireshark
48 lines
912 B
C
48 lines
912 B
C
#include <stdio.h>
|
|
#include <limits.h>
|
|
#include "ucore/val_str.h"
|
|
#include "ucore/saturating_math.h"
|
|
|
|
|
|
const char *uc_vs_search(unsigned int val, const struct UCValStr *array)
|
|
{
|
|
const char *found = NULL;
|
|
|
|
while (array->str) {
|
|
if (array->val == val) {
|
|
found = array->str;
|
|
break;
|
|
}
|
|
array++;
|
|
}
|
|
|
|
return found;
|
|
}
|
|
|
|
const char *uc_vs_bsearch(unsigned int val,
|
|
const struct UCValStr *array,
|
|
size_t array_len)
|
|
{
|
|
size_t i = array_len;
|
|
const struct UCValStr *start = array;
|
|
|
|
while (i != 0) {
|
|
const struct UCValStr *curr;
|
|
curr = start + i / 2;
|
|
|
|
if (curr->val == val) {
|
|
return curr->str;
|
|
}
|
|
|
|
if (curr->val < val) {
|
|
start = curr + 1;
|
|
i--;
|
|
}
|
|
|
|
i = i / 2;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|