~ubuntu-branches/ubuntu/trusty/bmagic/trusty

« back to all changes in this revision

Viewing changes to samples/sample10/sample10.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Roberto C. Sanchez
  • Date: 2010-01-24 14:45:39 UTC
  • mfrom: (4.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100124144539-4ipk5rt64dpp38hl
Tags: 3.6.3-1
* New upstream release
* debian/patches/config.guess.patch: drop obsolete patch
* Add ${misc:Depends} as requested by lintian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)
 
3
 
 
4
Permission is hereby granted, free of charge, to any person 
 
5
obtaining a copy of this software and associated documentation 
 
6
files (the "Software"), to deal in the Software without restriction, 
 
7
including without limitation the rights to use, copy, modify, merge, 
 
8
publish, distribute, sublicense, and/or sell copies of the Software, 
 
9
and to permit persons to whom the Software is furnished to do so, 
 
10
subject to the following conditions:
 
11
 
 
12
The above copyright notice and this permission notice shall be included 
 
13
in all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
 
16
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
 
17
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 
18
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 
19
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
 
20
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
 
21
OTHER DEALINGS IN THE SOFTWARE.
 
22
*/
 
23
 
 
24
/** \example sample10.cpp
 
25
  Example of how to get random subset of a bit-vector
 
26
 
 
27
  For more information please visit:  http://bmagic.sourceforge.net
 
28
 
 
29
  \sa bm::random_subset  
 
30
 */
 
31
 
 
32
 
 
33
#include <iostream>
 
34
#include "bm.h"
 
35
#include "bmrandom.h"
 
36
 
 
37
using namespace std;
 
38
 
 
39
template<class T> void PrintContainer(T first, T last)
 
40
{
 
41
    if (first == last)
 
42
        cout << "<EMPTY SET>";
 
43
    else
 
44
        for(;first != last; ++first)
 
45
            cout << *first << ";";
 
46
    cout << endl;
 
47
}
 
48
 
 
49
 
 
50
int main(void)
 
51
{
 
52
    bm::bvector<>   bv;    
 
53
 
 
54
    // -----------------------------------------------
 
55
    // set some bits
 
56
    //
 
57
    unsigned i;
 
58
    for (i = 0; i < 30000; i+=10)
 
59
    {
 
60
        bv.set(i);
 
61
    }
 
62
 
 
63
    for (i = 300000; i < 400000; i+=100)
 
64
    {
 
65
        bv.set(i);
 
66
    }
 
67
 
 
68
    bm::bvector<>   bvsubset1;
 
69
    bm::bvector<>   bvsubset2;
 
70
 
 
71
    // random sampler instance can be shared between calls
 
72
    //
 
73
    bm::random_subset<bm::bvector<> > rand_sampler;
 
74
    rand_sampler.sample(bvsubset1, bv, 20);
 
75
    rand_sampler.sample(bvsubset2, bv, 20);
 
76
 
 
77
    PrintContainer(bvsubset1.first(), bvsubset1.end());
 
78
    cout << endl;
 
79
    PrintContainer(bvsubset2.first(), bvsubset2.end());
 
80
 
 
81
    return 0;
 
82
}
 
83