TSG-13500 tsg-service-chaining-engine扫描策略

This commit is contained in:
luwenpeng
2023-02-06 10:34:23 +08:00
parent 72ba473aa5
commit 450d9ab0f2
23 changed files with 2253 additions and 11 deletions

63
common/src/utils.cpp Normal file
View 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];
}