diff options
| author | chenzizhan <[email protected]> | 2023-08-29 10:56:23 +0800 |
|---|---|---|
| committer | chenzizhan <[email protected]> | 2023-08-29 10:56:23 +0800 |
| commit | b66c1942eb6e51ad689c8d68b8b7aca63a7308ef (patch) | |
| tree | b3827f4679cf03ff5399820bd11924c077dabd3f | |
| parent | 259a3af66f6fc97527786b326236f6e8673846cb (diff) | |
feat: unlimited size cube
| -rw-r--r-- | include/fieldstat/fieldstat.h | 2 | ||||
| -rw-r--r-- | src/fieldstat.c | 7 | ||||
| -rw-r--r-- | src/tags/cell_manager.c | 6 |
3 files changed, 12 insertions, 3 deletions
diff --git a/include/fieldstat/fieldstat.h b/include/fieldstat/fieldstat.h index 8667d27..f634b00 100644 --- a/include/fieldstat/fieldstat.h +++ b/include/fieldstat/fieldstat.h @@ -68,7 +68,7 @@ struct fieldstat *fieldstat_dup(const struct fieldstat *instance); * @param shared_tags: tags that are shared by all cubes in this instance. This is the key of the cube. Cannot be NULL. Must be unique. shared_tags are ordered. * @param n_tag: number of shared tags. * @param mode: sampling mode. Refer to enum sampling_mode. - * @param max_n_cell: max number of cells in each cube. + * @param max_n_cell: max number of cells in each cube. When mode is TOPK, max_n_cell > 0, while in COMPREHENSIVE mode, max_n_cell can be 0, meaning that there is no limit. * @return cube id, if success; otherwise, return -1. Fail only when `instance` == NULL. the uniqueness of shared_tags is not checked, user should guarantee that shared_tags are unique. */ int fieldstat_register_cube(struct fieldstat *instance, const struct fieldstat_tag *shared_tags, size_t n_tag, enum sampling_mode mode, size_t max_n_cell); diff --git a/src/fieldstat.c b/src/fieldstat.c index 07142a3..a0ccdbb 100644 --- a/src/fieldstat.c +++ b/src/fieldstat.c @@ -273,6 +273,13 @@ int fieldstat_register_cube(struct fieldstat *instance, const struct fieldstat_t shared_tags = NULL; n_tag = 0; } + if (mode == SAMPLING_MODE_TOPK && max_n_cell == 0) { + return -1; + } + if (max_n_cell == 0) { + max_n_cell = INTMAX_MAX; + } + struct fs_cube *cube = fieldstat_cube_new(shared_tags, n_tag, mode, max_n_cell); int cube_id = fieldstat_append_cube_to_instance(instance, cube); diff --git a/src/tags/cell_manager.c b/src/tags/cell_manager.c index a10c5e2..9dfe01d 100644 --- a/src/tags/cell_manager.c +++ b/src/tags/cell_manager.c @@ -44,8 +44,10 @@ struct cell_manager *cell_manager_new_without_map(enum sampling_mode sampling_mo cell_manager->next_cell_id = 0; cell_manager->id_tag_array_len = max_cell_num; - cell_manager->id_tag_array = calloc(max_cell_num, sizeof(struct tag_hash_key *)); - assert(cell_manager->id_tag_array != NULL); + if (cell_manager->id_tag_array_len > 4096) { // support dynamic size cube (especially when max_max_num is unlimited) + cell_manager->id_tag_array_len = 4096; + } + cell_manager->id_tag_array = calloc(cell_manager->id_tag_array_len, sizeof(struct tag_hash_key *)); cell_manager->max_cell_id = -1; return cell_manager; |
