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

📄 gistfcnt.cpp

📁 此文件包含了在linux下实现tpr-tree索引的源代码
💻 CPP
字号:
//--------------------------------------------------------------------//        GiSTfcnt.cpp//        ------------////        GiST - Generalized Search Tree //        June 2001 release, Aalborg University//        //        This file is a revised version of a part of the original //        libGiST release (version  0.9beta1)     //        Copyright (c) 1996, Regents of the University of California//#include "GiSTfcnt.h"                                  int GiSTfileCnt::DefPageSize = 1024;//--------------------------------------------------------------------//   GiSTcache - stores the numbers and dirty flags of the pages//               in the simulated cache buffer//GiSTcache::GiSTcache(int size) :           num(0), len(size) {    array      = new int[size];   dirtyFlags = new char[size]; }//---------------------------------------------GiSTcache::~GiSTcache(){   if (array)      delete[] array;    if (dirtyFlags) delete[] dirtyFlags; }//---------------------------------------------void GiSTcache::UpdateSize(int size) {   if (!size)    {      if (array)      delete[] array;      if (dirtyFlags) delete[] dirtyFlags;       array      = NULL;      dirtyFlags = NULL;      len = num  = 0;   }   else    {      int*  tempa = new int[size];      char* tempd = new char[size];      int i;      for (i = 0; i < num && i < size; i++)       {         tempa[i] = array[i];         tempd[i] = dirtyFlags[i];      }      num = i;       if (array)      delete[] array;      if (dirtyFlags) delete[] dirtyFlags;       array      = tempa;      dirtyFlags = tempd;       len = size;   }}//---------------------------------------------int GiSTcache::Find(int x) const{  for (int i = 0; i < num; i++)     if (array[i] == x) return i + 1;  return 0;}//---------------------------------------------int GiSTcache::Add(int x, char dirty){   // least recently used page is in 0 position   int i;   int no;   int ret = 0;   if (!len) return 1;   // No buffer, disk is accessed   if (len == 1 && x != GiSTRootPage) // Buffer - just a single pinned root      return 1;   no = Find(x);   if (no)   {      dirty = dirty || dirtyFlags[no-1];      for (i = no - 1; i > 0; i--)      {         array[i]      = array[i-1];               dirtyFlags[i] = dirtyFlags[i-1];      }   }   else   {      int to;         // index in array of page to be thrown out       if (!dirty)          ret++;       // reading from disk       if (num == len)      { 	 if (array[num-1] == GiSTRootPage) // we do not throw out root-page            to = num - 2; 		 else to = num - 1;         if (dirtyFlags[to]) ret++;   // writing to disk dirty page,       }                               // that is being thrown out from the buffer        else to = num;      for (i = to; i > 0; i--)      {         array[i]      = array[i-1];         dirtyFlags[i] = dirtyFlags[i-1];          }      if (num < len) num++;           }   array[0] = x;   dirtyFlags[0] = dirty;   return ret;}//---------------------------------------------int GiSTcache::FlushDirty(){   int ret = 0;   for (int i = 0; i < num; i++)       if (dirtyFlags[i])       {         ret++;         dirtyFlags[i] = 0;      }      return ret;}//--------------------------------------------------------------------//   GiSTfileCnt - augments GiSTfileCache to count accessed disk pages//                 and simulates the cache buffer of the desired side //                 (GiSTfileCahce caches real pages to improve the//                  perfofmance of the experimental testbench itself)////---------------------------------------------void GiSTfileCnt::ResetCounter() {   pcount = 0;    // cache is not cleared, other operations can use it   //     cache->Clear();   //   cache->Add(GiSTRootPage);     // Root is always in the cache}//---------------------------------------------void GiSTfileCnt::Write (GiSTpage page, const char *buf){   pcount += cache->Add(page, 1);    // Dirty page   GiSTfileCache::Write(page, buf);}//---------------------------------------------void GiSTfileCnt::Read (GiSTpage page, char *buf){   pcount += cache->Add(page, 0);   GiSTfileCache::Read (page, buf);}//---------------------------------------------int GiSTfileCnt::GetCounter(){   pcount += cache->FlushDirty();   return pcount;}

⌨️ 快捷键说明

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