⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmdline.cc

📁 Libgist is an implementation of the Generalized Search Tree, a template index structure that makes i
💻 CC
📖 第 1 页 / 共 2 页
字号:
        cout << "can't parse data" << endl;	return;    }    if (echoOutput) { 	printDatum(key, klen, data, dlen, ext);	cout << endl;    }    if (index->insert(key, klen, data, dlen) != RCOK) {	cout << "can't insert" << endl;    }}///////////////////////////////////////////////////////////////////////////////// cmdDelete - call gist::delete//// Description://///////////////////////////////////////////////////////////////////////////////voidcmdDelete(    const char* 	table,    const char* 	qstr){    int i;    if ((i = getTable(table)) == NOT_FOUND) {	cout << "Index not opened" << endl;	return;    }    gist *index = tables[i].index;    gist_ext_t* ext = tables[i].index->extension();    // make sure extension can parse queries    if (ext->parseQuery == NULL) {        cout << "Extension can't parse queries." << endl;	return;    }    gist_cursor_t cursor;    gist_query_t* query;    rc_t status = ext->parseQuery(qstr, query);    if (tables[i].index->remove(query) != RCOK) {        cout << "can't delete" << endl;    }    delete query;}///////////////////////////////////////////////////////////////////////////////// cmdQuit - close tables and analysis and exit//// Description:///////////////////////////////////////////////////////////////////////////////voidcmdQuit(){    while (numTables > 0) {	(void) closeTable(0);    }#ifdef AMDB    while (numAnalyses > 0) {	closeAnalysis(0);    }#endif    cout << "Goodbye." << endl;    exit(0);}///////////////////////////////////////////////////////////////////////////////// cmdDump - call gist::dump//// Description:///////////////////////////////////////////////////////////////////////////////voidcmdDump(    const char* 	table,    shpid_t 		pgno){    int i;    if ((i = getTable(table)) == NOT_FOUND) {	cout << "Index not opened" << endl;	return;    }    if (tables[i].index->dump(cout, pgno) != RCOK) {        cerr << "can't dump" << endl;    }}///////////////////////////////////////////////////////////////////////////////// cmdSplit - call gist::split//// Description:///////////////////////////////////////////////////////////////////////////////voidcmdSplit(    const char* 	table,    shpid_t 		pgno){#ifdef AMDB    int i;    if ((i = getTable(table)) == NOT_FOUND) {	cout << "Index not opened" << endl;	return;    }    int splitEntries[gist_p::max_scnt];    int numSplit;    gist::AlignedPred x, y;    vec_t leftBp(x.pred, gist_p::max_tup_sz);    vec_t rightBp(x.pred, gist_p::max_tup_sz);    rc_t status = tables[i].index->pickSplit(pgno, splitEntries, numSplit, leftBp, rightBp);    if (status != RCOK) {        cout << "Can't split page " << pgno << endl;	return;    }    cout << "Entries for right sibling (" << numSplit << ") :" << endl;    if (numSplit > 0) {        cout << splitEntries[0];	for (i = 1; i < numSplit; i++) {	    cout << ", " << splitEntries[i];	}	cout << endl;    }#endif}voidcmdSetEcho(    int 	state){    echoOutput = (state == 1);}#ifdef AMDB// hack: index of last 'table' that had its amdb_idxstruct enabledstatic int structIdx;///////////////////////////////////////////////////////////////////////////////// breakHandler - amdb break handler//// Description://// Return Values://      RCOK///////////////////////////////////////////////////////////////////////////////static boolbreakHandler(    amdb_breakpoints::BreakInfo* 	info){    // see if event signals a structure change    if (!amdb_breakpoints::isStructureUpdate(info->event)) {	return false;    }    amdb_idxstruct* strct = tables[structIdx].strct;    switch (info->event) { 	case amdb_breakpoints::newNodeEvent: {	    strct->splitNode(info->param.newNodeParam.origNode,		info->param.newNodeParam.rightSib,		info->param.newNodeParam.rightChildren);	    break;	}	case amdb_breakpoints::newRootEvent: {	    strct->splitRoot(info->param.newRootParam.leftNode,		info->param.newRootParam.rightNode,		info->param.newRootParam.rightChildren);	    break;	}	case amdb_breakpoints::relocateChildEvent: {	    strct->relocateChild(info->param.relocateChildParam.child,		info->param.relocateChildParam.oldParent,		info->param.relocateChildParam.newParent);	    break;	}	case amdb_breakpoints::itemInsertedEvent:	case amdb_breakpoints::itemDeletedEvent:	case amdb_breakpoints::bpUpdatedEvent: {	    strct->updateNode(info->param.updNodeParam);	    break;	}	default: 	    assert(0);    }    return false;}#endif///////////////////////////////////////////////////////////////////////////////// cmdSetStruct - creates amdb_idxstruct//// Description:///////////////////////////////////////////////////////////////////////////////voidcmdSetStruct(    const char* 	table,    int 		state){#ifdef AMDB    int i;    if ((i = getTable(table)) == NOT_FOUND) {        cerr << "Table not open" << endl;	return;    }    gist* index = tables[i].index;    if (state != 0) {	if (tables[i].strct == NULL) {	    tables[i].strct = new amdb_idxstruct(index);	} else {	    delete tables[i].strct;	    tables[i].strct = new amdb_idxstruct(index);	}	index->setBreakHandler(breakHandler);	structIdx = i;    } else {	index->setBreakHandler(NULL);    }#endif}///////////////////////////////////////////////////////////////////////////////// cmdCreateAnl - run queries and create amdb_analysis//// Description://///////////////////////////////////////////////////////////////////////////////voidcmdCreateAnl(    const char* 	analysisname,    const char* 	indexname,    const char* 	scriptfile,    int 		numRandomRuns,    float 		targetUtil){#ifdef AMDB    // make sure we don't overflow analyses[]    if (numAnalyses == MAXIDX) { 	cout << "Capacity exceeded (" << MAXIDX << ")" << endl;	return;     }    // open index and create empty amdb_wkldprofile    gist* index = new gist();    if (index->open(indexname) != RCOK) {        cerr << "Can't open index " << indexname << endl;	return;    }    // need a tree map for profiling    amdb_treemap* map = new amdb_treemap();    index->computeTreeMap(map);    // create profile    amdb_wkldprofile* profile = new amdb_wkldprofile();    profile->setTreeMap(map);    index->setProfilingEnabled(profile);    // make sure we can parse queries    gist_ext_t* ext = index->extension();    if (ext->parseQuery == NULL) {        cerr << "Extension of " << indexname << " can't parse queries" << endl;	return;    }    // scan scriptfile and run queries    ifstream s(scriptfile);    if (s.fail()) {        cout << "Error opening " << scriptfile << endl;        return;    }    char buf[1024];	char *b;	int maxR = 0;    while (s.getline(buf, sizeof(buf))) {		b = buf;		// if buf starts with maxR then its a nearest neighbor query ...		if (strncmp("maxR:",b,5) == 0) {			char *tmp;			b += 5;			maxR = strtol(b, &tmp, 0);			b = tmp;		}        gist_query_t* query;        rc_t status = ext->parseQuery(b, query);        if (status != RCOK) {            cout << "Error parsing qualification (" << b << ")" << endl;            return;        }	// run query	int dummyInt;	if (runQuery(*index, query, maxR, 0, dummyInt) != RCOK) {	    return;	}	delete query;    }    s.close();    delete index;    delete map;    amdb_analysis* analysis = new amdb_analysis();    if (analysis->init(indexname, profile, scriptfile, numRandomRuns, targetUtil)        != RCOK) {	cerr << "can't initialize analysis" << endl;	delete analysis;	return;    }    if (analysis->write(analysisname, false) != RCOK) {        cerr << "can't write analysis" << endl;	delete analysis;	return;    }    analyses[numAnalyses].name = strdup(analysisname);    analyses[numAnalyses].analysis = analysis;    numAnalyses++;#endif}/////////////////////////////////////////////////////////////////////////// cmdOpenAnl - read amdb_analysis from file//// Description://///////////////////////////////////////////////////////////////////////voidcmdOpenAnl(    const char* 	filename){#ifdef AMDB    // make sure we don't overrun analyses[]    if (numAnalyses == MAXIDX) { 	cout << "Capacity exceeded (" << MAXIDX << ")" << endl;	return;     }    amdb_analysis* analysis = new amdb_analysis();    if (analysis->read(filename) != RCOK) {        cerr << "Error reading analysis (file " << filename << ")" << endl;	delete analysis;	return;    }    analyses[numAnalyses].name = strdup(filename);    analyses[numAnalyses].analysis = analysis;    numAnalyses++;#endif}/////////////////////////////////////////////////////////////////////////// cmdCloseAnl - write amdb_analysis to file//// Description://///////////////////////////////////////////////////////////////////////voidcmdCloseAnl(    const char* 	analysisname){#ifdef AMDB    int i;    if ((i = getAnalysis(analysisname)) == NOT_FOUND) {        cerr << "Analysis not open" << endl;	return;    }    amdb_analysis* analysis = analyses[i].analysis;    if (analysis->write(analyses[i].name, false) != RCOK) {        cerr << "Error writing analysis (file " << analyses[i].name << ")" << endl;	return;    }    closeAnalysis(i);#endif}/////////////////////////////////////////////////////////////////////////// cmdSplitStats - call amdb_analysis::analyzeSplit//// Description://	- needs loaded analysis///////////////////////////////////////////////////////////////////////////voidcmdSplitStats(    const char* 	analysis,    const char* 	option){#ifdef AMDB    int i;    if ((i = getAnalysis(analysis)) == NOT_FOUND) {        cerr << "Analysis not open" << endl;	return;    }    if (option != NULL &&        strcmp(option, "opt") != 0 && strcmp(option, "act") != 0) {	cout << "Option " << option << " not recognized" << endl;	return;    }    bool evalOpt = (option != NULL && strcmp(option, "opt") == 0);    if (analyses[i].analysis->analyzeSplit(evalOpt) != RCOK) {	cout << "can't analyze splits" << endl;    }#endif}/////////////////////////////////////////////////////////////////////////// cmdPenaltyStats - call amdb_analysis::analyzePenalty//// Description://	- needs loaded analysis///////////////////////////////////////////////////////////////////////////voidcmdPenaltyStats(    const char* 	analysis,    const char* 	loadfile,    const char* 	option){#ifdef AMDB    int i;    if ((i = getAnalysis(analysis)) == NOT_FOUND) {        cerr << "Analysis not open" << endl;	return;    }    if (option != NULL &&        strcmp(option, "opt") != 0 && strcmp(option, "act") != 0) {	cout << "Option " << option << " not recognized" << endl;	return;    }    bool evalOpt = (option != NULL && strcmp(option, "opt") == 0);    if (analyses[i].analysis->analyzePenalty(evalOpt, loadfile) != RCOK) {        cerr << "can't analyze penalty" << endl;	return;    }#endif}/////////////////////////////////////////////////////////////////////////// cmdWkldStats - call amdb_analysis::analyzeWkld//// Description://	- needs loaded analysis///////////////////////////////////////////////////////////////////////////voidcmdWkldStats(    const char* 	analysis){#ifdef AMDB    int i;    if ((i = getAnalysis(analysis)) == NOT_FOUND) {        cerr << "Analysis not open" << endl;	return;    }    if (analyses[i].analysis->analyzeWkld(false) != RCOK) {	cout << "can't analyze workload" << endl;    }#endif}/////////////////////////////////////////////////////////////////////////// cmdAnlInfo - print info about analysis//// Description://	- needs loaded analysis///////////////////////////////////////////////////////////////////////////voidcmdAnlInfo(    const char* 	analysis){#ifdef AMDB    int i;    if ((i = getAnalysis(analysis)) == NOT_FOUND) {        cerr << "Analysis not open" << endl;	return;    }    amdb_analysis* anl = analyses[i].analysis;    cout << "actual: ";    if (anl->actualAnalysis.profile != NULL) {        cout << "profile ";    }    if (anl->actualAnalysis.map != NULL) {        cout << "map ";    }    if (anl->actualAnalysis.wkldStats != NULL) {        cout << "wkldstats ";    }    if (anl->actualAnalysis.splitStats != NULL) {        cout << "splitstats ";    }    if (anl->actualAnalysis.penaltyStats != NULL) {        cout << "penaltystats ";    }    cout << endl;    cout << "opt: ";    if (anl->optAnalysis.profile != NULL) {        cout << "profile ";    }    if (anl->optAnalysis.map != NULL) {        cout << "map ";    }    if (anl->optAnalysis.wkldStats != NULL) {        cout << "wkldstats ";    }    if (anl->optAnalysis.splitStats != NULL) {        cout << "splitstats ";    }    if (anl->optAnalysis.penaltyStats != NULL) {        cout << "penaltystats ";    }    cout << endl;#endif}/////////////////////////////////////////////////////////////////////////// cmdPredInfo - construct gist::DisplayPredInfo array//// Description:///////////////////////////////////////////////////////////////////////////voidcmdPredInfo(    const char* 	table,    int 		subtreeRoot,    int 		levels){#ifdef AMDB    int i;    if ((i = getTable(table)) == NOT_FOUND) {        cerr << "Table not open" << endl;	return;    }    gist* index = tables[i].index;    rc_t status = eARRAYSIZE;    int numPredInfo = 50;    gist::DisplayPredInfo* predInfo = NULL;    while (status == eARRAYSIZE) {	delete [] predInfo;	numPredInfo *= 2;	predInfo = new gist::DisplayPredInfo[numPredInfo];        status = index->getPredInfo(subtreeRoot, levels, predInfo, numPredInfo);    }    if (status != RCOK) {        cerr << "gist::getPredInfo() failed" << endl;    }    delete [] predInfo;#endif}voidcmdHelp(){    int i;    cout << "gistcmdline was built on " << timestamp << endl;    cout << "Valid commands:" << endl << usage << endl;    cout << "Valid extension names:" << endl;    for (i = 0; i < gist_ext_t::gist_numext; ++i) {        cout << '\t' << gist_ext_t::gist_ext_list[i]->myName << endl;    }}voidcmdPrompt(){    if (!noPrompt) {	cout << "libgist" << "> ";	cout.flush();    }}intmain(    int argc,    char* argv[]){    int i;    for (i = 1; i < argc; i++) {        if (strcmp(argv[i], "-h") == 0) {	    // print help	    cout << argv[0] << " [-hs]" << endl;	    exit(0);	} else if (strcmp(argv[i], "-s") == 0) {	    // 'silent' option (no prompt)	    noPrompt = true;	}    }    cout.setf(ios::fixed);    cmdPrompt();    yyparse();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -