📄 eqclass.cpp,v
字号:
head 1.2;access;symbols;locks zaki:1.2; strict;comment @// @;1.2date 2001.06.24.19.16.01; author zaki; state Exp;branches;next 1.1;1.1date 2001.06.06.00.04.45; author zaki; state Exp;branches;next ;desc@@1.2log@added pruning.@text@#include <stack>#include <algorithm> #include "eqclass.h"#include "treeminer.h"bool Eqnode::find_in_tlist(vector<int> &par, int lit, ival &it, int stpos){ idlist::iterator ii; for (ii = &tlist[stpos]; ii != tlist.end(); ++ii){ if (equal(par.begin(), par.end(), (*ii).parscope.begin())){ if ((lit == (*ii).parscope.back()) && (ival::compare((*ii).itscope, it) == equals)) return true; } } return false;}ostream & operator<<(ostream& ostr, Eqnode& eqn){ int *fidx = Dbase_Ctrl_Blk::FreqIdx; ostr << fidx[eqn.val] << " (" << eqn.pos << ") - " << eqn.sup << endl; if (output_idlist) ostr << eqn.tlist; return ostr;}Eqclass::~Eqclass(){ //list<Eqnode *>::iterator ni = _nodelist.begin(); for_each(nlist().begin(), nlist().end(), delnode<Eqnode *>());} void Eqclass::add_node(int val, int pos, int sup=0){ Eqnode *eqn = new Eqnode(val,pos,sup); _nodelist.push_back(eqn);}void Eqclass::add_node(Eqnode *eqn){ _nodelist.push_back(eqn);}int Eqclass::item(int n) { int i,k; //cout << "in item: " << n << " " << _prefix.size() << endl; for (i=0,k=0; i < _prefix.size(); i++){ if (_prefix[i] != BranchIt){ if (k == n) return _prefix[i]; k++; } } return -1;}//return the scope of the prefixint Eqclass::get_scope(int pos, int &scope){ int scnt=0; for (int i=0; i < _prefix.size(); i++){ if (_prefix[i] == BranchIt) scnt--; else scnt++; if (i == pos) scope = scnt; } return scnt;} void Eqclass::set_prefix(vector<int> &pref, Eqnode &node){ _prefix = pref; int scope, scnt; scnt = get_scope(node.pos, scope); //what is the scope of node.pos while(scnt > scope){ _prefix.push_back(BranchIt); scnt--; } _prefix.push_back(node.val);}ostream & Eqclass::print_prefix(ostream& fout){ for (int i=0; i < _prefix.size(); i++){ if (_prefix[i] == BranchIt) fout << BranchIt << " "; else fout << Dbase_Ctrl_Blk::FreqIdx[_prefix[i]] << " "; } return fout;}//print with items remapped to their original valuevoid Eqclass::print(){ list<Eqnode *>::iterator ni = _nodelist.begin(); int st, en; for (; ni != _nodelist.end(); ni++){ print_prefix(); en = get_scope((*ni)->pos, st); while (en > st){ st++; cout << BranchIt << " "; } cout << Dbase_Ctrl_Blk::FreqIdx[(*ni)->val] << " - " << (*ni)->sup << endl; }} ostream& operator << (ostream& fout, Eqclass& eq){ list<Eqnode *>::iterator ni = eq._nodelist.begin(); int st, en; for (; ni != eq._nodelist.end(); ni++){ eq.print_prefix(fout); en = eq.get_scope((*ni)->pos, st); while (en > st){ st++; fout << BranchIt << " "; } fout << *(*ni); } return fout;} @1.1log@Initial revision@text@d2 1a2 1d27 6@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -