~ubuntu-branches/ubuntu/jaunty/bmagic/jaunty

« back to all changes in this revision

Viewing changes to samples/sample1/sample1.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 sample1.cpp
25
 
  Example of how to use bvector template class to set
26
 
  bits and then retrieve indexes of ON bits.
27
 
 
28
 
  For more information please visit:  http://bmagic.sourceforge.net
29
 
 
30
 
  \sa bm::bvector<>::get_next() 
31
 
  \sa bm::bvector<>::get_first() 
32
 
  \sa bm::bvector<>::set()
33
 
  \sa bm::bvector<>::count() 
34
 
  \sa bm::bvector<>::clear()
35
 
  
36
 
 */
37
 
 
38
 
 
39
 
#include <iostream>
40
 
#include "bm.h"
41
 
 
42
 
using namespace std;
43
 
 
44
 
int main(void)
45
 
{
46
 
    bm::bvector<>   bv;    // Bitvector variable declaration.
47
 
 
48
 
    cout << bv.count() << endl;
49
 
 
50
 
    // Set some bits.
51
 
 
52
 
    bv.set(10);
53
 
    bv.set(100);
54
 
    bv.set(1000000);
55
 
 
56
 
    // New bitvector's count.
57
 
 
58
 
    cout << bv.count() << endl;
59
 
 
60
 
 
61
 
    // Print the bitvector.
62
 
 
63
 
    unsigned value = bv.get_first();
64
 
    do
65
 
    {
66
 
        cout << value;
67
 
        value = bv.get_next(value);
68
 
        if (value)
69
 
        {
70
 
            cout << ",";
71
 
        }
72
 
        else
73
 
        {
74
 
            break;
75
 
        }
76
 
    } while(1);
77
 
 
78
 
    cout << endl;
79
 
 
80
 
    bv.clear();   // Clean up.
81
 
 
82
 
    cout << bv.count() << endl;
83
 
 
84
 
    // We also can use operators to set-clear bits;
85
 
 
86
 
    bv[10] = true;
87
 
    bv[100] = true;
88
 
    bv[10000] = true;
89
 
 
90
 
    cout << bv.count() << endl;
91
 
 
92
 
    if (bv[10])
93
 
    {
94
 
        bv[10] = false;
95
 
    }
96
 
 
97
 
    cout << bv.count() << endl;
98
 
 
99
 
    return 0;
100
 
}
101
 
 
 
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 sample1.cpp
 
25
  Example of how to use bvector template class to set
 
26
  bits and then retrieve indexes of ON bits.
 
27
 
 
28
  For more information please visit:  http://bmagic.sourceforge.net
 
29
 
 
30
  \sa bm::bvector<>::get_next() 
 
31
  \sa bm::bvector<>::get_first() 
 
32
  \sa bm::bvector<>::set()
 
33
  \sa bm::bvector<>::count() 
 
34
  \sa bm::bvector<>::clear()
 
35
  
 
36
 */
 
37
 
 
38
 
 
39
#include <iostream>
 
40
#include "bm.h"
 
41
 
 
42
using namespace std;
 
43
 
 
44
int main(void)
 
45
{
 
46
    bm::bvector<>   bv;    // Bitvector variable declaration.
 
47
 
 
48
    cout << bv.count() << endl;
 
49
 
 
50
    // Set some bits.
 
51
 
 
52
    bv.set(10);
 
53
    bv.set(100);
 
54
    bv.set(1000000);
 
55
 
 
56
    // New bitvector's count.
 
57
 
 
58
    cout << bv.count() << endl;
 
59
 
 
60
 
 
61
    // Print the bitvector.
 
62
 
 
63
    unsigned value = bv.get_first();
 
64
    do
 
65
    {
 
66
        cout << value;
 
67
        value = bv.get_next(value);
 
68
        if (value)
 
69
        {
 
70
            cout << ",";
 
71
        }
 
72
        else
 
73
        {
 
74
            break;
 
75
        }
 
76
    } while(1);
 
77
 
 
78
    cout << endl;
 
79
 
 
80
    bv.clear();   // Clean up.
 
81
 
 
82
    cout << bv.count() << endl;
 
83
 
 
84
    // We also can use operators to set-clear bits;
 
85
 
 
86
    bv[10] = true;
 
87
    bv[100] = true;
 
88
    bv[10000] = true;
 
89
 
 
90
    cout << bv.count() << endl;
 
91
 
 
92
    if (bv[10])
 
93
    {
 
94
        bv[10] = false;
 
95
    }
 
96
 
 
97
    cout << bv.count() << endl;
 
98
 
 
99
    return 0;
 
100
}
 
101