Stxxl  1.4.0
containers/test_deque2.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  containers/test_deque2.cpp
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2012 Timo Bingmann <bingmann@kit.edu>
00007  *  based on containers/test_deque.cpp
00008  *
00009  *  Distributed under the Boost Software License, Version 1.0.
00010  *  (See accompanying file LICENSE_1_0.txt or copy at
00011  *  http://www.boost.org/LICENSE_1_0.txt)
00012  **************************************************************************/
00013 
00014 #include <iterator>
00015 #include <stxxl/deque2>
00016 
00017 int main(int argc, char * argv[])
00018 {
00019     if (argc != 2) {
00020         STXXL_MSG("Usage: " << argv[0] << " #ops");
00021         return -1;
00022     }
00023 
00024     srand(2397423);
00025     stxxl::deque2<int> XXLDeque;
00026     std::deque<int> STDDeque;
00027 
00028     stxxl::int64 ops = stxxl::atoint64(argv[1]);
00029     for (stxxl::int64 i = 0; i < ops; ++i)
00030     {
00031         unsigned curOP = rand() % 5;
00032         unsigned value = rand();
00033         switch (curOP)
00034         {
00035         case 0:
00036         case 1:
00037             XXLDeque.push_front(value);
00038             STDDeque.push_front(value);
00039             break;
00040         case 2:
00041             XXLDeque.push_back(value);
00042             STDDeque.push_back(value);
00043             break;
00044         case 3:
00045             if (!XXLDeque.empty())
00046             {
00047                 XXLDeque.pop_front();
00048                 STDDeque.pop_front();
00049             }
00050             break;
00051         case 4:
00052             if (!XXLDeque.empty())
00053             {
00054                 XXLDeque.pop_back();
00055                 STDDeque.pop_back();
00056             }
00057             break;
00058         }
00059 
00060         assert(XXLDeque.empty() == STDDeque.empty());
00061         assert(XXLDeque.size() == STDDeque.size());
00062 
00063         if (XXLDeque.size() > 0)
00064         {
00065             assert(XXLDeque.back() == STDDeque.back());
00066             assert(XXLDeque.front() == STDDeque.front());
00067         }
00068 
00069         if (!(i % 100000))
00070         {
00071             std::cout << "Complete check of deque (size " << XXLDeque.size() << ")\n";
00072             stxxl::deque2<int>::stream stream = XXLDeque.get_stream();
00073             std::deque<int>::const_iterator b = STDDeque.begin();
00074 
00075             while ( !stream.empty() )
00076             {
00077                 assert( b != STDDeque.end() );
00078                 assert( *stream == *b );
00079                 ++stream; ++b;
00080             }
00081 
00082             assert( b == STDDeque.end() );
00083         }
00084 
00085         if (!(i % 100000))
00086         {
00087             std::cout << "Complete check of reverse deque (size " << XXLDeque.size() << ")\n";
00088             stxxl::deque2<int>::reverse_stream stream = XXLDeque.get_reverse_stream();
00089             std::deque<int>::const_reverse_iterator b = STDDeque.rbegin();
00090 
00091             while ( !stream.empty() )
00092             {
00093                 assert( b != STDDeque.rend() );
00094                 assert( *stream == *b );
00095                 ++stream; ++b;
00096             }
00097 
00098             assert( b == STDDeque.rend() );
00099         }
00100     }
00101 
00102     return 0;
00103 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines