int netloc_lookup_table_remove(struct netloc_dt_lookup_table *ht, const char *key) { unsigned long hashed_key; // JJH : Add hash function hashed_key = 0; return netloc_lookup_table_remove_with_int(ht, key, hashed_key); }
int netloc_dc_append_node(netloc_data_collection_handle_t *handle, netloc_node_t *node) { char *key = NULL; netloc_node_t *cur_node = NULL; unsigned long key_int; /* * Setup the table for the first node */ if(NULL == handle->node_list) { handle->node_list = calloc(1, sizeof(*handle->node_list)); netloc_lookup_table_init(handle->node_list, 1, 0); } /* * Check to see if we have seen this node before */ SUPPORT_CONVERT_ADDR_TO_INT(node->physical_id, handle->network->network_type, key_int); asprintf(&key, "%s", node->physical_id); cur_node = netloc_lookup_table_access_with_int(handle->node_list, key, key_int); if( NULL != cur_node ) { if( NETLOC_NODE_TYPE_INVALID == cur_node->node_type ) { // JJH: We should be able to use 'replace' instead of 'remove' and 'append' // Need to double check ordering. netloc_lookup_table_remove_with_int(handle->node_list, key, key_int); } else { fprintf(stderr, "Warning: A version of this node has already been added to the data set!\n"); fprintf(stderr, "Warning: Support for updating nodes is not yet available\n"); // JJH: Delete the old cached version ? replace it? //json_object_del(handle->node_data_acc, node->physical_id); } } free(key); key = NULL; /* * Add the node to our list */ if( NULL == cur_node ) { cur_node = netloc_dt_node_t_dup(node); cur_node->__uid__ = 0; cur_node->physical_id_int = key_int; asprintf(&key, "%s", node->physical_id); netloc_lookup_table_append_with_int(handle->node_list, key, key_int, cur_node); /* * Encode the data: Physical ID is the key */ json_object_set_new(handle->node_data_acc, node->physical_id, netloc_dt_node_t_json_encode(node)); } else if( NETLOC_NODE_TYPE_INVALID == cur_node->node_type ) { netloc_dt_node_t_copy(node, cur_node); cur_node->__uid__ = 0; cur_node->physical_id_int = key_int; asprintf(&key, "%s", node->physical_id); netloc_lookup_table_append_with_int(handle->node_list, key, key_int, cur_node); /* * Encode the data: Physical ID is the key */ json_object_set_new(handle->node_data_acc, node->physical_id, netloc_dt_node_t_json_encode(node)); } else { /* * Replace the node? * The code below will fix the cache (node_data_acc), but the handle->node_list needs to also be updated. */ //json_object_del(handle->node_data_acc, node->physical_id); //json_object_set_new(handle->node_data_acc, node->physical_id, netloc_dt_node_t_json_encode(node)); return NETLOC_ERROR_NOT_IMPL; } return NETLOC_SUCCESS; }