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

📄 command.cpp

📁 此文件包含了在linux下实现tpr-tree索引的源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//--------------------------------------------------------------------//      command.cpp//      -----------//      Functions for processing of user commands////      TPR-tree - Index for continuously moving objects//      July 2001 release, Aalborg University//#include <stdio.h>#ifdef UNIX#include <unistd.h>#include <ctype.h>#endif#include <iomanip.h>#include "rtprofile.h"#include "command.h"FILE*    imports[5];              // Imported files int      numImports = 0;          // Number of imported filesstatic char*    ot_name = NULL;   // Name of the opened tablestatic char     ot_data[30];      // Data file name, from which the index was loadedstatic GiST*    ot_gist;          // GiST of the opened tablestatic int  numInsertions = 0;    // Number of insertions performedstatic int  debug        = 0;     // If (debug) DebugSearch is called  static int  printOn      = 1;     // If (!printOn) no output to the screenstatic int  statisticsOn = 0;     // Gathering of I/O statisticsstatic long stInserts     = 0;     // Statisticsstatic long stInsertsOld  = 0;     // Old - to support reporting of running totalsstatic long stDeletes     = 0;static long stDeletesOld  = 0;static long stSelects     = 0;static long stSelectsOld  = 0;static long stDelFails    = 0;static long stSelectsR    = 0;     // Number of results static long stSelectsROld = 0;     // Number of results oldstatic long stInsertIOs   = 0;     static long stInsertIOsOld= 0;static long stDeleteIOs   = 0;static long stDeleteIOsOld= 0;static long stSelectIOs   = 0;static long stSelectIOsOld= 0;static double cmAlpha     = 1;                    static double cmHorizon   = 1;      static double cmW         = 0;static bool   cmAutoHorizon = false;static double cmWFactor   = 1;static ostream*  outFile = &cout;  // Properties, statisticsOut and Output write here//------------------------------------------------static bool CheckForOpenTable (){   if (!ot_name)   {      outstr << "Table is not open!" << endl;      return false;   }   return true;}//------------------------------------------------static bool CheckForClosedTable (){   if (ot_name)   {      outstr << "This operation can only be performed if no table is open!" << endl;      return false;   }   return true;}//------------------------------------------------void CommandCreate(const char *method, const char *table, int nDims){   if (!CheckForClosedTable()) return;      if (!Settings.SetDims (nDims))   {      outstr << "Number of spatial dimensions too large, using 1" << endl;      Settings.SetDims (1);   }   if (!strcmp(method, "tprtree")) Settings.SetTreeType (RTsettings::tTPRtree);   else if (!strcmp(method, "rtree")) Settings.SetTreeType (RTsettings::tRtree);        else if (!strcmp(method, "opttree")) Settings.SetTreeType (RTsettings::tOpttree);             else             {                outstr << "Supported methods are: tprtree, rtree, opttree"                        << endl;                return;             }      ot_gist = new RT;// Visualiser support   Register (ot_gist);//   CT = 0;    ot_gist->Create(table);   if (!ot_gist->IsOpen())   {      outstr << "Error creating table." << endl;      delete ot_gist;      return;   }   numInsertions = 0;   // setting the parameters from the environment   ((RT*) ot_gist)->SetHorizon(cmHorizon, cmW);     ((RT*) ot_gist)->SetAutoHorizon(cmAutoHorizon);   ((RT*) ot_gist)->SetWFactor(cmWFactor);          ((RT*) ot_gist)->SetAlpha(cmAlpha);     outstr << "Table " << table << " created as type " << method << "." << endl          << "current time is " << setprecision(3) << CT << endl          << "page size is " << ((RT*) ot_gist)->PageSize() << endl;   ot_name = new char[strlen(table)+1];   strcpy(ot_name, table);}//------------------------------------------------void CommandDrop(){   if (!CheckForOpenTable()) return;   ((RT*) ot_gist)->Drop();   outstr << "Table " << ot_name << " dropped." << endl;   delete   ot_gist;   delete[] ot_name;   ot_name = NULL;}//------------------------------------------------void CommandOpen(const char *table){   if (!CheckForClosedTable()) return;   ot_gist = new RT;// Visualiser support   Register (ot_gist);//   ot_gist->Open(table);   if (!ot_gist->IsOpen())   {      delete ot_gist;      outstr << "Error opening table." << endl;      return;   }   CT = ((RT*) ot_gist)->GetLastCh();   numInsertions = 0;   // setting the parameters from the environment   ((RT*) ot_gist)->SetAutoHorizon(cmAutoHorizon);   ((RT*) ot_gist)->SetWFactor(cmWFactor);             outstr << "Table " << table << " opened." << endl          << "current time is " << setprecision(3) << CT << endl          << "page size is " << ((RT*)ot_gist)->PageSize() << endl;   ot_name = new char[strlen(table)+1];   strcpy(ot_name, table);}//------------------------------------------------void CommandLoad(const char* data_file){   if (!CheckForOpenTable()) return;   RTsortArray loadArray;      ifstream    loadFile(data_file, ios::in);          if (!loadFile)    {      outstr << "Cannot open data file \"" << data_file              << "\" for bulk loading!" << endl;      return;   }   loadArray.ReadPoints(loadFile);   if (CT != 0.0) loadArray.AdjustPoints(CT);   //   ((RT*)ot_gist)->LoadTopDownSTR(loadArray);   ((RT*)ot_gist)->LoadBottomUp(loadArray);   strcpy(ot_data, data_file); }//------------------------------------------------void CommandClose(){   if (!CheckForOpenTable()) return;   ot_gist->Close();   outstr << "Table " << ot_name << " closed.\n";   delete   ot_gist;   delete[] ot_name;   ot_name = NULL;}//------------------------------------------------void CommandSelect(inputstruct* k){   int          i;   RTkey*       key;   RTpredicate* pred;   GiSTcursor*  c;   GiSTentry *  e;   RT*          rt = (RT*) ot_gist;      if (!CheckForOpenTable()) return;      PROFILE_ACTION_BEGIN(profile_search);      key  = new RTkey (k->coordslow, k->coordshigh, k->t1, k->t2);   pred = new RTpredicate (k->oper, *key);   if (Settings.GetTreeType() == RTsettings::tOpttree && key->t1 != rt->GetRefTS())    {      RTtimeStamp oldCT = CT;             CT = key->t1;       rt->DeleteAll();      CommandLoad(ot_data);      CT = oldCT;   }   if (printOn)      outstr << *pred << ":" << endl;      rt->ResetCounter();      c = debug ? ot_gist->DebugSearch(*pred) : ot_gist->Search(*pred);   for (i = 0; (e = c->Next()) != NULL; i++)   {      if (printOn) outstr << e << endl;      delete e;   }   delete c;      obs.Inform(ON_SEARCHEND);      if (printOn)      outstr << i << " results found" << endl;      if (statisticsOn)   {      if (printOn)         outstr << rt->GetCounter() << " I/Os performed" << endl;      stSelects++;      stSelectsR  += i;      stSelectIOs += rt->GetCounter();   }      delete key;   delete pred;      PROFILE_ACTION_END(profile_search);}//------------------------------------------------void CommandDelete(inputstruct* k){   RTkey*       key;   RTpredicate* pred;   int          found;   RT*          rt = (RT*) ot_gist;      if (!CheckForOpenTable()) return;      rt->ResetCounter();      PROFILE_ACTION_BEGIN(profile_delete);   key  = new RTkey (k->coordslow, rt->GetRefTS(), k->t2);   pred = new RTpredicate (k->rid, *key);      found = ot_gist->Delete(*pred);   stDelFails += !found;      if (printOn)      outstr << "Delete operation " << *key << (found ? " succeeded" : " failed") << endl;      if (statisticsOn)   {      if (printOn)         outstr << ((RT*)ot_gist)->GetCounter()                << " I/Os performed"                << endl;      stDeletes++;      stDeleteIOs += ((RT*)ot_gist)->GetCounter();   }      delete key;   delete pred;      PROFILE_ACTION_END(profile_delete);}//------------------------------------------------void CommandInsert(inputstruct* k){   RTentry* entry;   RTkey*   key;   RT*      rt = (RT*) ot_gist;      if (!CheckForOpenTable()) return;      PROFILE_ACTION_BEGIN(profile_insert);      rt->ResetCounter();      key = new RTkey (k->coordslow, rt->GetRefTS(), k->t2);      if (Settings.GetTreeType() == RTsettings::tRtree)    {      key->SetRefTS(CT);      key->t2 = CT + rt->GetParam();   }   entry = new RTentry(*key, k->rid);      ot_gist->Insert(*entry);   if (printOn)      outstr << *entry << " inserted" << endl;      if (statisticsOn)   {      if (printOn)         outstr << ((RT*)ot_gist)->GetCounter() << " I/Os performed"                << endl;      stInserts++;      stInsertIOs += ((RT*)ot_gist)->GetCounter();   }      delete key;   delete entry;      ++numInsertions;      PROFILE_ACTION_END(profile_insert);}//------------------------------------------------void CommandParam(RTperiod param){   if (!CheckForOpenTable()) return;   ((RT*) ot_gist)->SetHorizon(param);}//------------------------------------------------void CommandTime (RTtimeStamp time){   CT = time;   RefreshVisualiser();}//------------------------------------------------void CommandAdvanceTime (RTtimeStamp time){   if (time < 0)      outstr << "Warning: You move time backwards" << endl;   CT = CT + time;   RefreshVisualiser();}//------------------------------------------------void CommandBufferSize (int size){   if (!CheckForOpenTable()) return;   ((RT*)ot_gist)->SetBufferSize(size);   outstr << "Buffer size is set to " << ((RT*)ot_gist)->GetBufferSize() << endl;}//------------------------------------------------void CommandGetBufferSize (){   if (!CheckForOpenTable()) return;   outstr << "Buffer size is set to " << ((RT*)ot_gist)->GetBufferSize() << endl;}//------------------------------------------------void CommandPage (int page){   GiSTfileCnt::DefPageSize = page;   outstr << "Page size is set to " << GiSTfileCnt::DefPageSize << endl;}//------------------------------------------------void CommandGetPage (){   if (!CheckForOpenTable()) return;   outstr << ot_name << " page size is "          << ((RT*) ot_gist)->PageSize() << endl;   outstr << "Page size of new tables is " << GiSTfileCnt::DefPageSize << endl;}//------------------------------------------------void CommandGetParam (){   if (!CheckForOpenTable()) return;   outstr << ((RT*) ot_gist)->GetParam() << endl;}//------------------------------------------------void CommandGetTime (){   outstr << "Current time is " << setprecision(3) << CT << endl;}

⌨️ 快捷键说明

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