1 /** @file printtree.cpp
3 * print in tree- (indented-) form, so developers can have a look at the
4 * underlying structure. */
11 void ex::printtree(ostream & os, unsigned indent) const
13 debugmsg("ex printtree",LOGLEVEL_PRINT);
15 // os << "refcount=" << bp->refcount << " ";
16 bp->printtree(os,indent);
19 void ex::dbgprinttree(void) const
21 debugmsg("ex dbgprinttree",LOGLEVEL_PRINT);
26 void basic::printtree(ostream & os, unsigned indent) const
28 debugmsg("basic printtree",LOGLEVEL_PRINT);
29 os << string(indent,' ') << "type=" << typeid(*this).name()
30 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
31 << ", flags=" << flags
32 << ", nops=" << nops() << endl;
33 for (int i=0; i<nops(); ++i) {
34 op(i).printtree(os,indent+delta_indent);
38 void basic::dbgprinttree(void) const
43 void numeric::printtree(ostream & os, unsigned indent) const
45 debugmsg("numeric printtree", LOGLEVEL_PRINT);
46 // We are cheating here, because we don't want to include the underlying
47 // bignum package's headers again, so we use ostream::operator<<(numeric):
48 os << string(indent,' ');
51 << "hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
52 << ", flags=" << flags << endl;
55 void symbol::printtree(ostream & os, unsigned indent) const
57 debugmsg("symbol printtree",LOGLEVEL_PRINT);
58 os << string(indent,' ') << name << " (symbol): "
59 << "serial=" << serial
60 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
61 << ", flags=" << flags << endl;
64 void power::printtree(ostream & os, unsigned indent) const
66 debugmsg("power printtree",LOGLEVEL_PRINT);
68 os << string(indent,' ') << "power: "
69 << "hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
70 << ", flags=" << flags << endl;
71 basis.printtree(os,indent+delta_indent);
72 exponent.printtree(os,indent+delta_indent);
75 void expairseq::printtree(ostream & os, unsigned indent) const
77 debugmsg("expairseq printtree",LOGLEVEL_PRINT);
79 os << string(indent,' ') << "type=" << typeid(*this).name()
80 << ", hash=" << hashvalue << " (0x" << hex << hashvalue << dec << ")"
81 << ", flags=" << flags
82 << ", nops=" << nops() << endl;
83 for (unsigned i=0; i<seq.size(); ++i) {
84 seq[i].rest.printtree(os,indent+delta_indent);
85 seq[i].coeff.printtree(os,indent+delta_indent);
86 if (i!=seq.size()-1) {
87 os << string(indent+delta_indent,' ') << "-----" << endl;
90 if (!overall_coeff.is_equal(default_overall_coeff())) {
91 os << string(indent+delta_indent,' ') << "-----" << endl;
92 os << string(indent+delta_indent,' ') << "overall_coeff" << endl;
93 overall_coeff.printtree(os,indent+delta_indent);
95 os << string(indent+delta_indent,' ') << "=====" << endl;
96 #ifdef EXPAIRSEQ_USE_HASHTAB
97 os << string(indent+delta_indent,' ')
98 << "hashtab size " << hashtabsize << endl;
99 if (hashtabsize==0) return;
101 unsigned count[MAXCOUNT+1];
102 for (int i=0; i<MAXCOUNT+1; ++i) count[i]=0;
103 unsigned this_bin_fill;
104 unsigned cum_fill_sq=0;
106 for (unsigned i=0; i<hashtabsize; ++i) {
108 if (hashtab[i].size()>0) {
109 os << string(indent+delta_indent,' ')
110 << "bin " << i << " with entries ";
111 for (epplist::const_iterator it=hashtab[i].begin();
112 it!=hashtab[i].end(); ++it) {
113 os << *it-seq.begin() << " ";
117 cum_fill += this_bin_fill;
118 cum_fill_sq += this_bin_fill*this_bin_fill;
120 if (this_bin_fill<MAXCOUNT) {
121 ++count[this_bin_fill];
128 double lambda=(1.0*seq.size())/hashtabsize;
129 for (int k=0; k<MAXCOUNT; ++k) {
131 double prob=pow(lambda,k)/fact*exp(-lambda);
133 os << string(indent+delta_indent,' ') << "bins with " << k << " entries: "
134 << int(1000.0*count[k]/hashtabsize)/10.0 << "% (expected: "
135 << int(prob*1000)/10.0 << ")" << endl;
137 os << string(indent+delta_indent,' ') << "bins with more entries: "
138 << int(1000.0*count[MAXCOUNT]/hashtabsize)/10.0 << "% (expected: "
139 << int((1-cum_prob)*1000)/10.0 << ")" << endl;
141 os << string(indent+delta_indent,' ') << "variance: "
142 << 1.0/hashtabsize*cum_fill_sq-(1.0/hashtabsize*cum_fill)*(1.0/hashtabsize*cum_fill)
144 os << string(indent+delta_indent,' ') << "average fill: "
145 << (1.0*cum_fill)/hashtabsize
146 << " (should be equal to " << (1.0*seq.size())/hashtabsize << ")" << endl;
147 #endif // def EXPAIRSEQ_USE_HASHTAB