예제 #1
0
파일: deque.cpp 프로젝트: ziqifan16/Lintel
void testNoDefaultConstructor() {
    Deque<NoDefaultConstructor> deque;

    deque.reserve(8);

    for(int i = 0; i < 5; ++i) {
        deque.push_back(NoDefaultConstructor(i));
        SINVARIANT(deque.back().v == i);
        SINVARIANT(deque.size() == static_cast<size_t>(i + 1));
        INVARIANT(NoDefaultConstructor::ndc_count == i + 1, format("%d != %d + 1")
                  % NoDefaultConstructor::ndc_count % i);
    }

    for(int i = 0; i < 5; ++i) {
        SINVARIANT(deque.front().v == i);
        deque.pop_front();
        deque.push_back(NoDefaultConstructor(i));
        SINVARIANT(deque.back().v == i);
        SINVARIANT(deque.size() == 5);
        SINVARIANT(NoDefaultConstructor::ndc_count == 5);
    }

    for(int i = 0; i < 5; ++i) {
        SINVARIANT(deque.front().v == i);
        deque.pop_front();
        SINVARIANT(deque.size() == static_cast<size_t>(4 - i));
        SINVARIANT(NoDefaultConstructor::ndc_count == 4 - i);
    }
    SINVARIANT(NoDefaultConstructor::ndc_count == 0);
}
void testQuickSort(){
    cout<<"***********************"<<endl;
    cout<<"******quick sort*******"<<endl;
    Deque<int> deque;
    deque.push_front(10);
    deque.push_back(3);
    deque.push_back(2);
    deque.push_front(4);
    deque.output();
    hds::quickSort(deque.begin(),deque.end());
    deque.output();
    hds::quickSort(deque.begin(),deque.end(),hds::Greater<int>());
    deque.output();

    deque.clear();
    for(int i=0;i < 20;++i){
        deque.push_back(i+10);
    }
    deque.insert(deque.begin()+10,2);
    deque.insert(deque.begin()+2,34);
    deque.insert(deque.begin()+16,6);
    deque.insert(deque.begin()+13,78);
    deque.output();
    hds::quickSort(deque.begin(),deque.end(),hds::Greater<int>());
    deque.output();
    cout<<"***********************"<<endl;
}
예제 #3
0
TEST(Deque, grow)
{
    Deque d;
    for (int i = 0; i < 10; i++)
        d.push_back(i);
    d.push_back(10);
    CHECK(11 == d.size());
    CHECK(10 == d.pop_back());
}
예제 #4
0
TEST (Deque, double_test)
{
	Deque<double> d;
	d.push_front(0.1);
	d.push_back(1.1);
	d.push_back(2.1);
	d.push_back(3.1);
	CHECK ( 4 == d.size() );
	CHECK ( 0.1 == d.pop_front() );
	CHECK ( 3.1 == d.pop_back() );
}
예제 #5
0
TEST(Deque, doit)
{
    Deque d;
    d.push_front(0);
    d.push_back(1);
    d.push_back(2);
    d.push_back(3);
    CHECK(4 == d.size());
    CHECK(0 == d.pop_front());
    CHECK(3 == d.pop_back());
}
예제 #6
0
파일: deque.cpp 프로젝트: ziqifan16/Lintel
void testAssign() {
    Deque<int> a;
    a.push_back(1);
    a.push_back(2);
    a.push_back(3);

    vector<int> b;
    b.assign(a.begin(), a.end());
    SINVARIANT(b.size() == 3);
    for(int32_t i = 0; i < 3; ++i) {
        SINVARIANT(b[i] == i+1);
    }
}
예제 #7
0
파일: deque.cpp 프로젝트: ziqifan16/Lintel
void testPushBack() {
    Deque<int> deque;

    SINVARIANT(deque.empty());
    deque.reserve(8);
    SINVARIANT(deque.empty() && deque.capacity() == 8);
    for(int i = 0; i < 5; ++i) {
        deque.push_back(i);
        SINVARIANT(deque.back() == i);
        SINVARIANT(deque.size() == static_cast<size_t>(i + 1));
    }

    for(int i = 0; i < 5; ++i) {
        SINVARIANT(deque.at(i) == i);
    }

    for(int i = 0; i < 5; ++i) {
        SINVARIANT(deque.front() == i);
        deque.pop_front();
        deque.push_back(i);
        SINVARIANT(deque.back() == i);
        SINVARIANT(deque.size() == 5);
    }

    for(int i = 0; i < 5; ++i) {
        SINVARIANT(deque.at(i) == i);
    }

    {
        Deque<int>::iterator i = deque.begin();
        int j = 0;
        while(i != deque.end()) {
            INVARIANT(*i == j, format("%d != %d") % *i % j);
            ++i;
            ++j;
        }
    }

    vector<int> avec;
    for(int i = 5; i < 10; ++i) {
        avec.push_back(i);
    }
    deque.push_back(avec);

    for(int i = 0; i < 10; ++i) {
        SINVARIANT(deque.front() == i);
        deque.pop_front();
    }
    SINVARIANT(deque.empty());
}
예제 #8
0
파일: test.cpp 프로젝트: nzinov/home_tasks
TEST(EmptyDequeTest, Random) {
    std::deque<int> control;
    Deque<int> deque;
    for (size_t i = 0; i < CHUNK_COUNT; ++i) {
        clock_t time = clock();
        for (size_t c = 0; c < CHUNK_SIZE; ++c) {
            int operand = rand();
            switch (rand() % 4) {
                case 0:
                    deque.push_back(operand);
                    control.push_back(operand);
                    break;
                case 1:
                    deque.push_front(operand);
                    control.push_front(operand);
                    break;
                case 2:
                    if (control.size() == 0) {
                        break;
                    }
                    EXPECT_EQ(deque.pop_front(), control.front());
                    control.pop_front();
                    break;
                case 3:
                    if (control.size() == 0) {
                        break;
                    }
                    EXPECT_EQ(deque.pop_back(), control.back());
                    control.pop_back();
                    break;
            }
        }
        std::cout << clock() - time << std::endl;
    }
}
예제 #9
0
 void update(int64_t packet_raw, int packet_size, const Int64TimeField &packet_at,
             const string &filename) {
     LintelLogDebug("IPRolling::packet", format("UPD %d %d") % packet_raw % packet_size);
     if (!packets_in_flight.empty()) {
         int64_t cur_back_ts_raw = packets_in_flight.back().timestamp_raw;
         INVARIANT(packet_raw >= cur_back_ts_raw,
                   format("out of order by %.4fs in %s; %d < %d") 
                   % packet_at.rawToDoubleSeconds(cur_back_ts_raw - packet_raw) % filename
                   % packet_raw % cur_back_ts_raw);
     }
     while ((packet_raw - cur_time_raw) > interval_width_raw) {
         // update statistics for the interval from cur_time to cur_time + interval_width
         // all packets in p_i_f must have been received in that interval
         double bw = cur_bytes_in_queue * MiB_per_second_convert;
         MiB_per_second.add(bw);
         double pps = packets_in_flight.size() * kpackets_per_second_convert;
         kpackets_per_second.add(pps);
         LintelLogDebug("IPRolling::detail", format("[%d..%d[: %.0f, %d -> %.6g %.6g")
                        % cur_time_raw % (cur_time_raw + update_step_raw)
                        % cur_bytes_in_queue % packets_in_flight.size() % bw % pps);
         cur_time_raw += update_step_raw;
         while (! packets_in_flight.empty() &&
               packets_in_flight.front().timestamp_raw < cur_time_raw) {
             cur_bytes_in_queue -= packets_in_flight.front().packetsize;
             packets_in_flight.pop_front();
         }
     }
     packets_in_flight.push_back(packetTimeSize(packet_raw, packet_size));
     cur_bytes_in_queue += packet_size;
 }
예제 #10
0
void HyperDijkstra::visitAdjacencyMap(AdjacencyMap& amap, TreeAction* action, bool useDistance)
{

    typedef std::deque<HyperGraph::Vertex*> Deque;
    Deque q;
    // scans for the vertices without the parent (whcih are the roots of the trees) and applies the action to them.
    for (AdjacencyMap::iterator it=amap.begin(); it!=amap.end(); ++it) {
        AdjacencyMapEntry& entry(it->second);
        if (! entry.parent()) {
            action->perform(it->first,0,0);
            q.push_back(it->first);
        }
    }

    //std::cerr << "q.size()" << q.size() << endl;
    int count=0;
    while (! q.empty()) {
        HyperGraph::Vertex* parent=q.front();
        q.pop_front();
        ++count;
        AdjacencyMap::iterator parentIt=amap.find(parent);
        if (parentIt==amap.end()) {
            continue;
        }
        //cerr << "parent= " << parent << " parent id= " << parent->id() << "\t children id =";
        HyperGraph::VertexSet& childs(parentIt->second.children());
        for (HyperGraph::VertexSet::iterator childsIt=childs.begin(); childsIt!=childs.end(); ++childsIt) {
            HyperGraph::Vertex* child=*childsIt;
            //cerr << child->id();
            AdjacencyMap::iterator adjacencyIt=amap.find(child);
            assert (adjacencyIt!=amap.end());
            HyperGraph::Edge* edge=adjacencyIt->second.edge();

            assert(adjacencyIt->first==child);
            assert(adjacencyIt->second.child()==child);
            assert(adjacencyIt->second.parent()==parent);
            if (! useDistance) {
                action->perform(child, parent, edge);
            } else {
                action->perform(child, parent, edge, adjacencyIt->second.distance());
            }
            q.push_back(child);
        }
        //cerr << endl;
    }

}
예제 #11
0
TEST(Deque, pop_back)
{
    Deque d;
    d.push_back(0);
    d.push_back(1);
    CHECK(1 == d.pop_back());
    CHECK(0 == d.pop_back());
}
예제 #12
0
파일: main.cpp 프로젝트: nakulj/csci-102
int main()
{
	cout << "It runs!" << endl;
	
	//create a stack & show it works
	Stack<int> s;
        s.pop();
        s.print();
        cout<<"Empty?  "<<s.empty()<<endl;
        cout<<s.size()<<endl;
        for(int i=0; i<10; i++) {
            s.push(2*i+1);
            s.print();
            cout<<s.size()<<endl<<endl;
        }
        cout<<"Empty?  "<<s.empty()<<endl;
        cout<<"The top is "<<(s.top())<<endl;
        for(int i=0; i<12; i++) {
            s.pop();
            s.print();
        }
        cout<<"The top is "<<(s.top())<<endl;
	//create a queue & show it works
	Queue<int> q;
        q.print();
        cout<<"Empty?  "<<q.empty()<<endl;
        cout<<q.size()<<endl;
        for(int i=0; i<10; i++) {
            q.push(2*i+1);
            q.print();
            cout<<q.size()<<endl<<endl;
        }
        cout<<"Empty?  "<<q.empty()<<endl;
        cout<<"The front is "<<(q.front())<<endl;
        cout<<"The rear is "<<(q.back())<<endl;
        for(int i=0; i<12; i++) {
            q.pop();
            q.print();
        }
        cout<<"The front is "<<(q.front())<<endl;
        cout<<"The rear is "<<(q.back())<<endl;

        Deque<int> d;
        d.print();
        for(int i=0; i<10; i++) {
            d.push_back(i);
            d.print();
        }
        for(int i=0; i<10; i++) {
            if(i%2==0) {cout<<"back"<<endl;
                d.pop_back();}
            else{cout<<"front"<<endl;
                d.pop_front();}
            d.print();
        }
}
예제 #13
0
파일: 10194.cpp 프로젝트: liuhb86/uva
int main(){

	int n;
	cin>>n;
	string s;
	getline(cin,s);
	Deque dteams;
	Map mteams;
	bool first=true;
	for(int i=0;i<n;i++){
		dteams.clear(); mteams.clear();
		if(first) first=false; else cout<<endl;
		getline(cin,s);
		cout<<s<<endl;
		int numTeam,numMatch;
		cin>>numTeam;
		getline(cin,s);
		for(int j=0;j<numTeam;j++){
			getline(cin,s);
			dteams.push_back(Team(s));
			mteams.insert(make_pair(s,&(dteams.back())));
		}
		cin>>numMatch;
		getline(cin,s);
		for(int j=0;j<numMatch;j++){
			Team* t1,*t2;
			int score1,score2;
			getline(cin,s,'#');
			t1=mteams.find(s)->second;
			cin>>score1;
			getline(cin,s,'@');
			cin>>score2;
			getline(cin,s,'#');
			getline(cin,s);
			t2=mteams.find(s)->second;
			t1->goalScored+=score1;
			t1->goalAgainst+=score2;
			t2->goalScored+=score2;
			t2->goalAgainst+=score1;
			if(score1>score2){t1->win++;t2->lose++;}
			else if(score1<score2){t1->lose++;t2->win++;}
			else {t1->tie++;t2->tie++;}
		}
		sort(dteams.begin(),dteams.end());
		int rank=1;
		for(Deque::iterator it=dteams.begin();it!=dteams.end();it++,rank++){
			cout<<rank<<") "<<it->name<<" "<<it->point()<<"p, "<<it->total()<<
				"g ("<<it->win<<"-"<<it->tie<<"-"<<it->lose<<"), "<<
				it->goalDiff()<<"gd ("<<it->goalScored<<"-"<<it->goalAgainst<<")"<<endl;
		}
		//cout<<endl;
	}	
}
예제 #14
0
int main(){
    Deque *d = new Deque();
    d->push_front(1);
    d->push_back(2);
    d->push_back(3);
    d->push_front(0);
    d->pop_front();
    d->pop_back();
    d->print();
    delete d;
    return 0;
}
예제 #15
0
void testShellSort(){
    cout<<"***********************"<<endl;
    cout<<"******shell sort*******"<<endl;
    Deque<int> deque;
    deque.push_front(10);
    deque.push_back(3);
    deque.push_back(2);
    deque.push_front(4);
    deque.output();
    hds::shellSort(deque.begin(),deque.end());
    deque.output();
    hds::shellSort(deque.begin(),deque.end(),hds::Greater<int>());
    deque.output();
    cout<<"***********************"<<endl;
}
예제 #16
0
void testMergeSortBU(){
    cout<<"***********************"<<endl;
    cout<<"****merge sort BU******"<<endl;
    Deque<int> deque;
    deque.push_front(10);
    deque.push_back(3);
    deque.push_back(2);
    deque.push_front(4);
    deque.output();
    hds::mergeSortBU(deque.begin(),deque.end());
    deque.output();
    hds::mergeSortBU(deque.begin(),deque.end(),hds::Greater<int>());
    deque.output();
    cout<<"***********************"<<endl;
}
예제 #17
0
파일: deque.cpp 프로젝트: ziqifan16/Lintel
// verify that the destructor is called on pop_front.
void testDestroy() {
    Deque<Thing> things;

    for(uint32_t i = 0; i < 10; ++i) {
        INVARIANT(Thing::thing_count == i, format("%d != %d") % Thing::thing_count % i);
        things.push_back(Thing());
    }

    for(uint32_t i = 0; i < 10; ++i) {
        SINVARIANT(Thing::thing_count == (10-i));
        things.pop_front();
    }

    SINVARIANT(Thing::thing_count == 0);
}
예제 #18
0
void testInsertionSort(){
    cout<<"***********************"<<endl;
    cout<<"*****insertion sort****"<<endl;
    Deque<int> deque;
    deque.push_front(10);
    deque.push_back(3);
    deque.push_back(2);
    deque.push_front(4);
    deque.output();
    hds::insertionSort(deque.begin(),deque.end());
    deque.output();
    hds::insertionSort(deque.begin(),deque.end(),hds::Greater<int>());
    deque.output();
    cout<<"***********************"<<endl;
}
예제 #19
0
파일: Ch8_Ex23.cpp 프로젝트: EDA-TADs/EDA
//--------------------Linear solution----------------------
void minimumValues(int v[], int k) {
	Deque<int> d = Deque<int>(); // In the queue I store positions, no elements

	for (int i = 0; i < N; i++)
	{
		if (i >= k) // Until we have not consider a subarray, we can not print the minimums.
			cout << v[d.front()] << " ";

		while (!d.empty() && v[d.back()] >= v[i]) { // While the queue is not empty and the element I want to insert is
												   // greater or equal than the last one I extract the last element
			d.pop_back();
		}
		d.push_back(i); // I insert the new element

		if (d.front() <= i - k) //This remove the minimum once is out of the subarray
			d.pop_front();
	}
	cout << v[d.front()] << endl;
}
예제 #20
0
파일: test.cpp 프로젝트: delhuy12/ecs60
int main()
{
Deque<int> A ; 
int  i ;
for( i = 0; i<200; i++)
{
	A.push_back(i);
	A.push_front(i);	
}
A[100] = 2;
int retval = A[100];
cout<<A[100]<<endl;
cout << retval << endl;
//for (i =100;i>0;i++)
//	A[i] = i;  
/*for( i =0; i<10;i++)
{
	A.pop_front();
	A.pop_back();
}

for (i = 0; i<4; i++)
{
        A.push_back(i);
        A.push_front(i);
}
for( i =0; i<2;i++)
{
        A.pop_front();
        A.pop_back();
}*/

//A.print();
A[50]=5;
for( i=0; i<400;i++)
	cout<<i<<" "<<A[i]<<"\n";
//A[2399]=5;
return 0;
}
예제 #21
0
파일: history.cpp 프로젝트: descent/progs
int main()
{

#if 0
  CString cstr;

  cstr.init("abc");
  cstr.print();
  printf("\n");

  Deque<CString> deque;
  deque.init();

  deque.push_back(cstr);

  CString ps;
  ps = "102";

  cstr.init("def");
  deque.push_back(cstr);

  deque.print();
  deque.back(0, ps);
  ps.print();
  printf("\n");
#endif

#if 1
  setlocale(LC_ALL, "");

  initscr();
  keypad(stdscr,true);
  curs_set(0);
  // KEY_UP
  // KEY_DOWN

  //Deque<string> deque;
  Deque<CString> deque;

  deque.init();

  move(0,0);
  int fail_time=1;
  while(1)
  {
    char str[128];
    getstr(str);
    move(0,0);
    //std::string s(str);
    CString s;
    s.init(str);
    if (deque.push_back(s) == false)
    {
      mvprintw(20, 0, "push back fail ## %d", fail_time++);
      deque.pop_front();
      deque.push_back(s);
    }

    deque.print();

    int index=0;
    noecho();
    //string ps;
    CString ps;
    while(1)
    {
      mvprintw(17, 0, "index: %d", index);
      refresh();
      int ch = getch();
      switch(ch)
      {
        case KEY_UP:
        {
          ++index;
          if (deque.back(index, ps) == true)
          {
            mvprintw(0, 15, "%s", ps.c_str());
          }
          else
            --index;
          break;
        }
        case KEY_DOWN:
        {
          --index;
          if (deque.back(index, ps) == true)
          {
            mvprintw(0, 15, "%s", ps.c_str());
          }
          else
          {
            //mvprintw(17, 5, "back fail");
            ++index;
          }
          break;
        }
        case 'q':
        {
          goto end;
        }
        default:
        {
          ungetch(ch);
          move(0, 0);
          goto outer;
          break;
        }
      }
      mvprintw(17, 0, "index: %d", index);
      refresh();
    }
    outer:
    echo();
  }
end:
  endwin();
#endif
  return 0;
}
void test_deque()
{
	const size_t SIZE = 10;
	Deque<int, SIZE> deque;

	cout << "--> testing push_back..." << endl;
	for (size_t i = 0; i < SIZE; i++)
	{
		try
		{
			deque.push_back(i);
		}
		catch (std::overflow_error &e)
		{
			cout << "i: " << i << endl;
			cout << e.what() << endl;
		}
	}
	deque.traverse(print);
	cout << endl;
	cout << "size: " << deque.size() << endl;
	deque.print_mark();

	cout << "--> testing pop_back..." << endl;
	while (!deque.empty())
	{
		deque.pop_back();
	}
	deque.traverse(print);
	cout << endl;
	cout << "size: " << deque.size() << endl;
	deque.print_mark();
	
	cout << "--> testing push_front..." << endl;
	for (size_t i = 0; i < SIZE; i++)
	{
		try
		{
			deque.push_front(i);
		}
		catch (std::overflow_error &e)
		{
			cout << "i: " << i << endl;
			cout << e.what() << endl;
		}
	}
	deque.traverse(print);
	cout << endl;
	cout << "size: " << deque.size() << endl;
	deque.print_mark();
	
	cout << "--> testing pop_front..." << endl;
	while (!deque.empty())
	{
		deque.pop_front();
	}
	deque.traverse(print);
	cout << endl;
	cout << "size: " << deque.size() << endl;
	deque.print_mark();
}
예제 #23
0
파일: mona.cpp 프로젝트: ondrik/mona-vata
int 
main(int argc, char *argv[])
{
  std::set_new_handler(&mem_error);

  if (!ParseArguments(argc, argv)) {
    Usage();
    exit(-1);
  }

  // Disable core dump
  struct rlimit r_core;
  r_core.rlim_cur = 0;
  r_core.rlim_max = 0;
  setrlimit(RLIMIT_CORE, &r_core);

  // Set demo limits 
  if (options.demo) {
    struct rlimit r_cpu, r_as;
    memlimit = true;

    r_cpu.rlim_cur = 30; // max 30 secs.
    r_cpu.rlim_max = 30;
    setrlimit(RLIMIT_CPU, &r_cpu);

    r_as.rlim_cur = 20971520; // max 20MB
    r_as.rlim_max = 20971520;
    setrlimit(RLIMIT_DATA, &r_as);

    signal(SIGXCPU, &cpuLimit);
  }

  initTimer();
  Timer timer_total;
  timer_total.start();
  
  ///////// PARSING ////////////////////////////////////////////////////////

  if (options.printProgress)
    cout << "MONA v" << VERSION << "-" << RELEASE <<  " for WS1S/WS2S\n"
      "Copyright (C) 1997-2008 BRICS\n\n"
      "PARSING\n";

  Timer timer_parsing;
  timer_parsing.start();

  loadFile(inputFileName);
  yyparse();
  MonaAST *ast = untypedAST->typeCheck();
  lastPosVar = ast->lastPosVar;
  allPosVar = ast->allPosVar;

  timer_parsing.stop();

  if (options.printProgress) {
    cout << "Time: ";
    timer_parsing.print();
  }

  delete untypedAST;

  if (options.dump) {
    // Dump AST for main formula, verify formulas, and assertion
    cout << "Main formula:\n";
    (ast->formula)->dump();
    Deque<ASTForm *>::iterator vf;
    Deque<char *>::iterator vt;
    for (vf = ast->verifyformlist.begin(), vt = ast->verifytitlelist.begin();
	 vf != ast->verifyformlist.end(); vf++, vt++) {
      cout << "\n\nFormula " << *vt << ":\n";
      (*vf)->dump();
    }
    cout << "\n\nAssertions:\n";
    (ast->assertion)->dump();
    cout << "\n";

    if (lastPosVar != -1)
      cout << "\nLastPos variable: " 
	   << symbolTable.lookupSymbol(lastPosVar) << "\n";
    if (allPosVar != -1)
      cout << "\nAllPos variable: " 
	   << symbolTable.lookupSymbol(allPosVar) << "\n";
    
    // Dump ASTs for predicates and macros
    PredLibEntry *pred = predicateLib.first();
    while (pred != NULL) {
      if (pred->isMacro)
	cout << "\nMacro '";
      else
	cout << "\nPredicate '";
      cout << symbolTable.lookupSymbol(pred->name) 
	   << "':\n";
      (pred->ast)->dump();
      cout << "\n";
      pred = predicateLib.next();
    }

    // Dump restrictions
    if (symbolTable.defaultRestriction1) {
      cout << "\nDefault first-order restriction (" 
	   << symbolTable.lookupSymbol(symbolTable.defaultIdent1) << "):\n";
      symbolTable.defaultRestriction1->dump();
      cout << "\n";
    }
    if (symbolTable.defaultRestriction2) {
      cout << "\nDefault second-order restriction (" 
	   << symbolTable.lookupSymbol(symbolTable.defaultIdent2) << "):\n";
      symbolTable.defaultRestriction2->dump();
      cout << "\n";
    }

    Ident id;
    for (id = 0; id < (Ident) symbolTable.noIdents; id++) {
      Ident t;
      ASTForm *f = symbolTable.getRestriction(id, &t);
      if (f) {
	cout << "\nRestriction for #" << id << " (" 
	     << symbolTable.lookupSymbol(id) << "):";
	if (t != -1)
	  cout << " default\n";
	else {
	  cout << "\n";
	  f->dump();
	  cout << "\n";
	}
      }
    }
  }

  if (options.mode != TREE && 
      (options.graphvizSatisfyingEx || options.graphvizCounterEx ||
       options.inheritedAcceptance)) 
    cout << "Warning: options -gc, -gs, and -h are only used in tree mode\n";
  if (options.mode == TREE && options.graphvizDFA)
    cout << "Warning: option -gw is only used in linear mode\n";
  
  if (options.mode == TREE && (options.dump || options.whole) && 
      !options.externalWhole)
    printGuide();


  ///////// CODE GENERATION ////////////////////////////////////////////////
  
  if (options.printProgress)
    cout << "\nCODE GENERATION\n";
  Timer timer_gencode;
  timer_gencode.start();
  
  // Generate code
  codeTable = new CodeTable;
  VarCode formulaCode = ast->formula->makeCode();
  VarCode assertionCode = ast->assertion->makeCode();
  Deque<VarCode> verifyCode;
  /* #warning NEW: 'VERIFY' */
  for (Deque<ASTForm *>::iterator i = ast->verifyformlist.begin(); 
       i != ast->verifyformlist.end(); i++)
    verifyCode.push_back((*i)->makeCode());

  // Implicitly assert restrictions for all global variables
  for (IdentList::iterator i = ast->globals.begin(); 
       i != ast->globals.end(); i++)
    assertionCode = andList(assertionCode, getRestriction(*i, NULL));

  // Restrict assertion if not trivial
  if (assertionCode.code->kind != cTrue)
    assertionCode = codeTable->insert
      (new Code_Restrict(assertionCode, assertionCode.code->pos));

  // Add assertion to main formula and to all verify formulas
  for (Deque<VarCode>::iterator i = verifyCode.begin(); 
       i != verifyCode.end(); i++) {
    assertionCode.code->refs++;
    *i = andList(*i, VarCode(copy(assertionCode.vars), assertionCode.code));
  }
  formulaCode = andList(formulaCode, assertionCode);

  timer_gencode.stop();
  if (options.printProgress) {
    codeTable->print_statistics();
    /* if (options.dump && options.statistics)
      codeTable->print_sizes(); */
    cout << "Time: ";
    timer_gencode.print();
  }
  
  ///////// REORDER BDD OFFSETS ////////////////////////////////////////////

  if (options.reorder >= 1) {
    Timer timer_reorder;
    timer_reorder.start();
    if (options.printProgress)
      cout << "\nREORDERING\n";

    // reorder using heuristics
    offsets.reorder();
    
    // regenerate DAG in new codetable
    CodeTable *oldCodeTable = codeTable, *newCodeTable = new CodeTable;
    IdentList emptylist;
    codeTable = newCodeTable;
    regenerate = true; // force making new nodes
    VarCode newcode = formulaCode.substCopy(&emptylist, &emptylist);
    Deque<VarCode> newverifycode;
    for (Deque<VarCode>::iterator i = verifyCode.begin(); 
	 i != verifyCode.end(); i++)
      newverifycode.push_back((*i).substCopy(&emptylist, &emptylist));
    codeTable->clearSCTable();
    regenerate = false;
    codeTable = oldCodeTable;
    formulaCode.remove();
    for (Deque<VarCode>::iterator i = verifyCode.begin(); 
	 i != verifyCode.end(); i++)
      (*i).remove();
    formulaCode = newcode;
    verifyCode.reset();
    for (Deque<VarCode>::iterator i = newverifycode.begin(); 
	 i != newverifycode.end(); i++)
      verifyCode.push_back(*i);
    delete oldCodeTable;
    codeTable = newCodeTable;

    if (options.printProgress) {
      codeTable->print_statistics2();
      cout << "Time: ";
      timer_reorder.print();
    }
  }

  ///////// REDUCTION AND CODE DUMPING /////////////////////////////////////

  if (options.optimize >= 1) {
    if (options.printProgress)
      cout << "\nREDUCTION\n";
    Timer timer_reduction;
    timer_reduction.start();
    
    // Reduce
    formulaCode.reduceAll(&verifyCode);

    timer_reduction.stop();
    if (options.printProgress) {
      codeTable->print_reduction_statistics();
      /* if (options.dump && options.statistics)
	 codeTable->print_sizes(); */
      cout << "Time: ";
      timer_reduction.print();
    }
  }
  
  if (options.dump) {
    // Dump symboltable
    symbolTable.dump();
    
    // Dump code
    cout << "\nMain formula:\n";
    formulaCode.dump();
    cout << "\n\n";
    Deque<VarCode>::iterator i;
    Deque<char *>::iterator j;
    for (i = verifyCode.begin(), j = ast->verifytitlelist.begin(); 
	 i != verifyCode.end(); i++, j++) {
      cout << "Formula " << *j << ":\n";
      (*i).dump();
      cout << "\n\n";
    }
  }
  
  if (options.graphvizDAG) {
    printf("digraph MONA_CODE_DAG {\n"
	   " size = \"7.5,10.5\";\n"
	   " main [shape = plaintext];\n"
	   " main -> L%lx;\n", 
	   (unsigned long) formulaCode.code);
    formulaCode.code->viz();
    Deque<VarCode>::iterator i;
    Deque<char *>::iterator j;
    for (i = verifyCode.begin(), j = ast->verifytitlelist.begin(); 
	 i != verifyCode.end(); i++, j++) {
      printf(" \"%s\" [shape = plaintext];\n"
	     " \"%s\" -> L%lx;\n", 
	     *j, *j, (unsigned long) (*i).code);
      (*i).code->viz();
    }
    formulaCode.unmark();
    for (Deque<VarCode>::iterator i = verifyCode.begin(); 
	 i != verifyCode.end(); i++)
      (*i).unmark();
    cout << "}\n";
  }

  ///////// AUTOMATON CONSTRUCTION /////////////////////////////////////////

  // Make variable lists
  Deque<char *> *verifytitlelist = ast->verifytitlelist.copy();
  if (lastPosVar != -1)
    ast->globals.remove(lastPosVar); 
  if (allPosVar != -1)
    ast->globals.remove(allPosVar); 
  ast->globals.sort(); // sort by id (= index)
  int numVars = ast->globals.size();
  int ix = 0;
  char **vnames = new char*[numVars];
  unsigned *offs = new unsigned[numVars];
  char *types = new char[numVars];
  int **univs = new int*[numVars];
  int *trees = new int[numVars];
  SSSet *statespaces = new SSSet[numVars];
  IdentList sign, freeVars;
  IdentList::iterator id;
  for (id = ast->globals.begin(); id != ast->globals.end(); id++, ix++) {
    statespaces[ix] = stateSpaces(*id);
    vnames[ix] = symbolTable.lookupSymbol(*id);
    offs[ix] = offsets.off(*id);
    sign.push_back(ix);
    freeVars.push_back(*id);
    switch (symbolTable.lookupType(*id)) {
    case VarnameTree:
      trees[ix] = 1;
      break;
    default:
      trees[ix] = 0;
    }
    IdentList *uu = symbolTable.lookupUnivs(*id);
    if (uu) {
      unsigned j;
      univs[ix] = new int[uu->size()+1];
      for (j = 0; j < uu->size(); j++)
	univs[ix][j] = symbolTable.lookupUnivNumber(uu->get(j));
      univs[ix][j] = -1;
    }
    else
      univs[ix] = 0;
    switch (symbolTable.lookupType(*id)) 
      {
      case Varname0: 
	types[ix] = 0;
	break;
      case Varname1: 
	types[ix] = 1;
	break;
      default:
	types[ix] = 2;
	break;
      }
  }
  
  if (options.printProgress)
    cout << "\nAUTOMATON CONSTRUCTION\n";

  Timer timer_automaton;
  timer_automaton.start();
  
  DFA *dfa = 0;
  Deque<DFA *> dfalist;
  GTA *gta = 0;
  Deque<GTA *> gtalist;
  
  // Initialize
  bdd_init();
  codeTable->init_print_progress();

  if (options.mode != TREE) { 
    // Generate DFAs
    dfa = formulaCode.DFATranslate();
    if (lastPosVar != -1)
      dfa = st_dfa_lastpos(dfa, lastPosVar);
    if (allPosVar != -1)
      dfa = st_dfa_allpos(dfa, allPosVar);
    for (Deque<VarCode>::iterator i = verifyCode.begin(); 
	 i != verifyCode.end(); i++) {
      DFA *d = (*i).DFATranslate();
      if (lastPosVar != -1)
	d = st_dfa_lastpos(d, lastPosVar);
      if (allPosVar != -1)
	d = st_dfa_allpos(d, allPosVar);
      dfalist.push_back(d);
    }
  }
  else { 
    // Generate GTAs
    gta = formulaCode.GTATranslate();
    if (allPosVar != -1)
      gta = st_gta_allpos(gta, allPosVar);
    for (Deque<VarCode>::iterator i = verifyCode.begin(); 
	 i != verifyCode.end(); i++) {
      GTA *g = (*i).GTATranslate();
      if (allPosVar != -1)
	g = st_gta_allpos(g, allPosVar);
      gtalist.push_back(g);
    }
  }
  formulaCode.remove();
  for (Deque<VarCode>::iterator i = verifyCode.begin(); 
       i != verifyCode.end(); i++)
    (*i).remove();
  
  timer_automaton.stop();
  if (options.printProgress) {
    if (options.statistics)
      cout << "Total automaton construction time: ";
    else
      cout << "Time: ";
    timer_automaton.print();
  }

  delete ast;
  delete codeTable;

  ///////// PRINT AUTOMATON ////////////////////////////////////////////////

  DFA *dfa2 = dfa;
  GTA *gta2 = gta;
  Deque<DFA *> *dfalist2 = &dfalist;
  Deque<GTA *> *gtalist2 = &gtalist;

  if (options.whole &&
      !options.externalWhole)
    cout << "\n";
  if (options.unrestrict) {
    // Unrestrict automata
    if (options.mode != TREE) {
      DFA *t = dfaCopy(dfa2);
      dfaUnrestrict(t);
      dfa2 = dfaMinimize(t);
      dfaFree(t);
      dfalist2 = new Deque<DFA *>;
      for (Deque<DFA *>::iterator i = dfalist.begin(); i != dfalist.end(); i++) {
	t = dfaCopy(*i);
	dfaUnrestrict(t);
	dfalist2->push_back(dfaMinimize(t));
	dfaFree(t);
      }
    }
    else {
      GTA *t = gtaCopy(gta2);
      gtaUnrestrict(t);
      gta2 = gtaMinimize(t);
      gtaFree(t);
      gtalist2 = new Deque<GTA *>;
      for (Deque<GTA *>::iterator i = gtalist.begin(); i != gtalist.end(); i++) {
	t = gtaCopy(*i);
	gtaUnrestrict(t);
	gtalist2->push_back(gtaMinimize(t));
	gtaFree(t);	
      }
    }
  }

  if (options.whole)
    // Print whole automaton
    if (options.mode != TREE) {
      if (options.externalWhole) {
	if (!dfalist.empty())
	  cout << "Main formula:\n";
	DFA *t = dfaCopy(dfa2);
	st_dfa_replace_indices(t, &sign, &freeVars, false, true);
	dfaExport(t, 0, numVars, vnames, types);
	dfaFree(t);
	Deque<DFA *>::iterator i;
	Deque<char *>::iterator j;
	for (i = dfalist2->begin(), j = verifytitlelist->begin();
	     i != dfalist2->end(); i++, j++) {
	  cout << "\nFormula " << *j << ":\n";
	  t = dfaCopy(*i);
	  st_dfa_replace_indices(t, &sign, &freeVars, false, true);
	  dfaExport(t, 0, numVars, vnames, types);
	  dfaFree(t);
	}
      }
      else if (options.graphvizDFA) {
	dfaPrintGraphviz(dfa2, numVars, offs);
	for (Deque<DFA *>::iterator i = dfalist2->begin(); i != dfalist2->end(); i++)
	  dfaPrintGraphviz(*i, numVars, offs);
      }
      else {
	if (!dfalist.empty())
	  cout << "Main formula:\n";
	dfaPrint(dfa2, numVars, vnames, offs);
	Deque<DFA *>::iterator i;
	Deque<char *>::iterator j;
	for (i = dfalist2->begin(), j = verifytitlelist->begin(); 
	     i != dfalist2->end(); i++, j++) {
	  cout << "\nFormula " << *j << ":\n";
	  dfaPrint(*i, numVars, vnames, offs);
	}
      }
    }
    else {
      if (options.externalWhole) {
	if (!gtalist.empty())
	  cout << "Main formula:\n";
	GTA *t = gtaCopy(gta2);
	st_gta_replace_indices(t, &sign, &freeVars, false, true);
	gtaExport(t, 0, numVars, vnames, types, statespaces, 
		  options.inheritedAcceptance);
	gtaFree(t);
	Deque<GTA *>::iterator i;
	Deque<char *>::iterator j;
	for (i = gtalist2->begin(), j = verifytitlelist->begin();
	     i != gtalist2->end(); i++, j++) {
	  cout << "\nFormula " << *j << ":\n";
	  t = gtaCopy(*i);
	  st_gta_replace_indices(t, &sign, &freeVars, false, true);
	  gtaExport(t, 0, numVars, vnames, types, statespaces, 
		    options.inheritedAcceptance);
	  gtaFree(t);
	}
      }
      else {
	if (!gtalist.empty())
	  cout << "Main formula:\n";
	gtaPrint(gta2, offs, numVars, vnames, 
		 options.inheritedAcceptance);
	Deque<GTA *>::iterator i;
	Deque<char *>::iterator j;
	for (i = gtalist2->begin(), j = verifytitlelist->begin();
	     i != gtalist2->end(); i++, j++) {
	  cout << "\nFormula " << *j << ":\n";
	  gtaPrint(*i, offs, numVars, vnames, 
		   options.inheritedAcceptance);
	}
      }
    }
  else if (options.analysis &&
	   !options.graphvizSatisfyingEx &&
	   !options.graphvizCounterEx &&
	   options.printProgress) {
    // Print summary only
    if (options.mode != TREE) {
      if (!dfalist.empty())
	cout << "Main formula:";
      dfaPrintVitals(dfa2);
      Deque<DFA *>::iterator i;
      Deque<char *>::iterator j;
      for (i = dfalist2->begin(), j = verifytitlelist->begin(); 
	   i != dfalist2->end(); i++, j++) {
	cout << "\nFormula " << *j << ":";
	dfaPrintVitals(*i);
      }
    }
    else {
      if (!gtalist.empty())
	cout << "Main formula:";
      gtaPrintTotalSize(gta2);
      Deque<GTA *>::iterator i;
      Deque<char *>::iterator j;
      for (i = gtalist2->begin(), j = verifytitlelist->begin(); 
	   i != gtalist2->end(); i++, j++) {
	cout << "\nFormula " << *j << ":";
	gtaPrintTotalSize(*i);
      }
    }
  }
  if (dfa2 != dfa) {
    dfaFree(dfa2);
    for (Deque<DFA *>::iterator i = dfalist2->begin(); i != dfalist2->end(); i++) 
      dfaFree(*i);
    delete dfalist2;
  }
  if (gta2 != gta) {
    gtaFree(gta2);
    for (Deque<GTA *>::iterator i = gtalist2->begin(); i != gtalist2->end(); i++) 
      gtaFree(*i);
    delete gtalist2;
  }

  ///////// AUTOMATON ANALYSIS /////////////////////////////////////////////

  if (options.analysis) {
    if (options.printProgress)
      cout << "\nANALYSIS\n";
    
    if (options.mode != TREE) {
      if (!dfalist.empty())
	cout << "Main formula:\n";
      dfaAnalyze(dfa, numVars, vnames, offs, types, 
		 options.treemodeOutput);
      Deque<DFA *>::iterator i;
      Deque<char *>::iterator j;
      for (i = dfalist.begin(), j = verifytitlelist->begin(); 
	   i != dfalist.end(); i++, j++) {
	cout << "\nFormula " << *j << ":\n";
	dfaAnalyze(*i, numVars, vnames, offs, types, 
		   options.treemodeOutput);
      }
    }
    else {
      if (numTypes == 0 || options.treemodeOutput) {
	if (!gtalist.empty())
	  cout << "Main formula:\n";
	gtaAnalyze(gta, numVars, vnames, offs,
		   options.graphvizSatisfyingEx,
		   options.graphvizCounterEx);
	Deque<GTA *>::iterator i;
	Deque<char *>::iterator j;
	for (i = gtalist.begin(), j = verifytitlelist->begin(); 
	     i != gtalist.end(); i++, j++) {
	  cout << "\nFormula " << *j << ":\n";
	  gtaAnalyze(*i, numVars, vnames, offs,
		     options.graphvizSatisfyingEx,
		     options.graphvizCounterEx);
	}
      }
      else {
	if (options.graphvizSatisfyingEx ||
	    options.graphvizCounterEx)
	  cout << "Graphviz output of typed trees not implemented.\n";
	if (!gtalist.empty())
	  cout << "Main formula:\n";
	gtaTypeAnalyze(gta, numVars, vnames, types, offs, univs, trees);
	Deque<GTA *>::iterator i;
	Deque<char *>::iterator j;
	for (i = gtalist.begin(), j = verifytitlelist->begin(); 
	     i != gtalist.end(); i++, j++) {
	  cout << "\nFormula " << *j << ":\n";
	  gtaTypeAnalyze(*i, numVars, vnames, types, offs, univs, trees);
	}
      }
    }
  }

  ///////// CLEAN UP ///////////////////////////////////////////////////////

  if (options.mode != TREE) {
    dfaFree(dfa);
    for (Deque<DFA *>::iterator i = dfalist.begin(); i != dfalist.end(); i++)
      dfaFree(*i);
  }
  else {
    gtaFree(gta);
    for (Deque<GTA *>::iterator i = gtalist.begin(); i != gtalist.end(); i++)
      gtaFree(*i);
    freeGuide();
  }
  delete verifytitlelist;

  Deque<FileSource *>::iterator i;
  for (i = source.begin(); i != source.end(); i++)
    delete *i;
  
  for (ix = 0; ix < numVars; ix++) {
    delete[] univs[ix];
    mem_free(statespaces[ix]);
  }
  delete[] statespaces;
  delete[] vnames;
  delete[] offs;
  delete[] types;
  delete[] univs;
  delete[] trees;
  freeTreetypes();
    
  if (options.statistics)
    print_statistics();

  if (options.time) {
    timer_total.stop();
    cout << "\nTotal time:     ";
    timer_total.print();
    print_timing();
  }
  else if (options.printProgress) { 
    timer_total.stop();
    cout << "\nTotal time: ";
    timer_total.print();
  }
#ifdef MAXALLOCATED
  cout << "Maximum space allocated: " << (maxallocated+524288)/1048576 << " MB\n";
#endif
}
예제 #24
0
 void AddElements(int size)
 {
     fori(i, size)
         deque_int.push_back(random(engine));
 }
