Stxxl
1.4.0
|
00001 /*************************************************************************** 00002 * containers/test_queue2.cpp 00003 * 00004 * Part of the STXXL. See http://stxxl.sourceforge.net 00005 * 00006 * Copyright (C) 2011 Andreas Beckmann <beckmann@cs.uni-frankfurt.de> 00007 * 00008 * Distributed under the Boost Software License, Version 1.0. 00009 * (See accompanying file LICENSE_1_0.txt or copy at 00010 * http://www.boost.org/LICENSE_1_0.txt) 00011 **************************************************************************/ 00012 00013 #define STXXL_VERBOSE_LEVEL 1 00014 00015 #include <stxxl/queue> 00016 00017 typedef stxxl::uint64 my_type; 00018 00019 int main(int argc, char ** argv) 00020 { 00021 if (argc < 2) 00022 { 00023 std::cout << "Usage: " << argv[0] << " [n in MiB]" << std::endl; 00024 return -1; 00025 } 00026 00027 stxxl::int64 mega = 1 << 20; 00028 stxxl::int64 megabytes = atoi(argv[1]); 00029 stxxl::int64 nelements = megabytes * mega / sizeof(my_type); 00030 stxxl::int64 i; 00031 my_type in = 0, out = 0; 00032 00033 stxxl::queue<my_type> q; 00034 00035 STXXL_MSG("op-sequence: ( push, pop, push ) * n"); 00036 for (i = 0; i < nelements; ++i) 00037 { 00038 if ((i % mega) == 0) 00039 STXXL_MSG("Insert " << i); 00040 00041 q.push(in++); 00042 00043 assert(q.front() == out); 00044 q.pop(); 00045 ++out; 00046 00047 q.push(in++); 00048 } 00049 STXXL_MSG("op-sequence: ( pop, push, pop ) * n"); 00050 for ( ; i > 0; --i) 00051 { 00052 if ((i % mega) == 0) 00053 STXXL_MSG("Remove " << i); 00054 00055 assert(q.front() == out); 00056 q.pop(); 00057 ++out; 00058 00059 q.push(in++); 00060 00061 assert(q.front() == out); 00062 q.pop(); 00063 ++out; 00064 } 00065 assert(q.empty()); 00066 assert(in == out); 00067 00068 std::cout << *stxxl::stats::get_instance(); 00069 }