Stxxl
1.4.0
|
00001 /*************************************************************************** 00002 * containers/test_deque.cpp 00003 * 00004 * Part of the STXXL. See http://stxxl.sourceforge.net 00005 * 00006 * Copyright (C) 2006 Roman Dementiev <dementiev@ira.uka.de> 00007 * Copyright (C) 2009 Andreas Beckmann <beckmann@cs.uni-frankfurt.de> 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/deque> 00016 00017 00018 int main(int argc, char * argv[]) 00019 { 00020 if (argc != 2) { 00021 STXXL_MSG("Usage: " << argv[0] << " #ops"); 00022 return -1; 00023 } 00024 00025 stxxl::deque<int> Deque; 00026 00027 stxxl::deque<int>::const_iterator b = Deque.begin(); 00028 stxxl::deque<int>::const_iterator e = Deque.end(); 00029 assert(b == e); 00030 Deque.push_front(1); 00031 Deque.push_front(2); 00032 Deque.push_front(3); 00033 b = Deque.begin(); 00034 assert(b != e); 00035 Deque.push_back(5); 00036 std::copy(Deque.begin(), Deque.end(), std::ostream_iterator<int>(std::cout, " ")); 00037 00038 stxxl::random_number32 rand; 00039 stxxl::deque<int> XXLDeque; 00040 std::deque<int> STDDeque; 00041 00042 stxxl::int64 ops = stxxl::atoint64(argv[1]); 00043 for (stxxl::int64 i = 0; i < ops; ++i) 00044 { 00045 unsigned curOP = rand() % 6; 00046 unsigned value = rand(); 00047 switch (curOP) 00048 { 00049 case 0: 00050 case 1: 00051 XXLDeque.push_front(value); 00052 STDDeque.push_front(value); 00053 break; 00054 case 2: 00055 XXLDeque.push_back(value); 00056 STDDeque.push_back(value); 00057 break; 00058 case 3: 00059 if (!XXLDeque.empty()) 00060 { 00061 XXLDeque.pop_front(); 00062 STDDeque.pop_front(); 00063 } 00064 break; 00065 case 4: 00066 if (!XXLDeque.empty()) 00067 { 00068 XXLDeque.pop_back(); 00069 STDDeque.pop_back(); 00070 } 00071 break; 00072 case 5: 00073 if (XXLDeque.size() > 0) 00074 { 00075 stxxl::deque<int>::iterator XXLI = XXLDeque.begin() + (value % XXLDeque.size()); 00076 std::deque<int>::iterator STDI = STDDeque.begin() + (value % STDDeque.size()); 00077 *XXLI = value; 00078 *STDI = value; 00079 unsigned value1 = rand(); 00080 if (XXLI - XXLDeque.begin() == 0) 00081 break; 00082 00083 XXLI = XXLI - (value1 % (XXLI - XXLDeque.begin())); 00084 STDI = STDI - (value1 % (STDI - STDDeque.begin())); 00085 *XXLI = value1; 00086 *STDI = value1; 00087 } 00088 break; 00089 } 00090 00091 assert(XXLDeque.empty() == STDDeque.empty()); 00092 assert(XXLDeque.size() == STDDeque.size()); 00093 assert(XXLDeque.end() - XXLDeque.begin() == STDDeque.end() - STDDeque.begin()); 00094 //assert(std::equal(XXLDeque.begin(),XXLDeque.end(),STDDeque.begin() _STXXL_FORCE_SEQUENTIAL)); 00095 if (XXLDeque.size() > 0) 00096 { 00097 assert(XXLDeque.back() == STDDeque.back()); 00098 assert(XXLDeque.front() == STDDeque.front()); 00099 } 00100 00101 if (!(i % 100000)) 00102 { 00103 assert(std::equal(XXLDeque.begin(), XXLDeque.end(), STDDeque.begin() _STXXL_FORCE_SEQUENTIAL)); 00104 STXXL_MSG("Operations done: " << i << " size: " << STDDeque.size()); 00105 } 00106 } 00107 00108 return 0; 00109 }