T_KRIndex* kr_create_index(T_KRDB *krdb, T_KRTable *krtable, int index_id, char *index_name, E_KRIndexType index_type, int index_field_id, int sort_field_id) { T_KRIndex *ptIndex = (T_KRIndex *)kr_calloc(sizeof(T_KRIndex)); if (ptIndex == NULL) { fprintf(stderr, "kr_calloc ptIndex failed!\n"); return NULL; } ptIndex->iIndexId = index_id; strncpy(ptIndex->caIndexName, index_name, sizeof(ptIndex->caIndexName)); ptIndex->eIndexType = index_type; ptIndex->iIndexFieldId = index_field_id; ptIndex->iSortFieldId = sort_field_id; E_KRType index_field_type = krtable->ptFieldDef[index_field_id].type; KRHashFunc hash_func = (KRHashFunc )kr_get_hash_func(index_field_type); KREqualFunc equal_func = (KREqualFunc )kr_get_equal_func(index_field_type); switch(ptIndex->eIndexType) { /* table-index build with two steps: * 1.create new hashtable; * 2.add index to the table-index list */ case KR_INDEXTYPE_TABLE: { ptIndex->pHashTable = kr_hashtable_new(hash_func, equal_func); kr_list_add_tail(krtable->pIndexList, ptIndex); break; } /* db-index build will be a little bit complicated... * Check whether db-index with same index_id exists? * exists: link hashtable to the exist one, add to table-index list; * not: create an new hashtable, add to table-index and db-index list; */ case KR_INDEXTYPE_DB: { T_KRIndex *ptDBIndex = kr_get_db_index(krdb, index_id); if (ptDBIndex != NULL) { ptIndex->pHashTable = ptDBIndex->pHashTable; kr_list_add_tail(krtable->pIndexList, ptIndex); } else { ptIndex->pHashTable = kr_hashtable_new(hash_func, equal_func); kr_list_add_tail(krtable->pIndexList, ptIndex); kr_list_add_tail(krdb->pIndexList, ptIndex); } break; } default: { fprintf(stderr, "Unknown index type[%c]\n", ptIndex->eIndexType); return NULL; } } return ptIndex; }
T_KRIndex* kr_index_create(T_KRDB *ptDB, int iIndexId, char *psIndexName, E_KRType eIndexFieldType) { T_KRIndex *ptIndex = (T_KRIndex *)kr_calloc(sizeof(T_KRIndex)); if (ptIndex == NULL) { fprintf(stderr, "kr_calloc ptIndex failed!\n"); return NULL; } ptIndex->ptDB = ptDB; ptIndex->iIndexId = iIndexId; strncpy(ptIndex->caIndexName, psIndexName, sizeof(ptIndex->caIndexName)); ptIndex->eIndexFieldType = eIndexFieldType; KRHashFunc hash_func = (KRHashFunc )kr_get_hash_func(eIndexFieldType); KREqualFunc equal_func = (KREqualFunc )kr_get_equal_func(eIndexFieldType); ptIndex->pHashTable = kr_hashtable_new(hash_func, equal_func); ptIndex->pIndexTableList = kr_list_new(); kr_list_set_match(ptIndex->pIndexTableList, (KRCompareFunc )kr_table_indexid_match); kr_list_add_tail(ptDB->pIndexList, ptIndex); return ptIndex; }
/*static dataitem*/ T_KRDDI *kr_ddi_construct(T_KRParamDDIDef *ptParamDDIDef, T_KRModule *ptModule, KRGetTypeFunc pfGetType, KRGetValueFunc pfGetValue) { T_KRDDI *ptDDI = kr_calloc(sizeof(T_KRDDI)); if (ptDDI == NULL) { KR_LOG(KR_LOGERROR, "kr_calloc ptDDI failed!"); return NULL; } ptDDI->ptParamDDIDef = ptParamDDIDef; ptDDI->lDDIId = ptParamDDIDef->lDdiId; ptDDI->ptDDICalc = kr_calc_construct(ptParamDDIDef->caDdiFilterFormat[0], \ ptParamDDIDef->caDdiFilterString, pfGetType, pfGetValue); ptDDI->eValueType = ptParamDDIDef->caDdiValueType[0]; /*get the retrieve data function from module*/ if (ptParamDDIDef->caDdiAggrFunc[0] != '\0') { ptDDI->pfDDIAggr = (KRDDIAggrFunc )kr_module_symbol(ptModule, ptParamDDIDef->caDdiAggrFunc); if (ptDDI->pfDDIAggr == NULL) { KR_LOG(KR_LOGERROR, "kr_module_symbol [%s] error!", \ ptParamDDIDef->caDdiAggrFunc); return NULL; } } ptDDI->eValueInd = KR_VALUE_UNSET; ptDDI->ptRelated = kr_hashtable_new(kr_pointer_hash, kr_pointer_equal); return ptDDI; }
void *kr_data_item_ddi_new(T_KRDataItem *ptDataItem) { T_KRParamDdi *ptParamDdi = (T_KRParamDdi *)ptDataItem->ptDataItemDef; T_KRDdi *ptDdi = kr_calloc(sizeof(*ptDdi)); if (ptDdi == NULL) { KR_LOG(KR_LOGERROR, "kr_calloc ptDdi failed!"); return NULL; } ptDdi->ptFilterCalc = kr_calc_construct( ptParamDdi->caDdiFilterFormat[0], \ ptParamDdi->caDdiFilterString, \ ptDataItem->pfGetType, \ ptDataItem->pfGetValue); if (ptDdi->ptFilterCalc == NULL) { KR_LOG(KR_LOGERROR, "kr_calc_construct filter failed!"); return NULL; } /* ptDdi->ptResultCalc = kr_calc_construct( ptParamSdi->caSdiResultFormat[0], \ ptParamSdi->caSdiResultString, \ ptDataItem->pfGetType, \ ptDataItem->pfGetValue); if (ptDdi->ptResultCalc == NULL) { KR_LOG(KR_LOGERROR, "kr_calc_construct result failed!"); return NULL; } */ ptDdi->ptRelated = kr_hashtable_new(kr_pointer_hash, kr_pointer_equal); if (ptDdi->ptRelated == NULL) { KR_LOG(KR_LOGERROR, "kr_hashtable_new related failed!"); return NULL; } ptDataItem->ptPrivate = ptDdi; return ptDdi; }