📄 tvindexstat.c
字号:
/* COPYRIGHT NOTICE This material was developed by Christos Faloutsos and King-Ip Linat the University of Maryland, College Park, Department of Computer Science.Permission is granted to copy this software, to redistribute iton a nonprofit basis, and to use it for any purpose, subject tothe following restrictions and understandings. 1. Any copy made of this software must include this copyright noticein full. 2. All materials developed as a consequence of the use of thissoftware shall duly acknowledge such use, in accordance with the usualstandards of acknowledging credit in academic research. 3. The authors have made no warranty or representation that theoperation of this software will be error-free or suitable for anyapplication, and they are under under no obligation to provide anyservices, by way of maintenance, update, or otherwise. The softwareis an experimental prototype offered on an as-is basis. 4. Redistribution for profit requires the express, written permissionof the authors. */// Author : $Author$// Date : $Date$// Id : $Id$// $Id: indexstat.C,v 1.1 1996/02/19 23:50:29 kilin Exp $ #include <iostream.h>#include <stdlib.h>#include <assert.h>#include <stdio.h>#include "TVdefine.h"#include "TVconstants.h"#include "TVindexstat.h"#include "TVutil.h"void TVTree_Stat::Init_arrays(){ readcount = new int[max_phase]; writecount = new int[max_phase]; leafreadcount = new int[max_phase]; leafwritecount = new int[max_phase]; splitnodecount = new int[max_phase]; splitleafcount = new int[max_phase]; totalradiusratio = new float[max_phase]; insertbranchcount = new int[max_phase]; unfoldcount = new int[max_phase]; foldbackcount = new int[max_phase]; insertelementcount = new int[max_phase]; treesize = new int[max_phase]; nodecount = new int[max_phase]; leafcount = new int[max_phase]; worddiffcalcount = new int[max_phase]; reinsertcount = new int[max_phase]; for (int i = 0; i < max_phase; i++) { readcount[i] = 0; writecount[i] = 0; leafreadcount[i] = 0; leafwritecount[i] = 0; splitnodecount[i] = 0; splitleafcount[i] = 0; totalradiusratio[i] = 0.0; insertbranchcount[i] = 0; unfoldcount[i] = 0; foldbackcount[i] = 0; insertelementcount[i] = 0; treesize[i] = 0; nodecount[i] = 0; leafcount[i] = 0; worddiffcalcount[i] = 0; reinsertcount[i] = 0; }}void TVTree_Stat::Destroy_arrays(){ delete [] readcount; delete [] writecount; delete [] leafreadcount; delete [] leafwritecount; delete [] splitnodecount; delete [] splitleafcount; delete [] totalradiusratio; delete [] insertbranchcount; delete [] unfoldcount; delete [] foldbackcount; delete [] insertelementcount; delete [] treesize; delete [] nodecount; delete [] leafcount; delete [] worddiffcalcount; delete [] reinsertcount;}void TVTree_Stat::Copy_arrays(const TVTree_Stat& ip){ for (int i=0; i < max_phase; i++) { readcount[i] = ip.readcount[i]; writecount[i] = ip.writecount[i]; leafreadcount[i] = ip.leafreadcount[i]; leafwritecount[i] = ip.leafwritecount[i]; splitnodecount[i] = ip.splitnodecount[i]; splitleafcount[i] = ip.splitleafcount[i]; totalradiusratio[i] = ip.totalradiusratio[i]; insertbranchcount[i] = ip.insertbranchcount[i]; unfoldcount[i] = ip.unfoldcount[i]; foldbackcount[i] = ip.foldbackcount[i]; insertelementcount[i] = ip.insertelementcount[i]; treesize[i] = ip.treesize[i]; nodecount[i] = ip.nodecount[i]; leafcount[i] = ip.leafcount[i]; worddiffcalcount[i] = ip.worddiffcalcount[i]; reinsertcount[i] = ip.reinsertcount[i]; }}TVTree_Stat::TVTree_Stat(){ max_phase = PHASES + 1; current_phase = 1; Init_arrays();}TVTree_Stat::TVTree_Stat(int mphase){ max_phase = mphase + 1; current_phase = 1; Init_arrays();}TVTree_Stat::TVTree_Stat(const TVTree_Stat& ip){ if (max_phase != ip.max_phase) { Destroy_arrays(); max_phase = ip.max_phase; Init_arrays(); Copy_arrays(ip); } current_phase = ip.current_phase;}TVTree_Stat::~TVTree_Stat(){ Destroy_arrays();}TVTree_Stat& TVTree_Stat::operator=(const TVTree_Stat& ip){ if (max_phase != ip.max_phase) { Destroy_arrays(); max_phase = ip.max_phase; Init_arrays(); Copy_arrays(ip); } current_phase = ip.current_phase; return *this;}TVTree_Stat& TVTree_Stat::IncrementPhase(){ assert(current_phase < PHASES); current_phase++; return *this;}TVTree_Stat& TVTree_Stat::DummyPhase(){ stored_phase = current_phase; current_phase = 0; return *this;}TVTree_Stat& TVTree_Stat::RestorePhase(){ current_phase = stored_phase; return *this;}TVTree_Stat& TVTree_Stat::IncrementStat(int code) { switch (code ) { case READCOUNT : readcount[current_phase]++; break; case WRITECOUNT : writecount[current_phase]++; break; case LEAFREADCOUNT : leafreadcount[current_phase]++; break; case LEAFWRITECOUNT : leafwritecount[current_phase]++; break; case SPLITNODECOUNT : splitnodecount[current_phase]++; break; case SPLITLEAFCOUNT : splitleafcount[current_phase]++; break; case INSERTBRANCHCOUNT : insertbranchcount[current_phase]++; break; case UNFOLDCOUNT : unfoldcount[current_phase]++; break; case FOLDBACKCOUNT : foldbackcount[current_phase]++; break; case INSERTELEMENTCOUNT : insertelementcount[current_phase]++; break; case TREESIZE : treesize[current_phase]++; break; case NODECOUNT : nodecount[current_phase]++; break; case LEAFCOUNT : leafcount[current_phase]++; break; case WORDDIFFCALCOUNT : worddiffcalcount[current_phase]++; break; case REINSERTCOUNT : reinsertcount[current_phase]++; break; default : printf("Oops! in Increment stat\n"); assert(0); break; } return *this;}TVTree_Stat& TVTree_Stat::SetZero(int code) { switch (code ) { case READCOUNT : readcount[current_phase] = 0; break; case WRITECOUNT : writecount[current_phase] = 0; break; case LEAFREADCOUNT : leafreadcount[current_phase] = 0; break; case LEAFWRITECOUNT : leafwritecount[current_phase] = 0; break; case SPLITNODECOUNT : splitnodecount[current_phase] = 0; break; case SPLITLEAFCOUNT : splitleafcount[current_phase] = 0; break; case INSERTBRANCHCOUNT : insertbranchcount[current_phase] = 0; break; case UNFOLDCOUNT : unfoldcount[current_phase] = 0; break; case FOLDBACKCOUNT : foldbackcount[current_phase] = 0; break; case INSERTELEMENTCOUNT : insertelementcount[current_phase] = 0; break; case TREESIZE : treesize[current_phase] = 0; break; case NODECOUNT : nodecount[current_phase] = 0; break; case LEAFCOUNT : leafcount[current_phase] = 0; break; case WORDDIFFCALCOUNT : worddiffcalcount[current_phase] = 0; break; case REINSERTCOUNT : reinsertcount[current_phase] = 0; break; default : printf("Oops! in Increment stat\n"); assert(0); break; } return *this;}TVTree_Stat& TVTree_Stat::SetPageSize(int ps){ pagesize = ps; return *this;}TVTree_Stat& TVTree_Stat::AddIntStat(int code, int val) { switch (code ) { case READCOUNT : readcount[current_phase] += val; break; case WRITECOUNT : writecount[current_phase] += val; break; case LEAFREADCOUNT : leafreadcount[current_phase] += val; break; case LEAFWRITECOUNT : leafwritecount[current_phase] += val; break; case SPLITNODECOUNT : splitnodecount[current_phase] += val; break; case SPLITLEAFCOUNT : splitleafcount[current_phase] += val; break; case INSERTBRANCHCOUNT : insertbranchcount[current_phase] += val; break; case UNFOLDCOUNT : unfoldcount[current_phase] += val; break; case FOLDBACKCOUNT : foldbackcount[current_phase] += val; break; case INSERTELEMENTCOUNT : insertelementcount[current_phase] += val; break; case TREESIZE : treesize[current_phase] += val; break; case NODECOUNT : nodecount[current_phase] += val; break; case LEAFCOUNT : leafcount[current_phase] += val; break; case WORDDIFFCALCOUNT : worddiffcalcount[current_phase] += val; break; case REINSERTCOUNT : reinsertcount[current_phase] += val; break; default : printf("Oops! in add int stat\n"); assert(0); break; } return *this;} /* Add the real stat by value */TVTree_Stat& TVTree_Stat::AddFloatStat(int code, float val){ switch (code ) { case TOTALRADIUSRATIO : totalradiusratio[current_phase] += val; break; default : printf("Oops! in add float stat\n"); break; } return *this;}int TVTree_Stat::GetIntStat(int code) { int result; switch (code ) { case READCOUNT : result = readcount[current_phase]; break; case WRITECOUNT : result = writecount[current_phase]; break; case LEAFREADCOUNT : result = leafreadcount[current_phase]; break; case LEAFWRITECOUNT : result = leafwritecount[current_phase]; break; case SPLITNODECOUNT : result = splitnodecount[current_phase]; break; case SPLITLEAFCOUNT : result = splitleafcount[current_phase]; break; case INSERTBRANCHCOUNT : result = insertbranchcount[current_phase]; break; case UNFOLDCOUNT : result = unfoldcount[current_phase]; break; case FOLDBACKCOUNT : result = foldbackcount[current_phase]; break; case INSERTELEMENTCOUNT : result = insertelementcount[current_phase]; break; case TREESIZE : result = treesize[current_phase]; break; case NODECOUNT : result = nodecount[current_phase]; break; case LEAFCOUNT : result = leafcount[current_phase]; break; case WORDDIFFCALCOUNT : result = worddiffcalcount[current_phase]; break; case REINSERTCOUNT : result = reinsertcount[current_phase]; break; default : printf("Oops! in add int stat\n"); assert(0); break; } return result;}// befriended functionsostream& operator<< (ostream& os, const TVTree_Stat& ip){ int i; os << "Stats\n"; os << "\tDisk accesses\n"; os << "Phase\tTVNode read\tLeaf read\tTotal\tTVNode Written\tLeaf Written\tTotal\n"; for (i = 0 ; i < ip.max_phase; i++) { os << i << "\t" << ip.readcount[i] << "\t\t" ; os << ip.leafreadcount[i] << "\t\t" ; os << ip.readcount[i] + ip.leafreadcount[i] << "\t" ; os << ip.writecount[i] << "\t\t" << ip.leafwritecount[i] << "\t\t"; os << ip.writecount[i] + ip.leafwritecount[i] << "\n"; } os << "\n\tNo.of \n"; os << "Phase\tEl insert\tReinsert\tSplits\tSplitLeaf\tUnfold\tFoldback\n"; for (int j = 0 ; j < ip.max_phase; j++) { os << j << "\t" << ip.insertelementcount[j] << "\t\t"; os << ip.reinsertcount[j] << "\t\t"; os << ip.splitnodecount[j] << "\t" ; os << ip.splitleafcount[j] << "\t\t" ; os << ip.unfoldcount[j] << "\t" ; os << ip.foldbackcount[j] << "\n"; } printf("Phase\tTVNode Count\tLeaf Count\tTotal Count\tByte used\tUtili.\tDiff cal\n"); for (i=0 ; i < ip.max_phase; i++) { os << i << "\t" << ip.nodecount[i] << "\t\t"; os << ip.leafcount[i] << "\t\t"; os << ip.nodecount[i] + ip.leafcount[i] << "\t\t"; os << ip.treesize[i] << "\t\t"; os << ((ip.nodecount[i] + ip.leafcount[i]) ? (ip.treesize[i] * 100.0) / ((ip.nodecount[i] + ip.leafcount[i]) * ip.pagesize) : 0) << "\t"; os << ip.worddiffcalcount[i] << "\n"; } return os;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -