示例#1
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;
}
示例#2
0
// Action_Diffusion::CalcDiffForSet()
void Action_Diffusion::CalcDiffForSet(unsigned int& set, Dlist const& Sets, int Ndim,
                                      std::string const& label) const
{
  for (Dlist::const_iterator ds = Sets.begin(); ds != Sets.end(); ds++)
    if (*ds != 0)
      CalcDiffusionConst(set, *ds, Ndim, label + "_" + integerToString( (*ds)->Meta().Idx() ));
}
/*
 *	Note, to_branch is included in the collapse!!
 */
void El_collapse_compare_chain(Hyperblock *hb, Dlist< Pair<Op*, Op*> > &cpr_block,
				Op *target_branch, Op *to_branch)
{
    Pair<Op*,Op*> cur_pair;
    Op *target_cmpp, *to_cmpp, *cur_branch, *cur_cmpp;
    Operand incoming_pred, br_pred, ft_pred;
    bool flag, last_br;

    target_cmpp = to_cmpp = NULL;
    for (Dlist_iterator<Pair<Op*, Op*> > dl_i(cpr_block); dl_i!=0; dl_i++) {
	cur_pair = *dl_i;
	cur_branch = cur_pair.first;
	cur_cmpp = cur_pair.second;
	if (cur_branch == target_branch)
	    target_cmpp = cur_cmpp;
	if (cur_branch == to_branch)
	    to_cmpp = cur_cmpp;
    }
    
    /* Figure out the value of incoming predicate */
    if (to_cmpp != NULL)
	incoming_pred = to_cmpp->src(PRED1);
    else {
	Pred_lit* new_pred_lit = new Pred_lit(true);
        Operand pred_true(new_pred_lit);
	incoming_pred = pred_true;
    }

    /* Create the collapsed pred and initialize it */
    El_create_collapsed_predicates(br_pred, ft_pred);
    El_insert_initializer_for_collapsed_predicate(hb, br_pred, ft_pred,
							incoming_pred, to_cmpp);

    /* Walk the chain in reverse order, insert collapsed cmpp ops */
    flag = false;
    for (Dlist_iterator<Pair<Op*, Op*> > dl_i2(cpr_block, true); dl_i2!=0; dl_i2--) {
	cur_pair = *dl_i2;
	cur_branch = cur_pair.first;
        cur_cmpp = cur_pair.second;
	last_br = false;
	if (cur_branch == target_branch) {
	    flag = true;
	    last_br = true;
	}
	if (flag == false)
	    continue;
	El_insert_collapsed_cmpp_op(hb, cur_cmpp, br_pred, ft_pred, incoming_pred,
					last_br);
	if (cur_branch == to_branch)
	    break;
    }

    El_reassociate_branch_pred(target_branch, br_pred);
    if (target_cmpp != NULL) {
        El_reassociate_input_operand(hb, target_cmpp->dest(DEST1), br_pred);
        El_reassociate_input_operand(hb, target_cmpp->dest(DEST2), ft_pred);
    }
    hb_br_preds.push_tail(br_pred);
    hb_ft_preds.push_tail(ft_pred);
}
示例#4
0
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;
}
示例#5
0
main()
{
  string s;
  Dlist l;
  Dnode *d;

  while (getline(cin, s)) l.Push_Front(s);
  for (d = l.Begin(); d != l.End(); d = d->flink) cout << d->s << endl;
}
示例#6
0
Dtable mult(const Dtable& T, double d) {
	Dtable t;
	for (int i=0; i<T.size(); i++) {
		Dlist l;
		for (int j=0; j<T[i].size(); j++) {
			l.push_back(T[i][j]*d);
		}
		t.push_back(l);
	}
	return t;
}
示例#7
0
Dtable ddivide_floor(const Table& T, double d) {
	Dtable t;
	for (int i=0; i<T.size(); i++) {
		Dlist l;
		for (int j=0; j<T[i].size(); j++) {
			l.push_back(floor(T[i][j]/d));
		}
		t.push_back(l);
	}
	return t;
}
示例#8
0
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";
}
示例#9
0
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;
}
示例#10
0
Dlist histogram(const Dplist& L, double interval) {
	Dlist hist; int l = L.size();
	for(int i=0; i<l; i++) {
		double a = L[i].f;
		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] += L[i].s;
		}
	}
	return hist;
}
示例#11
0
int main ()
{
  Dlist<int> mylist;
  Dlist<int>::node_type *it1;
  Dlist<int>::node_type *it2;

  // set some values:
  for (int i=1; i<10; ++i) mylist.insert_tail(new Dlist<int>::node_type(i*10));

                              // 10 20 30 40 50 60 70 80 90
  it1 = it2 = mylist.head();  // ^^
  for (int i = 0; i < 6; i++)
	it2 = dlist_next(it2);    // ^                 ^
  it1 = dlist_next(it1);      //    ^              ^

  it1 = mylist.erase(it1);    // 10 30 40 50 60 70 80 90
                              //    ^           ^

  it2 = mylist.erase(it2);    // 10 30 40 50 60 80 90
                              //    ^           ^

  it1 = dlist_next(it1);      //       ^        ^
  it2 = dlist_prev(it2);      //       ^     ^

  mylist.erase(it1,
		  dlist_prev(it2));   // 10 30 60 80 90
                              //        ^

  std::cout << "mylist contains:";
  for (it1=mylist.head(); it1!=mylist.nil(); it1 = dlist_next(it1))
    std::cout << ' ' << it1->key;
  std::cout << '\n';

  return 0;
}
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);
}
int main()
{
	Dlist stack;
	char name[120];
	char food[120];
	bool eating = true;
	bool grass = false;

	cout << "Hi, what is your doggie's name \n";
	cin.getline(name, 119);
	while (eating)
	{
		// eat
		while (!grass)
		{
			cout << "What does " << name << " eat? \n";
			cin.getline(food, 119);
			if (!strcmp(food, "grass"))
			{
				cout << "Oh, no, it looks like " << name <<" is getting sick! Ick...\n";
				break;
			}
			else if (!strcmp(food, "dog food"))
			{
				eating = false;
				break;
			}
			stack.insertBack(food);
		}
		// barf
		while (!stack.empty() && eating)
		{
			cout << name << " barfs up " << stack.removeBack() << endl;
			if (stack.empty())
				cout << "It looks like " << name << " is feeling better now...\n";
		}
	}
	cout << "Ugh! " << name << " is insulted and walks away in a huff!!!\n";
	
    system("Pause");
	return 0;
}
void El_max_reduce_cpr_blocks(Hyperblock *hb, Cont_cpr_match_result &match_result)
{
    Dlist<Dlist< Pair<Op*, Op*> > > hb_cprblocks;
    Dlist< Pair<Op*, Op*> > cur_cprblock;
    Pair<Op*, Op*> cur_tuple;
    Op *first_branch, *cur_branch, *cur_cmpp;

    hb_cprblocks = match_result.cpr_blk_list;

    if (hb_cprblocks.size() == 0) {
        if (dbg(cpr, 2))
            cdbg << "HB " << hb->id() << " has no cpr blocks" << endl;
        return;
    }

    hb_br_preds.clear();
    hb_ft_preds.clear();

    for (Dlist_iterator<Dlist< Pair<Op*, Op*> > > d_iter(hb_cprblocks);
			d_iter!=0; d_iter++) {
	cur_cprblock = *d_iter;
	El_normalize_cprblock(cur_cprblock);

	first_branch = NULL;
	for (Dlist_iterator<Pair<Op*, Op*> > d2_iter(cur_cprblock);
			d2_iter!=0; d2_iter++) {
	    cur_tuple = *d2_iter;
	    cur_branch = cur_tuple.first;
	    cur_cmpp = cur_tuple.second;
	    if (first_branch == NULL) {
		first_branch = cur_branch;
		hb_br_preds.push_tail(cur_cmpp->dest(DEST1));
		hb_ft_preds.push_tail(cur_cmpp->dest(DEST2));
		continue;
	    }
	    El_collapse_compare_chain(hb, cur_cprblock, cur_branch, first_branch);
	}
    }

    El_record_maxreduce_info_in_attr(hb);
}
示例#15
0
文件: dlist.c 项目: AsamQi/levawc
void DLISTdestroy(Dlist list)
{
  void *data;

  while (DLISTsize(list) > 0)
    {
      if (DLISTremove(list, DLISTtail(list), (void **)&data) == 0 && 
          list->destroy != NULL)
        {
          list->destroy(data);
        }
    }
  
  free(list);
}
示例#16
0
文件: dlist.c 项目: AsamQi/levawc
DlistNode DLISTfindnode(Dlist list, const void *data)
{
  DlistNode member = NULL;

  /* If match callback not set */
  if (list->match == NULL)
    return NULL;

  for (member = list->head; member != NULL; member = member->next)
    {
      if (list->match(data, DLISTdata(member)))
        break;
    }
  
  return member;
}
示例#17
0
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;
}
示例#18
0
int main(int argc,char* argv[]) {

  Command cmd(argc,argv);

  try {    

    string dic, board;
    int cols, min, mode;

    try {
      board = cmd.index().get("board");
    } catch(...) {
      cout<<"No board given."<<endl;
      throw;
    }

    try {
      min = atoi(cmd.index().get("min").c_str());
    } catch(...) {
      cout<<"Setting minimum word length to 4"<<endl;
      min=4;
    }
    
    try {
      dic = cmd.index().get("dic");
      for (int i = 0; i < (int)dic.size(); i++) {
        if (!isalpha(dic[i])) {
          dic[i]='_';
        }
      }
    } catch(...) {
      cout<<"Using default dictionary."<<endl;
      dic = "words";
    }

    try {
      mode = atoi(cmd.index().get("mode").c_str());
      if(mode) mode=1;
    }
    catch(...) {cout<<"Using default mode 0"<<endl; mode=0;}

    try {
      cols = atoi(cmd.index().get("cols").c_str());
      if(cols<2 || cols > 100) cols = 10;
    }
    catch(...) {cout<<"Using default output column count."<<endl; cols=10;}


    Untangle s(board.c_str(), dic+".trie", min, mode);

    cout<<"<p>Board size: "<<s.size()<<"<br>\n";
    cout<<"Minimum word length: "<<min<<"<br>\n";
    cout<<"Solve mode: "<<mode<<"</p>\n";



    cout<<"<p>Board:\n";
    print_html(s.get_letters(),min,s.size());
    cout<<"</p>\n"<<endl;

    cout<<"<p>Solving...<br>\n"<<endl;
    s.untangle();
    cout<<"<p>All done, sorting and displaying the result...</p>"<<endl;

    Dlist<string> words;

    cout<<"<h2>Alphabetically</h2>\n";   
    s.result().words_alpha(words);

    tabular_result_output(words,cols);

    words.clear();
    cout<<"<h2>Longest-first</h2>\n";
    s.result().words_length(words);

    tabular_result_output(words,cols);

    ofstream log("solve_log.txt");
    if(log.fail()) throw "Could not open logfile for writing.";

    log<<s.min()<<'\n'<<dic<<'\n'<<s.get_letters()<<'\n';
    log.close();

    cout<<"<p>"<</*s.num_words()<<" words found. */"Solution complete.</p>\n";
    }
  catch(string e) {
    cout<<e<<endl;
    cout<<"Error in getting program parameters."<<endl;
  }
  catch(char* e) {
    cout<<e<<endl;
  }
  catch(...) {
    cout<<"Unspecified error occurred. Please e-mail the author with the parameters that caused this condition."<<endl;
  }
  cout<<"<p>Boggle/Tangleword solver by Michael Hecht (c) 1999-2004</p>\n";
  return 0;  


}
示例#19
0
Dlist initDlist(int l, double val) {
	Dlist L;
	L.resize(l,val);
	return L;
}
示例#20
0
main(int argc, char **argv)
{
  map <string, Dnode *> words;
  Dlist *l;
  Dnode *n;
  vector <string> sv;
  string s;
  string p;

  if (argc != 2) {
    cerr << "usage: list_editor prompt(- for none)\n";
    exit(1);
  }

  l = new Dlist;
  p = argv[1];

  while(1) {
    if (p != "-") {
      printf("%s ", p.c_str());
      fflush(stdout);
    }
    if (!getline(cin, s)) exit(0);

    sv = StoSVec(s);
    if (sv.size() == 0 || sv[0][0] == '#') {
    } else if (sv[0] == "CLEAR") {
      if (sv.size() != 1) {
        printf("CLEAR takes no arguments.\n");
      } else {
        delete l;
        words.clear();
        l = new Dlist;
      }
    } else if (sv[0] == "EMPTY") {
      if (sv.size() != 1) {
        printf("EMPTY takes no arguments.\n");
      } else {
        cout << ((l->Empty()) ? "Yes" : "No") << endl;
      }
    } else if (sv[0] == "SIZE") {
      if (sv.size() != 1) {
        printf("SIZE takes no arguments.\n");
      } else {
        cout << l->Size() << endl;
      }
    } else if (sv[0] == "ERASE") {
      if (sv.size() != 2) {
        printf("ERASE word.\n");
      } else {
        if (words.find(sv[1]) == words.end()) {
          cout << sv[1] << " is not on the list\n";
        } else {
          l->Erase(words[sv[1]]); 
          words.erase(words.find(sv[1]));
        }
      }
    } else if (sv[0] == "INSERT_BEFORE") {
      if (sv.size() != 3) {
        printf("INSERT_BEFORE s1 s2.\n");
      } else {
        if (words.find(sv[1]) != words.end()) {
          cout << sv[1] << " is already on the list\n";
        } else if (words.find(sv[2]) == words.end()) {
          cout << sv[2] << " is not on the list\n";
        } else {
          n = words[sv[2]];
          l->Insert_Before(sv[1], n);
          words[sv[1]] = n->blink;
        }
      }
    } else if (sv[0] == "INSERT_AFTER") {
      if (sv.size() != 3) {
        printf("INSERT_AFTER s1 s2.\n");
      } else {
        if (words.find(sv[1]) != words.end()) {
          cout << sv[1] << " is already on the list\n";
        } else if (words.find(sv[2]) == words.end()) {
          cout << sv[2] << " is not on the list\n";
        } else {
          n = words[sv[2]];
          l->Insert_After(sv[1], n);
          words[sv[1]] = n->flink;
        }
      }
    } else if (sv[0] == "PUSH_BACK") {
      if (sv.size() != 2) {
        printf("PUSH_BACK word.\n");
      } else {
        if (words.find(sv[1]) != words.end()) {
          cout << sv[1] << " is already on the list\n";
        } else {
          l->Push_Back(sv[1]);
          words[sv[1]] = l->Rbegin();
        }
      }
    } else if (sv[0] == "PUSH_FRONT") {
      if (sv.size() != 2) {
        printf("PUSH_FRONT word.\n");
      } else {
        if (words.find(sv[1]) != words.end()) {
          cout << sv[1] << " is already on the list\n";
        } else {
          l->Push_Front(sv[1]);
          words[sv[1]] = l->Begin();
        }
      }
    } else if (sv[0] == "POP_FRONT") {
      if (sv.size() != 1) {
        printf("POP_FRONT takes no arguments.\n");
      } else if (l->Empty()) {
        printf("POP_FRONT called on an empty list.\n");
      } else {
        s = l->Pop_Front();
        words.erase(words.find(s));
        cout << s << endl;
      }
    } else if (sv[0] == "POP_BACK") {
      if (sv.size() != 1) {
        printf("POP_BACK takes no arguments.\n");
      } else if (l->Empty()) {
        printf("POP_BACK called on an empty list.\n");
      } else {
        s = l->Pop_Back();
        words.erase(words.find(s));
        cout << s << endl;
      }
    } else if (sv[0] == "PRINT_FORWARD") {
      if (sv.size() != 1) {
        printf("PRINT_FORWARD takes no arguments.\n");
      } else {
        for (n = l->Begin(); n != l->End(); n = n->flink) {
          if (n != l->Begin()) cout << " ";
          cout << n->s;
        }
        cout << endl;
      }
    } else if (sv[0] == "QUIT") {
      exit(0);
    } else if (sv[0] == "PRINT_REVERSE") {
      if (sv.size() != 1) {
        printf("PRINT_REVERSE takes no arguments.\n");
      } else {
        for (n = l->Rbegin(); n != l->Rend(); n = n->blink) {
          if (n != l->Rbegin()) cout << " ";
          cout << n->s;
        }
        cout << endl;
      }
    } else {
      printf("Bad command\n");
    }
  }
  
}
示例#21
0
double sumlist(const Dlist& L) {
	double d = 0;
	for (int l=0; l<L.size(); l++) d += L[l];
	return d;
}
示例#22
0
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");
}
示例#23
0
/** Copy constructor.
 *  @param src is a Dlist whose contents are copied to this Dlist.
 */
Dlist::Dlist(const Dlist& src) : List(src) {
	makeSpace(); init();
	for (index x = src.first(); x != 0; x = src.next(x))
		pred[x] = src.pred[x];
}
示例#24
0
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;
}
示例#25
0
Dlist var(const List& L) {
	Dlist v;
	for (int i=0; i<L.size(); i++) v.push_back(L[i]+fRand(0,0.2));
	return v;
}
示例#26
0
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;
}
示例#27
0
/*
 *	FRPize a superblock using the if-converter
 */
void El_frpize_sbs(Procedure *f)
{
    Basicblock *entry_bb;
    Hyperblock *hb;
    List_set<Basicblock*> hb_bbs;
    Hash_set<Hyperblock*> all_hbs;
    bool push_flag, applied;
    Dlist<Region*> rstack;
    Region *rtmp;
    Compound_region *new_hb;

    if (dbg(cpr, 2))
        cdbg << "Enter frpize sbs" << endl;

    // First find all the HBs in f and add them to set all_hbs
    rstack.push(f);
    while (! rstack.is_empty()) {
        rtmp = rstack.pop();
        push_flag = true;
        if (rtmp->is_hb()) {
	    all_hbs += ((Hyperblock *) rtmp);
            push_flag = false;  // Only ops below, so don't waste time!
        }
        else if (rtmp->is_bb()) {
            push_flag = false;  // Only ops below, so don't waste time!
        }
        if (push_flag==true) {
            for (Region_subregions subri(rtmp); subri!=0; subri++) {
                if ((*subri)->is_compound())
                    rstack.push(*subri);
            }
        }
    }

    // Now walk thru hash_set and frpize it
    applied = false;
    for (Hash_set_iterator<Hyperblock*> hseti(all_hbs); hseti!=0; hseti++) {
	hb = *hseti;
	if (dbg(cpr, 2))
	    cdbg << "Processing HB " << hb->id() << endl;
	if (! El_is_frpizable(hb)) {
	    if (dbg(cpr, 2))
		cdbg << "\tHB " << hb->id() << " not frpizable" << endl;
	    continue;
	}
	hb_bbs.clear();
	El_find_bbs_in_hb(hb, &entry_bb, hb_bbs);
	El_remove_region(hb, false);
	El_fprize_this_sb(f, entry_bb, hb_bbs);
	new_hb = entry_bb->parent();
	if (! new_hb->is_hb())
	   El_punt("El_frpize_sbs: HB not correctly inserted");
	// Copy over id/flags/lcode_attrs from hb to new_hb
	new_hb->set_id(hb->id());
	delete new_hb->attributes;
	new_hb->attributes = new Graph_attribute(*(hb->attributes)) ;
	((Region *)new_hb)->copy_flags(hb);
	// 1 of the flags will be the SB flag, so reset that one
	new_hb->reset_flag(EL_REGION_SUPERBLOCK);
	new_hb->set_flag(EL_REGION_HYPERBLOCK_FRP);
	applied = true;
	delete hb;
    }

    if (applied == true)
	f->set_flag(EL_PROC_HYPERBLOCK);
}