void ANC::load_index(const char *folder){ ASSERTINFO(folder == NULL || strlen(folder) == 0, "IPP"); ASSERTINFO(ncenter < 0 || d <= 0, "ncenter or d is invalid"); ASSERTINFO(!index_exists(folder), "index not exists or not integrated"); char filename[255] = {'\0'}; FILE *fp; int nci, i, cnt_member, cnt_neighbor; /// load clusters load_cluster(folder); /// allocate space for data innerLB = (DoubleIndex**)malloc(sizeof(DoubleIndex*)*ncenter); for(nci = 0; nci < ncenter; nci++){ innerLB[nci] = NULL; } /// load inner lower bounds sprintf(filename, "%s/%s", folder, FileInnerLB); fp = open_file(filename, "r"); for(nci = 0; nci < ncenter; nci++) { // member points of each cluster fscanf(fp, "%d", &cnt_member); ASSERTINFO(cnt_member != member[nci].size(), "count of lb not match to member points, error"); innerLB[nci] = (DoubleIndex*)malloc(sizeof(DoubleIndex) * cnt_member); for(i = 0; i < cnt_member; i++) { fscanf(fp, " %d %lf", &innerLB[nci][i].id, &innerLB[nci][i].val); } } fclose(fp); /// neighbor clusters sprintf(filename, "%s/%s", folder, FileNeighborCluster); fp = open_file(filename, "r"); for(nci = 0; nci < ncenter; nci++) { // member points of each cluster fscanf(fp, "%d", &cnt_neighbor); vector<int> i_neighbor(cnt_neighbor); for(i = 0; i < cnt_neighbor; i++) { fscanf(fp, " %d", &i_neighbor[i]); } neighbor.push_back(i_neighbor); } fclose(fp); printf("%s\n", filename); ASSERTINFO(neighbor.size() != ncenter, "error: [neighbor] size not match with cluster number"); }
void load_cluster(const char *folder){ ASSERTINFO(ncenter < 0 || d <= 0, "IPP"); /* check existance */ ASSERTINFO(!index_exists(folder), "index not exists or not integrated"); char filename[255] = {'\0'}; FILE *fp; int tempd, cnt_member, di, nci, i; /// allocate space for data centroid = fvec_new(ncenter*d); ASSERTINFO(centroid == NULL, "not enough space to allocate for centroids"); /// load centroid sprintf(filename, "%s/%s", folder, FileCentroid); fp = open_file(filename, "r"); for(nci = 0; nci < ncenter; nci++) { fscanf(fp, "%d", &tempd); for(di = 0; di < d; di++) { // centroids fscanf(fp, " %f", ¢roid[nci*d+di]); } } fclose(fp); /// load members sprintf(filename, "%s/%s", folder, FileMember); fp = open_file(filename, "r"); for(nci = 0; nci < ncenter; nci++) { fscanf(fp, "%d", &cnt_member); ASSERTINFO(cnt_member < 0, "invalid member count, load failed"); vector<int> i_member(cnt_member); for(i = 0; i < cnt_member; i++) { // centroids fscanf(fp, " %d", &i_member[i]); } member[nci] = i_member; } fclose(fp); }
void HBPlus::load_index(const char *folder){ ASSERTINFO(folder == NULL || strlen(folder) == 0, "IPP"); ASSERTINFO(ncenter < 0 || d <= 0, "ncenter or d is invalid"); ASSERTINFO(!index_exists(folder), "index not exists or not integrated"); char filename[255] = {'\0'}; FILE *fp; int nci, i, cnt_member; /// load clusters load_cluster(folder); /// allocate space for data innerLB = (DoubleIndex**)malloc(sizeof(DoubleIndex*)*ncenter); for(nci = 0; nci < ncenter; nci++){ innerLB[nci] = NULL; } /// load inner lower bounds sprintf(filename, "%s/%s", folder, FileInnerLB); fp = open_file(filename, "r"); for(nci = 0; nci < ncenter; nci++) { // member points of each cluster fscanf(fp, "%d", &cnt_member); ASSERTINFO(cnt_member != member[nci].size(), "count of lb not match to member points, error"); innerLB[nci] = (DoubleIndex*)malloc(sizeof(DoubleIndex) * cnt_member); ASSERTINFO(innerLB[nci] == NULL, "Failed to allocate space for inner LB"); for(i = 0; i < cnt_member; i++) { fscanf(fp, " %d %lf", &innerLB[nci][i].id, &innerLB[nci][i].val); } } fclose(fp); }
db_result_t relation_join(void *query_result, void *adt_ptr) { aql_adt_t *adt; db_handle_t *handle; relation_t *left_rel; relation_t *right_rel; relation_t *join_rel; char *name; db_direction_t dir; int i; char *attribute_name; attribute_t *attr; adt = (aql_adt_t *)adt_ptr; handle = (db_handle_t *)query_result; handle->current_row = 0; handle->ncolumns = 0; handle->adt = adt; handle->flags = DB_HANDLE_FLAG_INDEX_STEP; if(AQL_GET_FLAGS(adt) & AQL_FLAG_ASSIGN) { name = adt->relations[0]; dir = DB_STORAGE; } else { name = RESULT_RELATION; dir = DB_MEMORY; } relation_remove(name, 1); relation_create(name, dir); join_rel = relation_load(name); handle->result_rel = join_rel; if(join_rel == NULL) { PRINTF("DB: Failed to create a join relation!\n"); return DB_ALLOCATION_ERROR; } handle->join_rel = handle->result_rel = join_rel; left_rel = handle->left_rel; right_rel = handle->right_rel; handle->left_join_attr = relation_attribute_get(left_rel, adt->attributes[0].name); handle->right_join_attr = relation_attribute_get(right_rel, adt->attributes[0].name); if(handle->left_join_attr == NULL || handle->right_join_attr == NULL) { PRINTF("DB: The attribute (\"%s\") to join on does not exist in both relations\n", adt->attributes[0].name); return DB_RELATIONAL_ERROR; } if(!index_exists(handle->right_join_attr)) { PRINTF("DB: The attribute to join on is not indexed\n"); return DB_INDEX_ERROR; } /* * Define the resulting relation. We start from 1 when counting attributes * because the first attribute is only the one to join, and is not included * by default in the projected attributes. */ for(i = 1; i < AQL_ATTRIBUTE_COUNT(adt); i++) { attribute_name = adt->attributes[i].name; attr = relation_attribute_get(left_rel, attribute_name); if(attr == NULL) { attr = relation_attribute_get(right_rel, attribute_name); if(attr == NULL) { PRINTF("DB: The projection attribute \"%s\" does not exist in any of the relations to join\n", attribute_name); return DB_RELATIONAL_ERROR; } } if(relation_attribute_add(join_rel, dir, attr->name, attr->domain, attr->element_size) == NULL) { PRINTF("DB: Failed to add an attribute to the join relation\n"); return DB_ALLOCATION_ERROR; } handle->ncolumns++; } return generate_join_result(handle); }