- Main Page
- Modules
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

# sample10.cpp

Go to the documentation of this file.

    00001 /*
    00002 Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)
    00003
    00004 Permission is hereby granted, free of charge, to any person
    00005 obtaining a copy of this software and associated documentation
    00006 files (the "Software"), to deal in the Software without restriction,
    00007 including without limitation the rights to use, copy, modify, merge,
    00008 publish, distribute, sublicense, and/or sell copies of the Software,
    00009 and to permit persons to whom the Software is furnished to do so,
    00010 subject to the following conditions:
    00011
    00012 The above copyright notice and this permission notice shall be included
    00013 in all copies or substantial portions of the Software.
    00014
    00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    00016 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
    00017 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    00018 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
    00019 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    00020 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    00021 OTHER DEALINGS IN THE SOFTWARE.
    00022 */
    00023
    00024 /** \example sample10.cpp
    00025   Example of how to get random subset of a bit-vector
    00026
    00027   For more information please visit:  http://bmagic.sourceforge.net
    00028
    00029   \sa bm::random_subset
    00030  */
    00031
    00032
    00033 #include <iostream>
    00034 #include "bm.h"
    00035 #include "bmrandom.h"
    00036
    00037 using namespace std;
    00038
    00039 template<class T> void PrintContainer(T first, T last)
    00040 {
    00041     if (first == last)
    00042         cout << "<EMPTY SET>";
    00043     else
    00044         for(;first != last; ++first)
    00045             cout << *first << ";";
    00046     cout << endl;
    00047 }
    00048
    00049
    00050 int main(void)
    00051 {
    00052     bm::bvector<>   bv;
    00053
    00054     // -----------------------------------------------
    00055     // set some bits
    00056     //
    00057     unsigned i;
    00058     for (i = 0; i < 30000; i+=10)
    00059     {
    00060         bv.set(i);
    00061     }
    00062
    00063     for (i = 300000; i < 400000; i+=100)
    00064     {
    00065         bv.set(i);
    00066     }
    00067
    00068     bm::bvector<>   bvsubset1;
    00069     bm::bvector<>   bvsubset2;
    00070
    00071     // random sampler instance can be shared between calls
    00072     //
    00073     bm::random_subset<bm::bvector<> > rand_sampler;
    00074     rand_sampler.sample(bvsubset1, bv, 20);
    00075     rand_sampler.sample(bvsubset2, bv, 20);
    00076
    00077     PrintContainer(bvsubset1.first(), bvsubset1.end());
    00078     cout << endl;
    00079     PrintContainer(bvsubset2.first(), bvsubset2.end());
    00080
    00081     return 0;
    00082 }
    00083