~ubuntu-branches/ubuntu/intrepid/bmagic/intrepid

« back to all changes in this revision

Viewing changes to samples/sample2/sample2.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 sample2.cpp
25
 
  Example demonstrates using set operations AND, OR, XOR, etc.
26
 
  For more information please visit:  http://bmagic.sourceforge.net
27
 
 
28
 
*/
29
 
 
30
 
 
31
 
#include <iostream>
32
 
#include "bm.h"
33
 
 
34
 
using namespace std;
35
 
 
36
 
void print_bvector(const bm::bvector<>& bv)
37
 
{
38
 
    unsigned value = bv.get_first();
39
 
    do
40
 
    {
41
 
        cout << value;
42
 
        value = bv.get_next(value);
43
 
        if (value)
44
 
        {
45
 
            cout << ",";
46
 
        }
47
 
        else
48
 
        {
49
 
            break;
50
 
        }
51
 
    } while(1);
52
 
    cout << endl;
53
 
}
54
 
 
55
 
int main(void)
56
 
{
57
 
    bm::bvector<>   bv1;    
58
 
    bm::bvector<>   bv2;
59
 
    bm::bvector<>   bv3;
60
 
 
61
 
    bv1.set(10);
62
 
    bv1.set(100);
63
 
    bv1.set(1000000);
64
 
 
65
 
 
66
 
    bv2.set(10);
67
 
    bv2.set(100);
68
 
 
69
 
    // Logical AND operation on bv2 (bv1 is the argument)
70
 
    // bv2 = bv2 AND bv1
71
 
 
72
 
    bv3 = bv1 & bv2;
73
 
    print_bvector(bv3);
74
 
 
75
 
    bv2 &= bv1;  // You also can use: bv2.bit_and(bv1);
76
 
    print_bvector(bv2);
77
 
    
78
 
    // bv2 = bv2 OR bv1
79
 
 
80
 
    bv3 = bv1 | bv2;
81
 
    print_bvector(bv3);
82
 
 
83
 
    bv2 |= bv1;  //  You can also use: bv2.bit_or(bv1);
84
 
    print_bvector(bv2);
85
 
 
86
 
    
87
 
    bv1.set(1000000, false);
88
 
    
89
 
    // bv2 = bv2 SUB bv1
90
 
 
91
 
    bv3 = bv2 - bv1;
92
 
    print_bvector(bv3);
93
 
 
94
 
    bv2 -= bv1;   // You can also use: bv2.bit_sub(bv1);
95
 
    print_bvector(bv2);
96
 
 
97
 
    // bv2 XOR bv1
98
 
 
99
 
    bv3 = bv2 ^ bv1;
100
 
    print_bvector(bv3);
101
 
 
102
 
    bv2 ^= bv1;  // You can also use: bv2.bit_xor(bv1);
103
 
    print_bvector(bv2);
104
 
 
105
 
    // For lexicographical comparison there is set of overloaded
106
 
    // operators and function compare.
107
 
 
108
 
    if (bv2 == bv3)
109
 
    {
110
 
        cerr << "Equivalent. Comparison result = " 
111
 
             << bv2.compare(bv3) << endl;
112
 
    }
113
 
    else
114
 
    {
115
 
        cout << "Error." << endl;
116
 
        return 1;
117
 
    }
118
 
 
119
 
 
120
 
    return 0;
121
 
}
 
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 sample2.cpp
 
25
  Example demonstrates using set operations AND, OR, XOR, etc.
 
26
  For more information please visit:  http://bmagic.sourceforge.net
 
27
 
 
28
*/
 
29
 
 
30
 
 
31
#include <iostream>
 
32
#include "bm.h"
 
33
 
 
34
using namespace std;
 
35
 
 
36
void print_bvector(const bm::bvector<>& bv)
 
37
{
 
38
    unsigned value = bv.get_first();
 
39
    do
 
40
    {
 
41
        cout << value;
 
42
        value = bv.get_next(value);
 
43
        if (value)
 
44
        {
 
45
            cout << ",";
 
46
        }
 
47
        else
 
48
        {
 
49
            break;
 
50
        }
 
51
    } while(1);
 
52
    cout << endl;
 
53
}
 
54
 
 
55
int main(void)
 
56
{
 
57
    bm::bvector<>   bv1;    
 
58
    bm::bvector<>   bv2;
 
59
    bm::bvector<>   bv3;
 
60
 
 
61
    bv1.set(10);
 
62
    bv1.set(100);
 
63
    bv1.set(1000000);
 
64
 
 
65
 
 
66
    bv2.set(10);
 
67
    bv2.set(100);
 
68
 
 
69
    // Logical AND operation on bv2 (bv1 is the argument)
 
70
    // bv2 = bv2 AND bv1
 
71
 
 
72
    bv3 = bv1 & bv2;
 
73
    print_bvector(bv3);
 
74
 
 
75
    bv2 &= bv1;  // You also can use: bv2.bit_and(bv1);
 
76
    print_bvector(bv2);
 
77
    
 
78
    // bv2 = bv2 OR bv1
 
79
 
 
80
    bv3 = bv1 | bv2;
 
81
    print_bvector(bv3);
 
82
 
 
83
    bv2 |= bv1;  //  You can also use: bv2.bit_or(bv1);
 
84
    print_bvector(bv2);
 
85
 
 
86
    
 
87
    bv1.set(1000000, false);
 
88
    
 
89
    // bv2 = bv2 SUB bv1
 
90
 
 
91
    bv3 = bv2 - bv1;
 
92
    print_bvector(bv3);
 
93
 
 
94
    bv2 -= bv1;   // You can also use: bv2.bit_sub(bv1);
 
95
    print_bvector(bv2);
 
96
 
 
97
    // bv2 XOR bv1
 
98
 
 
99
    bv3 = bv2 ^ bv1;
 
100
    print_bvector(bv3);
 
101
 
 
102
    bv2 ^= bv1;  // You can also use: bv2.bit_xor(bv1);
 
103
    print_bvector(bv2);
 
104
 
 
105
    // For lexicographical comparison there is set of overloaded
 
106
    // operators and function compare.
 
107
 
 
108
    if (bv2 == bv3)
 
109
    {
 
110
        cerr << "Equivalent. Comparison result = " 
 
111
             << bv2.compare(bv3) << endl;
 
112
    }
 
113
    else
 
114
    {
 
115
        cout << "Error." << endl;
 
116
        return 1;
 
117
    }
 
118
 
 
119
 
 
120
    return 0;
 
121
}