예제 #25
0
TEST(Deque, push_back)
{
    Deque d;
    d.push_back(0);
    CHECK(1 == d.size());
}
예제 #26
0
파일: deque.cpp 프로젝트: ziqifan16/Lintel
void testIteratorOperations() {
    Deque<int> deque;
    MersenneTwisterRandom rng;
    int n_ops = rng.randInt(100);
    for (int i = 0; i < n_ops; ++i) {
        if (rng.randInt(10) < 3 && !deque.empty()) {
            deque.pop_front();
        } else {
            deque.push_back(rng.randInt());
        }
    }

    // Test iterator unary operators
    {
        for (Deque<int>::iterator it = deque.begin(); it != deque.end(); ) {
            Deque<int>::iterator it1 = it;
            Deque<int>::iterator it2 = it;
            SINVARIANT(it1 == it2);
            Deque<int>::iterator it3 = it1++;
            INVARIANT(it3 == it && it3 != it1 && it1 != it2,
                      "return unchanged && return different from iterator && iterator changed");
            Deque<int>::iterator it4 = ++it2;
            INVARIANT(it4 != it && it4 == it1 && it2 == it1,
                      "return changed && return == updated && two updates same");
            it = it4;
        }
    }

    // Test distance operators
    Deque<int>::iterator it_forward = deque.begin();
    Deque<int>::iterator it_backward = deque.end();
    ptrdiff_t dist_from_start = 0; // start can be .begin() or .end()
    ptrdiff_t dist_from_finish = deque.end() - deque.begin(); // finish can be .end() or .begin()
    for (; it_forward != deque.end(); ++dist_from_start, --dist_from_finish) {
        SINVARIANT(it_backward - it_forward == dist_from_finish - dist_from_start);

        SINVARIANT(it_forward + dist_from_finish == deque.end());
        SINVARIANT(it_backward - dist_from_finish == deque.begin());

        SINVARIANT((it_forward < it_backward) == (dist_from_start < dist_from_finish));
        SINVARIANT((it_forward <= it_backward) == (dist_from_start <= dist_from_finish));

        SINVARIANT((it_forward > it_backward) == (dist_from_start > dist_from_finish));
        SINVARIANT((it_forward >= it_backward) == (dist_from_start >= dist_from_finish));

        Deque<int>::iterator temp_a(it_forward);
        Deque<int>::iterator temp_b;
        temp_b = it_backward;
        SINVARIANT(temp_b - temp_a == dist_from_finish - dist_from_start);

        temp_a += dist_from_finish;
        SINVARIANT(temp_a == deque.end());
        temp_b -= dist_from_finish;
        SINVARIANT(temp_b == deque.begin());
        if (rng.randBool()) { // Exercise both variants of the increment/decrement operators
            ++it_forward;
            --it_backward;
        } else {
            it_forward++;
            it_backward--;
        }
    }
    SINVARIANT(it_backward == deque.begin());
    SINVARIANT(static_cast<size_t>(dist_from_start) == deque.size());
    SINVARIANT(dist_from_finish == 0);
}
예제 #27
0
파일: Deque.cpp 프로젝트: dataseries/Lintel
void
DequeTest()
{
    Deque<int> testq;

    Deque<int> testBad(256);
    for(int i=0;i<512;i++) {
	testBad.push_back(i);
    }
    for(int i=0;i<512;i++) {
	INVARIANT(testBad.empty() == false && testBad.front() == i,
		  "simple test failed?!");
	testBad.pop_front();
    }

    // test empty->size1->empty
    for(int size1=1;size1<2000;size1++) {
	INVARIANT(testq.empty()==true,"internal");
	for(int j=0;j<size1;j++) {
	    testq.push_back(j);
	    INVARIANT(testq.empty()==false,"internal");
	}
	for(int j=0;j<size1;j++) {
	    INVARIANT(testq.empty()==false,"internal");
	    INVARIANT(testq.front() == j,
		      boost::format("Internal Error: %d/%d")
		      % size1 % j);
	    testq.pop_front();
	}
	INVARIANT(testq.empty()==true,"internal");
    }
    printf("pass empty->full->empty tests\n");
    // test empty->size1, size2 add/remove, ->empty
    for(int size1=1;size1<150;size1++) {
	for(int size2=1;size2<400;size2++) {
	    INVARIANT(testq.empty()==true,"internal");
	    for(int j=0;j<size1;j++) {
		testq.push_back(j);
		INVARIANT(testq.empty()==false,"internal");
	    }
	    for(int j=0;j<size2;j++) {
		INVARIANT(testq.empty()==false,"internal");
		INVARIANT(testq.front() == j,
			  boost::format("Internal Error: %d/%d/%d")
			  % size1 % size2 %j);
		testq.pop_front();
		testq.push_back((j+size1));
	    }
	    for(int j=size2;j<size1+size2;j++) {
		INVARIANT(testq.empty()==false,"internal");
		int t = testq.front();
		testq.pop_front();
		INVARIANT(t == j,
			  boost::format("Internal Error: %d/%d/%d/%d")
			  % t % size1 % size2 % j);
	    }
	    INVARIANT(testq.empty()==true,"internal");
	}
    }
    printf("pass partial fill tests\n");
}
예제 #28
0
파일: test-deque.c 프로젝트: maksverver/BSc
int main(int argc, char *argv[])
{
    Deque *deque;
    char line[4096];
    size_t len;
    void *data;
    size_t size;

    if (argc == 1)
    {
        deque = Memory_Deque_create();
    }
    else
    if (argc == 2 && argv[1][0] != '-')
    {
        deque = File_Deque_create(argv[1]);
    }
    else
    {
        printf("Usage:\n"
               "  test-deque            -- use the in-memory deque\n"
               "  test-deque <path>     -- use the file-based deque\n"
               "\n"
               "Commands:\n"
               "  destroy       -- destroy the deque and exit\n"
               "  empty         -- report if the deque is empty\n"
               "  size          -- print number of elements in the deque\n"
               "  push_back     -- add element at the back\n"
               "  push_front    -- add element at the front\n"
               "  get_back      -- print element at the back\n"
               "  get_front     -- print element at the front\n"
               "  pop_back      -- remove element at the back\n"
               "  pop_front     -- remove element at the front\n");
        return 1;
    }

    if (deque == NULL)
    {
        fprintf(stderr, "Unable to create deque!\n");
        exit(1);
    }

    while (fgets(line, sizeof(line), stdin) != NULL)
    {
        /* Determine length and strip trailing newline character */
        len = strlen(line);
        if (len == 0)
            break;
        if (line[len - 1] == '\n')
        {
            line[len - 1] = '\0';
            len -= 1;
        }

        if (strcmp(line, "destroy") == 0)
        {
            break;
        }
        else
        if (strcmp(line, "empty") == 0)
        {
            printf("empty=%s\n", deque->empty(deque) ? "true" : "false");
        }
        else
        if (strcmp(line, "size") == 0)
        {
            printf("size=%ld\n", (long)deque->size(deque));
        }
        else
        if (strncmp(line, "push_back ", 10) == 0)
        {
            if (!deque->push_back(deque, line + 10, len - 10))
                printf("push_back failed!\n");
        }
        else
        if (strncmp(line, "push_front ", 11) == 0)
        {
            if (!deque->push_front(deque, line + 11, len - 11))
                printf("push_front failed!\n");
        }
        else
        if (strcmp(line, "get_back") == 0)
        {
            if (!deque->get_back(deque, &data, &size))
                printf("get_back failed!\n");
            else
            {
                fwrite(data, size, 1, stdout);
                fputc('\n', stdout);
            }
        }
        else
        if (strcmp(line, "get_front") == 0)
        {
            if (!deque->get_front(deque, &data, &size))
                printf("get_front failed!\n");
            else
            {
                fwrite(data, size, 1, stdout);
                fputc('\n', stdout);
            }
        }
        else
        if (strcmp(line, "pop_back") == 0)
        {
            if (!deque->pop_back(deque))
                printf("pop_back failed!\n");
        }
        else
        if (strcmp(line, "pop_front") == 0)
        {
            if (!deque->pop_front(deque))
                printf("pop_front failed!\n");
        }
        else
        {
            printf("Unrecognized input line: %s!\n", line);
        }
    }

    deque->destroy(deque);

    return 0;
}