summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2023-09-12 16:03:55 +0800
committerchenzizhan <[email protected]>2023-09-12 16:03:55 +0800
commit944214e499b0dde73a5a2f83aa18998671558da6 (patch)
tree1fe795a2ea23504758638425d6669f9852f51ce2
parent8063e9f92a2f0df4cf281279ad329a2357e7f7cf (diff)
fieldstat_find_cubev4.2.1
-rw-r--r--include/fieldstat/fieldstat.h5
-rw-r--r--src/fieldstat.c9
-rw-r--r--test/test_register_and_reset.cpp14
3 files changed, 28 insertions, 0 deletions
diff --git a/include/fieldstat/fieldstat.h b/include/fieldstat/fieldstat.h
index 722b224..9f38845 100644
--- a/include/fieldstat/fieldstat.h
+++ b/include/fieldstat/fieldstat.h
@@ -228,6 +228,11 @@ void fieldstat_get_cells(const struct fieldstat *instance, int cube_id, int metr
*/
struct fieldstat_tag_list *fieldstat_get_shared_tags(const struct fieldstat *instance, int cube_id);
+/*
+ return a cube id corresponding to the shared tags. -1 is returned if the shared tags are not found.
+*/
+int fieldstat_find_cube(const struct fieldstat *instance, const struct fieldstat_tag *shared_tags, size_t n_shared_tags);
+
/*
get the parameter max_n_cell of fieldstat_register_cube
*/
diff --git a/src/fieldstat.c b/src/fieldstat.c
index 89a472b..2e01d10 100644
--- a/src/fieldstat.c
+++ b/src/fieldstat.c
@@ -1172,4 +1172,13 @@ int fieldstat_get_max_cell_id(const struct fieldstat *instance, int cube_id)
int max_id;
(void)cell_manager_dump(cube->cell_manager, &max_id);
return max_id;
+}
+
+int fieldstat_find_cube(const struct fieldstat *instance, const struct fieldstat_tag *shared_tags, size_t n_shared_tags)
+{
+ const struct cube_manager *tag_cube_id_map = instance->shared_tag_cube_manager;
+ struct tag_hash_key *shared_tag_key = tag_hash_key_construct_with_fieldstat_tag(shared_tags, n_shared_tags);
+ int cube_id = cube_manager_find(tag_cube_id_map, shared_tag_key);
+ tag_hash_key_free(shared_tag_key);
+ return cube_id;
} \ No newline at end of file
diff --git a/test/test_register_and_reset.cpp b/test/test_register_and_reset.cpp
index 8df682a..4732f87 100644
--- a/test/test_register_and_reset.cpp
+++ b/test/test_register_and_reset.cpp
@@ -320,6 +320,20 @@ TEST(test_register, register_cube_twice) {
fieldstat_free(instance);
}
+TEST(test_register, find_cube) {
+ struct fieldstat *instance = fieldstat_new();
+ int cube_id = fieldstat_register_cube(instance, &TEST_SHARED_TAG, 1, SAMPLING_MODE_TOPK, 10);
+
+ int find_cube_id = fieldstat_find_cube(instance, &TEST_SHARED_TAG, 1);
+ EXPECT_EQ(cube_id, find_cube_id);
+ int find_cube_id2 = fieldstat_find_cube(instance, &TEST_TAG_DOUBLE, 1);
+ EXPECT_EQ(find_cube_id2, -1);
+
+ fieldstat_free(instance);
+}
+
+// int fieldstat_find_cube(const struct fieldstat *instance, const struct fieldstat_tag *shared_tags, size_t n_shared_tags);
+
int main(int argc, char *argv[])
{
testing::InitGoogleTest(&argc, argv);