summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2023-11-24 18:51:01 +0800
committerchenzizhan <[email protected]>2023-11-24 18:51:01 +0800
commit04d5d38bf1d1c9c77967cc9f4dac905a45edfc38 (patch)
tree3eee3960b10478deef6fdd447e7a23c021ddf665 /src
parentd0219e918b21fc39ecb567a00b81161bb7387eec (diff)
more readable rearrange_metric_delta
Diffstat (limited to 'src')
-rw-r--r--src/exporter/cjson_exporter.c32
-rw-r--r--src/tags/my_ut_hash.c1
2 files changed, 31 insertions, 2 deletions
diff --git a/src/exporter/cjson_exporter.c b/src/exporter/cjson_exporter.c
index e430f5a..c96ada3 100644
--- a/src/exporter/cjson_exporter.c
+++ b/src/exporter/cjson_exporter.c
@@ -426,7 +426,7 @@ int couple_export_table_find(const struct couple_export_table *tbl, const char *
struct couple_export_table_item *node;
HASH_FIND_STR(tbl->items, json, node);
if (node == NULL) {
- return false;
+ return -1;
}
return node->kv_pair_id;
}
@@ -451,6 +451,36 @@ void couple_export_table_free(struct couple_export_table *tbl)
const struct cellwise_rec_for_export **rearrange_metric_delta(const struct cellwise_rec_for_export *acc, size_t n_acc, const struct cellwise_rec_for_export *delta, size_t n_delta)
{
struct couple_export_table *map = couple_export_table_new(); // todo: 这个map更新放到exporter里,不要每次都new
+ for (int i = 0; i < n_delta; i++) {
+ const char *tag_json = json_writer_unwrap(delta[i].cjson_tags);
+ if (tag_json == NULL) { // tag might be empty, give it a dummy name
+ tag_json = "\anil";
+ }
+ couple_export_table_add(map, tag_json, i);
+ }
+
+ const struct cellwise_rec_for_export **ret = calloc(n_acc, sizeof(struct cellwise_rec_for_export *));
+
+ for (int id_acc = 0; id_acc < n_acc; id_acc++) {
+ const char *tag_str_acc = json_writer_unwrap(acc[id_acc].cjson_tags);
+ if (tag_str_acc == NULL) { // tag might be empty, give it a dummy name
+ tag_str_acc = "\anil";
+ }
+
+ int id_delta = couple_export_table_find(map, tag_str_acc);
+ if (id_delta == -1) {
+ continue;
+ }
+ ret[id_acc] = &delta[id_delta];
+ }
+
+ couple_export_table_free(map);
+ return ret;
+}
+
+const struct cellwise_rec_for_export **rearrange_metric_delta1(const struct cellwise_rec_for_export *acc, size_t n_acc, const struct cellwise_rec_for_export *delta, size_t n_delta)
+{
+ struct couple_export_table *map = couple_export_table_new(); // todo: 这个map更新放到exporter里,不要每次都new
for (int i = 0; i < n_acc; i++) {
const char *tag_json = json_writer_unwrap(acc[i].cjson_tags);
if (tag_json == NULL) { // tag might be empty, give it a dummy name
diff --git a/src/tags/my_ut_hash.c b/src/tags/my_ut_hash.c
index 4038067..0c1f2af 100644
--- a/src/tags/my_ut_hash.c
+++ b/src/tags/my_ut_hash.c
@@ -145,7 +145,6 @@ XXH128_hash_t cal_tag_hash_xxhash128(const struct fieldstat_tag *tag, size_t n_t
for (int i = 0; i < n_tag; i++)
{
- // XXH32_update(&state, (const xxh_u8 *)tag[i].key, strlen(tag[i].key));
XXH3_128bits_update(state, tag[i].key, strlen(tag[i].key));
if (tag[i].type != TAG_CSTRING) { // sizeof(long long) == sizeof(double)