From f4c06bd8bb9c487b225a92a5c7e0d6c585686ec5 Mon Sep 17 00:00:00 2001 From: mattjala <124107509+mattjala@users.noreply.github.com> Date: Wed, 6 Dec 2023 13:17:52 -0600 Subject: [PATCH] Type info table uses hash of URI (#102) --- src/rest_vol_attr.c | 8 ++++---- src/rest_vol_dataset.c | 43 ++++++++++++++++++----------------------- src/rest_vol_datatype.c | 8 ++++---- src/rest_vol_file.c | 7 ++++--- src/rest_vol_group.c | 8 ++++---- 5 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/rest_vol_attr.c b/src/rest_vol_attr.c index f5422326..4e30ac70 100644 --- a/src/rest_vol_attr.c +++ b/src/rest_vol_attr.c @@ -353,7 +353,7 @@ RV_attr_create(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_ printf("-> Created attribute\n\n"); #endif - if (rv_hash_table_insert(RV_type_info_array_g[H5I_ATTR]->table, (char *)new_attribute, + if (rv_hash_table_insert(RV_type_info_array_g[H5I_ATTR]->table, (char *)new_attribute->URI, (char *)new_attribute) == 0) FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTALLOC, NULL, "Failed to add attribute to type info array"); @@ -756,8 +756,8 @@ RV_attr_open(void *obj, const H5VL_loc_params_t *loc_params, const char *attr_na if ((attribute->u.attribute.acpl_id = H5Pcreate(H5P_ATTRIBUTE_CREATE)) < 0) FUNC_GOTO_ERROR(H5E_PLIST, H5E_CANTCREATE, NULL, "can't create ACPL for attribute"); - if (rv_hash_table_insert(RV_type_info_array_g[H5I_ATTR]->table, (char *)attribute, (char *)attribute) == - 0) + if (rv_hash_table_insert(RV_type_info_array_g[H5I_ATTR]->table, (char *)attribute->URI, + (char *)attribute) == 0) FUNC_GOTO_ERROR(H5E_ATTR, H5E_CANTALLOC, NULL, "Failed to add attribute to type info array"); ret_value = (void *)attribute; @@ -2990,7 +2990,7 @@ RV_attr_close(void *attr, hid_t dxpl_id, void **req) } /* end if */ if (RV_type_info_array_g[H5I_ATTR]) - rv_hash_table_remove(RV_type_info_array_g[H5I_ATTR]->table, (char *)_attr); + rv_hash_table_remove(RV_type_info_array_g[H5I_ATTR]->table, (char *)_attr->URI); if (RV_file_close(_attr->domain, H5P_DEFAULT, NULL) < 0) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTCLOSEOBJ, FAIL, "couldn't close attr domain"); diff --git a/src/rest_vol_dataset.c b/src/rest_vol_dataset.c index c62de081..2af81ae3 100644 --- a/src/rest_vol_dataset.c +++ b/src/rest_vol_dataset.c @@ -286,7 +286,7 @@ RV_dataset_create(void *obj, const H5VL_loc_params_t *loc_params, const char *na if ((new_dataset->u.dataset.space_id = H5Scopy(space_id)) < 0) FUNC_GOTO_ERROR(H5E_DATASPACE, H5E_CANTCOPY, NULL, "failed to copy dataset's dataspace"); - if (rv_hash_table_insert(RV_type_info_array_g[H5I_DATASET]->table, (char *)new_dataset, + if (rv_hash_table_insert(RV_type_info_array_g[H5I_DATASET]->table, (char *)new_dataset->URI, (char *)new_dataset) == 0) FUNC_GOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, NULL, "Failed to add dataset to type info array"); @@ -341,20 +341,17 @@ void * RV_dataset_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t dapl_id, hid_t dxpl_id, void **req) { - RV_object_t *parent = (RV_object_t *)obj; - RV_object_t *dataset = NULL; - H5I_type_t obj_type = H5I_UNINIT; - htri_t search_ret; - void *ret_value = NULL; - loc_info loc_info_out; - size_t path_size = 0; - size_t path_len = 0; - - RV_type_info *type_info = RV_type_info_array_g[H5I_DATASET]; - rv_hash_table_iter_t iterator; - rv_hash_table_iterate(type_info->table, &iterator); - hid_t matching_dspace = H5I_INVALID_HID; - RV_object_t *other_dataset = NULL; + RV_object_t *parent = (RV_object_t *)obj; + RV_object_t *dataset = NULL; + H5I_type_t obj_type = H5I_UNINIT; + htri_t search_ret; + void *ret_value = NULL; + loc_info loc_info_out; + size_t path_size = 0; + size_t path_len = 0; + hid_t matching_dspace = H5I_INVALID_HID; + RV_object_t *other_dataset = NULL; + rv_hash_table_value_t table_value = RV_HASH_TABLE_NULL; #ifdef RV_CONNECTOR_DEBUG printf("-> Received dataset open call with following parameters:\n"); @@ -411,13 +408,10 @@ RV_dataset_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name /* If this is another view of an already-opened dataset, make them share the same dataspace * so that changes to it (e.g. resizes) are visible to both views */ - while (rv_hash_table_iter_has_more(&iterator)) { - other_dataset = (RV_object_t *)rv_hash_table_iter_next(&iterator); - - if (!strcmp(other_dataset->URI, dataset->URI)) { - matching_dspace = other_dataset->u.dataset.space_id; - break; - } + if ((table_value = rv_hash_table_lookup(RV_type_info_array_g[H5I_DATASET]->table, dataset->URI)) != + RV_HASH_TABLE_NULL) { + other_dataset = (RV_object_t *)table_value; + matching_dspace = other_dataset->u.dataset.space_id; } if (matching_dspace != H5I_INVALID_HID) { @@ -453,7 +447,8 @@ RV_dataset_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name FUNC_GOTO_ERROR(H5E_DATASET, H5E_CANTCREATE, NULL, "can't parse dataset's creation properties from JSON representation"); - if (rv_hash_table_insert(RV_type_info_array_g[H5I_DATASET]->table, (char *)dataset, (char *)dataset) == 0) + if (rv_hash_table_insert(RV_type_info_array_g[H5I_DATASET]->table, (char *)dataset->URI, + (char *)dataset) == 0) FUNC_GOTO_ERROR(H5E_DATASET, H5E_CANTALLOC, NULL, "Failed to add dataset to type info array"); ret_value = (void *)dataset; @@ -1724,7 +1719,7 @@ RV_dataset_close(void *dset, hid_t dxpl_id, void **req) } /* end if */ if (RV_type_info_array_g[H5I_DATASET]) - rv_hash_table_remove(RV_type_info_array_g[H5I_DATASET]->table, (char *)_dset); + rv_hash_table_remove(RV_type_info_array_g[H5I_DATASET]->table, (char *)_dset->URI); if (RV_file_close(_dset->domain, H5P_DEFAULT, NULL)) { FUNC_DONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "can't close file"); diff --git a/src/rest_vol_datatype.c b/src/rest_vol_datatype.c index 8413ff6c..49ddc85b 100644 --- a/src/rest_vol_datatype.c +++ b/src/rest_vol_datatype.c @@ -284,7 +284,7 @@ RV_datatype_commit(void *obj, const H5VL_loc_params_t *loc_params, const char *n if (RV_parse_response(response_buffer.buffer, NULL, new_datatype->URI, RV_copy_object_URI_callback) < 0) FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_CANTGET, NULL, "can't parse committed datatype's URI"); - if (rv_hash_table_insert(RV_type_info_array_g[H5I_DATATYPE]->table, (char *)new_datatype, + if (rv_hash_table_insert(RV_type_info_array_g[H5I_DATATYPE]->table, (char *)new_datatype->URI, (char *)new_datatype) == 0) FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, NULL, "Failed to add datatype to type info array"); @@ -423,8 +423,8 @@ RV_datatype_open(void *obj, const H5VL_loc_params_t *loc_params, const char *nam if ((datatype->u.datatype.tcpl_id = H5Pcreate(H5P_DATATYPE_CREATE)) < 0) FUNC_GOTO_ERROR(H5E_PLIST, H5E_CANTCREATE, NULL, "can't create TCPL for datatype"); - if (rv_hash_table_insert(RV_type_info_array_g[H5I_DATATYPE]->table, (char *)datatype, (char *)datatype) == - 0) + if (rv_hash_table_insert(RV_type_info_array_g[H5I_DATATYPE]->table, (char *)datatype->URI, + (char *)datatype) == 0) FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, NULL, "Failed to add datatype to type info array"); ret_value = (void *)datatype; @@ -576,7 +576,7 @@ RV_datatype_close(void *dt, hid_t dxpl_id, void **req) } /* end if */ if (RV_type_info_array_g[H5I_DATATYPE]) - rv_hash_table_remove(RV_type_info_array_g[H5I_DATATYPE]->table, (char *)_dtype); + rv_hash_table_remove(RV_type_info_array_g[H5I_DATATYPE]->table, (char *)_dtype->URI); if (RV_file_close(_dtype->domain, H5P_DEFAULT, NULL) < 0) FUNC_DONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "can't close file"); diff --git a/src/rest_vol_file.c b/src/rest_vol_file.c index 5ee4c474..8c89a8d1 100644 --- a/src/rest_vol_file.c +++ b/src/rest_vol_file.c @@ -266,7 +266,8 @@ RV_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, h RV_parse_server_version) < 0) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTCREATE, NULL, "can't parse server version"); - if (rv_hash_table_insert(RV_type_info_array_g[H5I_FILE]->table, (char *)new_file, (char *)new_file) == 0) + if (rv_hash_table_insert(RV_type_info_array_g[H5I_FILE]->table, (char *)new_file->URI, + (char *)new_file) == 0) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, NULL, "Failed to add file to type info array"); ret_value = (void *)new_file; @@ -433,7 +434,7 @@ RV_file_open(const char *name, unsigned flags, hid_t fapl_id, hid_t dxpl_id, voi if ((file->u.file.fcpl_id = H5Pcreate(H5P_FILE_CREATE)) < 0) FUNC_GOTO_ERROR(H5E_PLIST, H5E_CANTCREATE, NULL, "can't create FCPL for file"); - if (rv_hash_table_insert(RV_type_info_array_g[H5I_FILE]->table, (char *)file, (char *)file) == 0) + if (rv_hash_table_insert(RV_type_info_array_g[H5I_FILE]->table, (char *)file->URI, (char *)file) == 0) FUNC_GOTO_ERROR(H5E_FILE, H5E_CANTALLOC, NULL, "Failed to add file to type info array"); ret_value = (void *)file; @@ -894,7 +895,7 @@ RV_file_close(void *file, hid_t dxpl_id, void **req) } if (RV_type_info_array_g[H5I_FILE]) - rv_hash_table_remove(RV_type_info_array_g[H5I_FILE]->table, (char *)_file); + rv_hash_table_remove(RV_type_info_array_g[H5I_FILE]->table, (char *)_file->URI); RV_free(_file); } diff --git a/src/rest_vol_group.c b/src/rest_vol_group.c index d21014a2..01d06007 100644 --- a/src/rest_vol_group.c +++ b/src/rest_vol_group.c @@ -283,8 +283,8 @@ RV_group_create(void *obj, const H5VL_loc_params_t *loc_params, const char *name if (RV_parse_response(response_buffer.buffer, NULL, new_group->URI, RV_copy_object_URI_callback) < 0) FUNC_GOTO_ERROR(H5E_SYM, H5E_CANTCREATE, NULL, "can't parse new group's URI"); - if (rv_hash_table_insert(RV_type_info_array_g[H5I_GROUP]->table, (char *)new_group, (char *)new_group) == - 0) + if (rv_hash_table_insert(RV_type_info_array_g[H5I_GROUP]->table, (char *)new_group->URI, + (char *)new_group) == 0) FUNC_GOTO_ERROR(H5E_SYM, H5E_CANTALLOC, NULL, "Failed to add group to type info array"); ret_value = (void *)new_group; @@ -438,7 +438,7 @@ RV_group_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, else group->u.group.gapl_id = H5P_GROUP_ACCESS_DEFAULT; - if (rv_hash_table_insert(RV_type_info_array_g[H5I_GROUP]->table, (char *)group, (char *)group) == 0) + if (rv_hash_table_insert(RV_type_info_array_g[H5I_GROUP]->table, (char *)group->URI, (char *)group) == 0) FUNC_GOTO_ERROR(H5E_SYM, H5E_CANTALLOC, NULL, "Failed to add group to type info array"); ret_value = (void *)group; @@ -717,7 +717,7 @@ RV_group_close(void *grp, hid_t dxpl_id, void **req) } /* end if */ if (RV_type_info_array_g[H5I_GROUP]) - rv_hash_table_remove(RV_type_info_array_g[H5I_GROUP]->table, (char *)_grp); + rv_hash_table_remove(RV_type_info_array_g[H5I_GROUP]->table, (char *)_grp->URI); if (RV_file_close(_grp->domain, H5P_DEFAULT, NULL) < 0) { FUNC_DONE_ERROR(H5E_FILE, H5E_CANTCLOSEFILE, FAIL, "can't close file");