algo/test_random_shuffle.cpp

Test stxxl::random_shuffle()

00001 /***************************************************************************
00002  *  algo/test_random_shuffle.cpp
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2007 Manuel Krings
00007  *  Copyright (C) 2007 Markus Westphal
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 
00016 
00017 #include <stxxl/random_shuffle>
00018 
00019 
00020 template <typename type>
00021 struct counter
00022 {
00023     type value;
00024     counter(type v = type(0)) : value(v) { }
00025     type operator () ()
00026     {
00027         type old_val = value;
00028         value++;
00029         return old_val;
00030     }
00031 };
00032 
00033 
00034 int main()
00035 {
00036     typedef stxxl::vector<int> ext_vec_type;
00037     ext_vec_type STXXLVector(1024 * 1024 * 256 / sizeof(int));
00038 
00039     STXXL_MSG("Filling vector with increasing values...");
00040     stxxl::generate(STXXLVector.begin(), STXXLVector.end(),
00041                     counter<stxxl::uint64>(), 4);
00042 
00043     stxxl::uint64 i;
00044 
00045     STXXL_MSG("Begin: ");
00046     for (i = 0; i < 10; i++)
00047         STXXL_MSG(STXXLVector[i]);
00048 
00049     STXXL_MSG("End: ");
00050     for (i = STXXLVector.size() - 10; i < STXXLVector.size(); i++)
00051         STXXL_MSG(STXXLVector[i]);
00052 
00053     STXXL_MSG("Permute randomly...");
00054     stxxl::random_shuffle(STXXLVector.begin(), STXXLVector.end(), 1024 * 1024 * 128);
00055 
00056 
00057     STXXL_MSG("Begin: ");
00058     for (i = 0; i < 10; i++)
00059         STXXL_MSG(STXXLVector[i]);
00060 
00061     STXXL_MSG("End: ");
00062     for (i = STXXLVector.size() - 10; i < STXXLVector.size(); i++)
00063         STXXL_MSG(STXXLVector[i]);
00064 }

Generated on Thu Jun 4 10:21:43 2009 for Stxxl by  doxygen 1.4.7