TSG-13500 tsg-service-chaining-engine扫描策略
This commit is contained in:
63
common/src/utils.cpp
Normal file
63
common/src/utils.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "log.h"
|
||||
|
||||
void fixed_num_array_init(struct fixed_num_array *array)
|
||||
{
|
||||
memset(array, 0, sizeof(fixed_num_array));
|
||||
array->num = 0;
|
||||
array->size = sizeof(array->elems) / sizeof(array->elems[0]);
|
||||
}
|
||||
|
||||
void fixed_num_array_add_elem(struct fixed_num_array *array, int elem)
|
||||
{
|
||||
if (array->num < array->size)
|
||||
{
|
||||
array->elems[array->num] = elem;
|
||||
array->num++;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("%s: fixed num array add elem too much !!!", LOG_TAG_UTILS);
|
||||
}
|
||||
}
|
||||
|
||||
void fixed_num_array_del_elem(struct fixed_num_array *array, int elem)
|
||||
{
|
||||
for (int i = 0; i < array->num; i++)
|
||||
{
|
||||
if (array->elems[i] == elem)
|
||||
{
|
||||
if (i + 1 != array->size)
|
||||
{
|
||||
memmove(&(array->elems[i]), &(array->elems[i + 1]), sizeof(array->elems[0]) * (array->num - i - 1));
|
||||
}
|
||||
i--;
|
||||
array->num--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int fixed_num_array_count_elem(struct fixed_num_array *array)
|
||||
{
|
||||
if (array)
|
||||
{
|
||||
return array->num;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int fixed_num_array_index_elem(struct fixed_num_array *array, int index)
|
||||
{
|
||||
if (index >= array->num)
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
return array->elems[index];
|
||||
}
|
||||
Reference in New Issue
Block a user