Dlist cumulate(const Dlist& L) { Dlist l = initDlist(L.size()); double a = 0; for (int i=0; i<L.size(); i++) { a += L[i]; l[i] = a; } return l; }
void tabular_result_output(const Dlist<string>& words,int cols) { cout<<"<table>\n<tr>\n"; int rowpos=0; for(int i=0;i<words.size();i++) { cout<<"<td>"<<words[i]<<"</td>\n"; if(!(++rowpos%cols) && (i+1 != words.size())) cout<<"</tr>\n<tr>\n"; } cout<<"</tr>\n</table>\n"; }
Dlist histogram(const Dlist& L, double interval) { Dlist hist; int l = L.size(); for(int i=0; i<l; i++) { double a = L[i]; if (a!=-1) { if (a<0) { printf("Error in print_hist, neg\n"); fl(); } int n = floor(a/interval); if (n>=hist.size()) { hist.resize(n+1); hist[n] = 0;} hist[n]++; } } return hist; }
int main() { Dlist<int> dlist; int i=dlist.size(); std::cout<<i<<std::endl; dlist.push_back(2); for (int j1=0; j1<dlist.size(); ++j1) std::cout<<dlist.value(j1+1)<<'-'; std::cout<<std::endl; dlist.push_front(4); for (int j2=0; j2<dlist.size(); ++j2) std::cout<<dlist.value(j2+1)<<'-'; std::cout<<std::endl; dlist.insert_after(7,1); i=dlist.size(); std::cout<<i<<std::endl; for (int j3=0; j3<dlist.size(); ++j3) std::cout<<dlist.value(j3+1)<<'-'; std::cout<<std::endl; dlist.reverse(); std::cout<<dlist.size()<<std::endl; for (int j4=0; j4<dlist.size(); ++j4) std::cout<<dlist.value(j4+1)<<'-'; std::cout<<std::endl; dlist.clear(); std::cout<<dlist.size()<<std::endl; return 0; }
Dlist percents(const Dlist& L, double n) { Dlist Dl; for (int i=0; i<L.size(); i++) { Dl.push_back(percent(L[i],n)); } return Dl; }
List get_permut_sort(const List& l) { List perm = initList(l.size()); Dlist lp = var(l); Dlist L = lp; std::sort(L.begin(), L.end()); for (int i=0; i<L.size(); i++) { int pos = isfound_pos(L[i],lp); if (pos==-1) printf("Error in get_permut_sort\n"); else perm[i] = pos; } return perm; }
void El_record_maxreduce_info_in_attr(Hyperblock *hb) { Control_cpr_info *attr; int size, i; Operand br_pred, ft_pred; Hash_set<Operand> cpr_preds(hash_operand), derived_on_preds(hash_operand), derived_off_preds(hash_operand); if (dbg(cpr, 3)) cdbg << "Enter El_record_maxreduce_info_in_attr: " << hb->id() << endl; attr = get_control_cpr_info(hb); if (attr != NULL) El_punt("El_record_maxreduce_info_in_attr: HB %d already has an attr", hb->id()); size = hb_br_preds.size(); attr = new Control_cpr_info(size); // Compute set of all preds used for cpr, cpr_preds for (Dlist_iterator<Operand> dl_i(hb_br_preds); dl_i!=0; dl_i++) { cpr_preds += (*dl_i); } for (Dlist_iterator<Operand> dl_i2(hb_ft_preds); dl_i2!=0; dl_i2++) { cpr_preds += (*dl_i2); } for (i=0; i<size; i++) { br_pred = hb_br_preds.pop(); ft_pred = hb_ft_preds.pop(); if (dbg(cpr, 3)) cdbg << "i " << i << " on_trace_pred " << ft_pred << " off_trace_pred " << br_pred << endl; attr->set_on_trace_pred(i, ft_pred); attr->set_off_trace_pred(i, br_pred); El_compute_maxreduce_derived_preds(hb, ft_pred, br_pred, cpr_preds, derived_on_preds, derived_off_preds); if (derived_on_preds.size() > 0) attr->set_derived_on_trace_pred(i, derived_on_preds); if (derived_off_preds.size() > 0) attr->set_derived_off_trace_pred(i, derived_off_preds); } set_control_cpr_info(hb, attr); }
Dlist division(const Dlist& L, double d) { Dlist Dl; for (int i=0; i<L.size(); i++) Dl.push_back(L[i]/d); return Dl; }
int isfound_pos(double n, const Dlist& L) { if (L.size()==0) return -1; for (int i=0; i<L.size(); i++) if (L[i]==n) return i; return -1; }
double sumlist(const Dlist& L) { double d = 0; for (int l=0; l<L.size(); l++) d += L[l]; return d; }
void print_Dlist(str s, const Dlist& L) { printf("%s \n",s.c_str()); int n = L.size(); for (int i=0; i<n; i++) printf("%5d : %.3f\n",i,L[i]); printf("\n"); }