summaryrefslogtreecommitdiff
path: root/test/utils.cpp
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2024-07-09 11:41:37 +0800
committerchenzizhan <[email protected]>2024-07-09 11:41:37 +0800
commitaff77f35e9a3d8c5c3a315c431b2da9a4e4da39d (patch)
treef45502850763c509d44c4b73f169d72f0ab84bcc /test/utils.cpp
parentde1125112fbbdb63760ffe12871224b201b4e898 (diff)
rename tag->field; tag2key on stack
Diffstat (limited to 'test/utils.cpp')
-rw-r--r--test/utils.cpp148
1 files changed, 74 insertions, 74 deletions
diff --git a/test/utils.cpp b/test/utils.cpp
index b53e4e4..7fa9825 100644
--- a/test/utils.cpp
+++ b/test/utils.cpp
@@ -32,24 +32,24 @@ string gen_rand_string(int len)
/* taglist wrapper */
/* -------------------------------------------------------------------------- */
-Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const struct fieldstat_tag_list *tag_list) {
- tag_list_c.tag = (struct fieldstat_tag *)malloc(sizeof(struct fieldstat_tag) * tag_list->n_tag);
- tag_list_c.n_tag = tag_list->n_tag;
- for (size_t i = 0; i < tag_list->n_tag; i++)
+Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const struct field_list *tag_list) {
+ tag_list_c.field = (struct field *)malloc(sizeof(struct field) * tag_list->n_field);
+ tag_list_c.n_field = tag_list->n_field;
+ for (size_t i = 0; i < tag_list->n_field; i++)
{
// copy the tag_list
- tag_list_c.tag[i].key = strdup(tag_list->tag[i].key);
- tag_list_c.tag[i].type = tag_list->tag[i].type;
- switch (tag_list->tag[i].type)
+ tag_list_c.field[i].key = strdup(tag_list->field[i].key);
+ tag_list_c.field[i].type = tag_list->field[i].type;
+ switch (tag_list->field[i].type)
{
case TAG_INTEGER:
- tag_list_c.tag[i].value_longlong = tag_list->tag[i].value_longlong;
+ tag_list_c.field[i].value_longlong = tag_list->field[i].value_longlong;
break;
case TAG_DOUBLE:
- tag_list_c.tag[i].value_double = tag_list->tag[i].value_double;
+ tag_list_c.field[i].value_double = tag_list->field[i].value_double;
break;
case TAG_CSTRING:
- tag_list_c.tag[i].value_str = strdup(tag_list->tag[i].value_str);
+ tag_list_c.field[i].value_str = strdup(tag_list->field[i].value_str);
break;
default:
break;
@@ -59,84 +59,84 @@ Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const struct fieldstat_ta
Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const char * key, int value)
{
- tag_list_c.tag = (struct fieldstat_tag *)malloc(sizeof(struct fieldstat_tag));
- tag_list_c.n_tag = 1;
- tag_list_c.tag[0].key = strdup(key);
- tag_list_c.tag[0].type = TAG_INTEGER;
- tag_list_c.tag[0].value_longlong = value;
+ tag_list_c.field = (struct field *)malloc(sizeof(struct field));
+ tag_list_c.n_field = 1;
+ tag_list_c.field[0].key = strdup(key);
+ tag_list_c.field[0].type = TAG_INTEGER;
+ tag_list_c.field[0].value_longlong = value;
}
Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const char * key, const char *value)
{
- tag_list_c.tag = (struct fieldstat_tag *)malloc(sizeof(struct fieldstat_tag));
- tag_list_c.n_tag = 1;
- tag_list_c.tag[0].key = strdup(key);
- tag_list_c.tag[0].type = TAG_CSTRING;
- tag_list_c.tag[0].value_str = strdup(value);
+ tag_list_c.field = (struct field *)malloc(sizeof(struct field));
+ tag_list_c.n_field = 1;
+ tag_list_c.field[0].key = strdup(key);
+ tag_list_c.field[0].type = TAG_CSTRING;
+ tag_list_c.field[0].value_str = strdup(value);
}
Fieldstat_tag_list_wrapper::~Fieldstat_tag_list_wrapper() {
- for (size_t i = 0; i < tag_list_c.n_tag; i++) {
- free((char *)tag_list_c.tag[i].key);
- if (tag_list_c.tag[i].type == TAG_CSTRING) {
- free((char *)tag_list_c.tag[i].value_str);
+ for (size_t i = 0; i < tag_list_c.n_field; i++) {
+ free((char *)tag_list_c.field[i].key);
+ if (tag_list_c.field[i].type == TAG_CSTRING) {
+ free((char *)tag_list_c.field[i].value_str);
}
}
- free(tag_list_c.tag);
+ free(tag_list_c.field);
}
Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(std::uniform_int_distribution<int> &dist, int tag_count)
{
- tag_list_c.tag = (struct fieldstat_tag *)malloc(sizeof(struct fieldstat_tag) * tag_count);
- tag_list_c.n_tag = tag_count;
+ tag_list_c.field = (struct field *)malloc(sizeof(struct field) * tag_count);
+ tag_list_c.n_field = tag_count;
std::mt19937 rng(1);
for (int i = 0; i < tag_count; i++)
{
- tag_list_c.tag[i].key = strdup(gen_rand_string(10).c_str());
+ tag_list_c.field[i].key = strdup(gen_rand_string(10).c_str());
int rand_ret = rand() % 3;
if (rand_ret == 0)
{
- tag_list_c.tag[i].type = TAG_INTEGER;
- tag_list_c.tag[i].value_longlong = static_cast<long long>(dist(rng));
+ tag_list_c.field[i].type = TAG_INTEGER;
+ tag_list_c.field[i].value_longlong = static_cast<long long>(dist(rng));
}
else if (rand_ret == 1)
{
- tag_list_c.tag[i].type = TAG_DOUBLE;
- tag_list_c.tag[i].value_double = static_cast<double>(dist(rng)) + 0.5;
+ tag_list_c.field[i].type = TAG_DOUBLE;
+ tag_list_c.field[i].value_double = static_cast<double>(dist(rng)) + 0.5;
}
else
{
- tag_list_c.tag[i].type = TAG_CSTRING;
- tag_list_c.tag[i].value_str = strdup(gen_rand_string(10).c_str());
+ tag_list_c.field[i].type = TAG_CSTRING;
+ tag_list_c.field[i].value_str = strdup(gen_rand_string(10).c_str());
}
}
}
Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper() {
- tag_list_c.tag = NULL;
- tag_list_c.n_tag = 0;
+ tag_list_c.field = NULL;
+ tag_list_c.n_field = 0;
}
Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const Fieldstat_tag_list_wrapper &tag_list_wrapper){
- const struct fieldstat_tag_list *tag_list = tag_list_wrapper.get_c_struct();
- tag_list_c.tag = (struct fieldstat_tag *)malloc(sizeof(struct fieldstat_tag) * tag_list->n_tag);
- tag_list_c.n_tag = tag_list->n_tag;
- for (size_t i = 0; i < tag_list->n_tag; i++)
+ const struct field_list *tag_list = tag_list_wrapper.get_c_struct();
+ tag_list_c.field = (struct field *)malloc(sizeof(struct field) * tag_list->n_field);
+ tag_list_c.n_field = tag_list->n_field;
+ for (size_t i = 0; i < tag_list->n_field; i++)
{
// copy the tag_list
- tag_list_c.tag[i].key = strdup(tag_list->tag[i].key);
- tag_list_c.tag[i].type = tag_list->tag[i].type;
- switch (tag_list->tag[i].type)
+ tag_list_c.field[i].key = strdup(tag_list->field[i].key);
+ tag_list_c.field[i].type = tag_list->field[i].type;
+ switch (tag_list->field[i].type)
{
case TAG_INTEGER:
- tag_list_c.tag[i].value_longlong = tag_list->tag[i].value_longlong;
+ tag_list_c.field[i].value_longlong = tag_list->field[i].value_longlong;
break;
case TAG_DOUBLE:
- tag_list_c.tag[i].value_double = tag_list->tag[i].value_double;
+ tag_list_c.field[i].value_double = tag_list->field[i].value_double;
break;
case TAG_CSTRING:
- tag_list_c.tag[i].value_str = strdup(tag_list->tag[i].value_str);
+ tag_list_c.field[i].value_str = strdup(tag_list->field[i].value_str);
break;
default:
break;
@@ -144,38 +144,38 @@ Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const Fieldstat_tag_list_
}
}
-const struct fieldstat_tag *Fieldstat_tag_list_wrapper::get_tag() const
+const struct field *Fieldstat_tag_list_wrapper::get_tag() const
{
- return tag_list_c.tag;
+ return tag_list_c.field;
}
size_t Fieldstat_tag_list_wrapper::get_tag_count() const
{
- return tag_list_c.n_tag;
+ return tag_list_c.n_field;
}
-const struct fieldstat_tag_list *Fieldstat_tag_list_wrapper::get_c_struct() const
+const struct field_list *Fieldstat_tag_list_wrapper::get_c_struct() const
{
return &tag_list_c;
}
void Fieldstat_tag_list_wrapper::print_tag_list() const
{
- printf("tag_list_c.n_tag: %zu\n", tag_list_c.n_tag);
- for (size_t i = 0; i < tag_list_c.n_tag; i++)
+ printf("tag_list_c.n_field: %zu\n", tag_list_c.n_field);
+ for (size_t i = 0; i < tag_list_c.n_field; i++)
{
- printf("tag_list_c.tag[%zu].key: %s\n", i, tag_list_c.tag[i].key);
- printf("tag_list_c.tag[%zu].type: %d\n", i, (int)tag_list_c.tag[i].type);
- switch (tag_list_c.tag[i].type)
+ printf("tag_list_c.field[%zu].key: %s\n", i, tag_list_c.field[i].key);
+ printf("tag_list_c.field[%zu].type: %d\n", i, (int)tag_list_c.field[i].type);
+ switch (tag_list_c.field[i].type)
{
case TAG_INTEGER:
- printf("tag_list_c.tag[%zu].value_longlong: %lld\n", i, tag_list_c.tag[i].value_longlong);
+ printf("tag_list_c.field[%zu].value_longlong: %lld\n", i, tag_list_c.field[i].value_longlong);
break;
case TAG_DOUBLE:
- printf("tag_list_c.tag[%zu].value_double: %lf\n", i, tag_list_c.tag[i].value_double);
+ printf("tag_list_c.field[%zu].value_double: %lf\n", i, tag_list_c.field[i].value_double);
break;
case TAG_CSTRING:
- printf("tag_list_c.tag[%zu].value_str: %s\n", i, tag_list_c.tag[i].value_str);
+ printf("tag_list_c.field[%zu].value_str: %s\n", i, tag_list_c.field[i].value_str);
break;
default:
break;
@@ -187,20 +187,20 @@ void Fieldstat_tag_list_wrapper::print_tag_list() const
string Fieldstat_tag_list_wrapper::to_string() const
{
string str = "";
- for (size_t i = 0; i < tag_list_c.n_tag; i++)
+ for (size_t i = 0; i < tag_list_c.n_field; i++)
{
- str += tag_list_c.tag[i].key;
+ str += tag_list_c.field[i].key;
str += ":";
- switch (tag_list_c.tag[i].type)
+ switch (tag_list_c.field[i].type)
{
case TAG_INTEGER:
- str += std::to_string(tag_list_c.tag[i].value_longlong);
+ str += std::to_string(tag_list_c.field[i].value_longlong);
break;
case TAG_DOUBLE:
- str += std::to_string(tag_list_c.tag[i].value_double);
+ str += std::to_string(tag_list_c.field[i].value_double);
break;
case TAG_CSTRING:
- str += tag_list_c.tag[i].value_str;
+ str += tag_list_c.field[i].value_str;
break;
default:
break;
@@ -212,30 +212,30 @@ string Fieldstat_tag_list_wrapper::to_string() const
bool Fieldstat_tag_list_wrapper::operator==(const Fieldstat_tag_list_wrapper &tag_list_wrapper) const
{
- const struct fieldstat_tag_list *tag_list = tag_list_wrapper.get_c_struct();
- if (tag_list_c.n_tag != tag_list->n_tag) {
+ const struct field_list *tag_list = tag_list_wrapper.get_c_struct();
+ if (tag_list_c.n_field != tag_list->n_field) {
return false;
}
- for (size_t i = 0; i < tag_list_c.n_tag; i++) {
- if (strcmp((char *)tag_list_c.tag[i].key, (char *)tag_list->tag[i].key) != 0) {
+ for (size_t i = 0; i < tag_list_c.n_field; i++) {
+ if (strcmp((char *)tag_list_c.field[i].key, (char *)tag_list->field[i].key) != 0) {
return false;
}
- if (tag_list_c.tag[i].type != tag_list->tag[i].type) {
+ if (tag_list_c.field[i].type != tag_list->field[i].type) {
return false;
}
- switch (tag_list_c.tag[i].type) {
+ switch (tag_list_c.field[i].type) {
case TAG_INTEGER:
- if (tag_list_c.tag[i].value_longlong != tag_list->tag[i].value_longlong) {
+ if (tag_list_c.field[i].value_longlong != tag_list->field[i].value_longlong) {
return false;
}
break;
case TAG_DOUBLE:
- if (tag_list_c.tag[i].value_double != tag_list->tag[i].value_double) {
+ if (tag_list_c.field[i].value_double != tag_list->field[i].value_double) {
return false;
}
break;
case TAG_CSTRING:
- if (strcmp((char *)tag_list_c.tag[i].value_str, (char *)tag_list->tag[i].value_str) != 0) {
+ if (strcmp((char *)tag_list_c.field[i].value_str, (char *)tag_list->field[i].value_str) != 0) {
return false;
}
break;
@@ -248,7 +248,7 @@ bool Fieldstat_tag_list_wrapper::operator==(const Fieldstat_tag_list_wrapper &ta
Fieldstat_tag_list_wrapper& Fieldstat_tag_list_wrapper::sort_tag_list()
{
- std::sort(tag_list_c.tag, tag_list_c.tag + tag_list_c.n_tag, [](const struct fieldstat_tag &a, const struct fieldstat_tag &b) {
+ std::sort(tag_list_c.field, tag_list_c.field + tag_list_c.n_field, [](const struct field &a, const struct field &b) {
return strcmp((char *)a.key, (char *)b.key) < 0;
});
return *this;