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

📄 amdb_penaltystats.cc

📁 Libgist is an implementation of the Generalized Search Tree, a template index structure that makes i
💻 CC
📖 第 1 页 / 共 2 页
字号:
// amdb_penaltystats.cc -*- c++ -*-// Copyright (c) 1998, Regents of the University of California// $Id: amdb_penaltystats.cc,v 1.7 2000/03/15 00:24:20 mashah Exp $#ifdef __GNUG__#pragma implementation "amdb_penaltystats.h"#endif// VCPORT_B#ifdef  WIN32#pragma warning(disable:4786)#endif// VCPORT_E// VCPORT_B#ifdef HAVE_VALUES_H#include <values.h>#endif// VCPORT_E#include <stdlib.h>#include <stdio.h>#include <math.h>#include "amdb_penaltystats.h"#include "amdb_clustering.h"#include <assert.h>#include "gist.h"#include "gist_compat.h"#include "gist_p.h"#include "amdb_ext.h"#include "amdb_treemap.h"#include "amdb_wkldprofile.h"#include "amdb_itemset.h"#include "amdb_splitstats.h"// STL// VCPORT_B#ifdef WIN32#include <vector>#include <algorithm>#include <fstream>#include <iostream>using namespace std;#else#include <fstream.h>#include <vector.h>#include <algo.h>#endif// VCPORT_E/////////////////////////////////////////////////////////////////////////// amdb_penaltystats::clear - reset state//// Description:// 	- don't deallocate anything, we might still need it for //	  subsequent read() calls/////////////////////////////////////////////////////////////////////////voidamdb_penaltystats::clear(){    cout << "amdb_penaltystats::clear()" << endl;    PenaltyStatsVect::iterator psit;    for (psit = penaltyStats.begin(); psit != penaltyStats.end(); psit++) {        PenaltyStats* stats = (PenaltyStats *) *psit;	delete stats;    }    penaltyStats.erase(penaltyStats.begin(), penaltyStats.end());}///////////////////////////////////////////////////////////////////////////////// amdb_penaltystats::amdb_penaltystats - constructor//// Description://// Preconditions:// Postconditions:// Notes://// Return Values://      RCOK///////////////////////////////////////////////////////////////////////////////amdb_penaltystats::amdb_penaltystats() : penaltyStats(){}///////////////////////////////////////////////////////////////////////////////// amdb_penaltystats::~amdb_penaltystats - destructor//// Description://// Preconditions:// Postconditions:// Notes://// Return Values://      RCOK///////////////////////////////////////////////////////////////////////////////// free all dynamically allocated stuffamdb_penaltystats::~amdb_penaltystats(){    cout << "~amdb_penaltystats()" << endl;    clear();}///////////////////////////////////////////////////////////////////////////////// amdb_penaltystats::write - write to output stream//// Description://// Return Values://      RCOK///////////////////////////////////////////////////////////////////////////////rc_t amdb_penaltystats::write(    ostream& s,    bool ascii){    cout << "amdb_penaltystats::write()" << endl;    if (!ascii) {      // save penaltyStats      PenaltyStatsVect::size_type penaltyStatsSize = penaltyStats.size();      s.write((char *) &penaltyStatsSize, sizeof(penaltyStatsSize));      PenaltyStatsVect::iterator pit;      for (pit = penaltyStats.begin(); pit != penaltyStats.end(); pit++) {	PenaltyStats* stats = (PenaltyStats *) *pit;		// save stats	s.write((char *) stats, sizeof(*stats));		// save key	int klen = stats->key->len(0);	s.write((char *) &klen, sizeof(klen));	s.write((char *) stats->key->ptr(0), klen);      }            // write avgStats      s.write((char *) &avgStats, sizeof(avgStats));            // check for errors      if (!s) return(eFILEERROR);    }    else {      // save penaltyStats      PenaltyStatsVect::size_type penaltyStatsSize = penaltyStats.size();      s << penaltyStatsSize << "\n";      PenaltyStatsVect::iterator pit;      for (pit = penaltyStats.begin(); pit != penaltyStats.end(); pit++) {	PenaltyStats* stats = (PenaltyStats *) *pit;		// save stats	s << stats << "\n";		// save key	int klen = stats->key->len(0);	s << klen;	s << stats->key->ptr(0);      }            // write avgStats      //s << avgStats;            // check for errors      if (!s) return(eFILEERROR);    }    return(RCOK);}/////////////////////////////////////////////////////////////////////////// amdb_penaltystats::read - read binary profile from input stream//// Description://// Return Values://      RCOK//	eFILEERROR/////////////////////////////////////////////////////////////////////////rc_tamdb_penaltystats::read(    istream& s){    cout << "amdb_penaltystats::read()" << endl;    clear(); // delete current data, if there is any     // read penaltyStats    PenaltyStatsVect::size_type penaltyStatsSize;    s.read((char *) &penaltyStatsSize, sizeof(penaltyStatsSize));    int i;    for (i = 0; i < penaltyStatsSize; i++) {	PenaltyStats* stats = new PenaltyStats();	s.read((char *) stats, sizeof(*stats));	// read key	int klen;	s.read((char *) &klen, sizeof(klen));	char* keyptr = new char[klen];	s.read(keyptr, klen);	stats->key = new vec_t(keyptr, klen);	penaltyStats.push_back((void *) stats);    }    // read avgStats    s.read((char *) &avgStats, sizeof(avgStats));    // check for errors    if (!s) {        return(eFILEERROR);    }    return(RCOK);}/////////////////////////////////////////////////////////////////////////// amdb_penaltystats::evalPenalty - compute PenaltyStats of single insertion//// Description://// Return Values://      RCOK/////////////////////////////////////////////////////////////////////////rc_tamdb_penaltystats::evalPenalty(    gist& tree, // in: target tree    amdb_wkldprofile& profile, // in    const amdb_treemap& tmap, // in    const Vector& queryStructs, // vector<gist_query_t *>    shpid_t leaf, // in: target leaf chosen by penalty metric    const vec_t& key) // in: test key{    PenaltyStats* stats = new PenaltyStats();    profile.setTreeMap(&tmap); // make sure valid map is set    gist_ext_t* ext = tree.extension();    amdb_ext_t* amdbext = amdb_ext_t::extension(ext);    // copy key and set actualLeaf    char* keyptr = new char[key.len(0)];    (void) memcpy(keyptr, key.ptr(0), key.len(0));    stats->key = new vec_t(keyptr, key.len(0));    stats->actualLeaf = leaf;    // determine which queries would retrieve key    Vector matches; // vector<int>: indices of matching queries for 'queries'    _computeMatches(tree, queryStructs, key, matches);    // determine optLeaf and actual- and optAddIos:     // compute additional I/Os for every leaf    stats->optAddIos = MAXINT;    amdb_treemap::PageMap::const_iterator pmit;    for (pmit = tmap.pageMap.begin(); pmit != tmap.pageMap.end(); pmit++) {	amdb_treemap::PageInfo* info = (amdb_treemap::PageInfo *) (*pmit).second;	if (info->level > 1) {	    // this isn't a leaf, ignore it	    continue;	}        shpid_t pageno = (shpid_t) (*pmit).first;	int addIos = _computeExtraIos(tree, profile, tmap, pageno, key, matches);	if (pageno == leaf) {	    // we just looked at the actual target leaf	    stats->actualAddIos = addIos;	}	if (addIos < stats->optAddIos) {	    // we found a better leaf to insert on	    stats->optAddIos = addIos;	    stats->optLeaf = pageno;	}    }

⌨️ 快捷键说明

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