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

« back to all changes in this revision

Viewing changes to samples/sample5/sample5.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Andres Salomon
  • Date: 2008-01-05 23:58:56 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080105235856-2kmxhxkz14qjy9ia
Tags: 3.5.0-1
* New upstream release.
* Add tcpp.dpatch.  This stops tests/stress/t.cpp from including
  ncbi_pch.hpp.  As far as I can tell, NCBI is not used at all, I have
  no idea where that came from..
* Silence some lintian warnings; binary-arch-rules-but-pkg-is-arch-indep
  and ancient-standards-version.

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 sample5.cpp
25
 
 Example demonstrates using enumerators - the fastest way to retrieve 
26
 
 indexes of 1 bits from the bitvector. This approach works faster than
27
 
 get_first/get_next functions.
28
 
 
29
 
  \sa bm::bvector<>::enumerator 
30
 
 
31
 
For more information please visit:  http://bmagic.sourceforge.net
32
 
 
33
 
*/
34
 
 
35
 
#include <iostream>
36
 
#include <algorithm>
37
 
#include "bm.h"
38
 
 
39
 
using namespace std;
40
 
 
41
 
void Print(unsigned n)
42
 
{
43
 
    cout << n << endl;;
44
 
}
45
 
 
46
 
int main(void)
47
 
{
48
 
    bm::bvector<>   bv;    
49
 
 
50
 
    bv[10] = true;
51
 
    bv[100] = true;
52
 
    bv[10000] = true;
53
 
 
54
 
    bm::bvector<>::enumerator en = bv.first();
55
 
    bm::bvector<>::enumerator en_end = bv.end();
56
 
 
57
 
    while (en < en_end)
58
 
    {
59
 
        cout << *en << endl;
60
 
        ++en;  // Fastest way to increment enumerator
61
 
    }
62
 
 
63
 
    en = bv.first();
64
 
 
65
 
    // This is not the fastest way to do the job, because for_each 
66
 
    // often will try to calculate difference between iterators,
67
 
    // which is expensive for enumerators.
68
 
    // But it can be useful for some STL loyal applications. 
69
 
 
70
 
    std::for_each(en, en_end, Print);
71
 
 
72
 
    return 0;
73
 
}
 
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 sample5.cpp
 
25
 Example demonstrates using enumerators - the fastest way to retrieve 
 
26
 indexes of 1 bits from the bitvector. This approach works faster than
 
27
 get_first/get_next functions.
 
28
 
 
29
  \sa bm::bvector<>::enumerator 
 
30
 
 
31
For more information please visit:  http://bmagic.sourceforge.net
 
32
 
 
33
*/
 
34
 
 
35
#include <iostream>
 
36
#include <algorithm>
 
37
#include "bm.h"
 
38
 
 
39
using namespace std;
 
40
 
 
41
void Print(unsigned n)
 
42
{
 
43
    cout << n << endl;;
 
44
}
 
45
 
 
46
int main(void)
 
47
{
 
48
    bm::bvector<>   bv;    
 
49
 
 
50
    bv[10] = true;
 
51
    bv[100] = true;
 
52
    bv[10000] = true;
 
53
 
 
54
    bm::bvector<>::enumerator en = bv.first();
 
55
    bm::bvector<>::enumerator en_end = bv.end();
 
56
 
 
57
    while (en < en_end)
 
58
    {
 
59
        cout << *en << endl;
 
60
        ++en;  // Fastest way to increment enumerator
 
61
    }
 
62
 
 
63
    en = bv.first();
 
64
 
 
65
    // This is not the fastest way to do the job, because for_each 
 
66
    // often will try to calculate difference between iterators,
 
67
    // which is expensive for enumerators.
 
68
    // But it can be useful for some STL loyal applications. 
 
69
 
 
70
    std::for_each(en, en_end, Print);
 
71
 
 
72
    return 0;
 
73
}