Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
testBitArray.C
Go to the documentation of this file.
1
2/* Aleph-w
3
4 / \ | | ___ _ __ | |__ __ __
5 / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6 / ___ \| | __/ |_) | | | |_____\ V V / version 1.9c
7 /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8 |_|
9
10 This file is part of Aleph-w library
11
12 Copyright (c) 2002-2018 Leandro Rabindranath Leon
13
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <https://www.gnu.org/licenses/>.
26*/
27
28# include <fstream>
29# include <iostream>
30# include <bitArray.H>
31
32using namespace std;
33using namespace Aleph;
34
35void print(BitArray & array)
36{
37 cout << "size = " << array.size() << endl;
38
39 for (size_t i = 0; i < array.size(); ++i)
40 cout << array[i] << " ";
41 cout << endl;
42}
43
44int main()
45{
46 BitArray array(40);
47
48 for (int i = 0; i < 20; i++)
49 {
50 array[i] = 0;
51 }
52
53 array[20] = 1;
54 array[27] = 1;
55 array[22] = 1;
56
57 for (int i = 30; i < 40; i++)
58 {
59 array[i] = array[i];
60 }
61
62 print(array);
63
64 cout << endl;
65
66 {
67 ofstream out("test.bits");
68 array.save(out);
69 }
70
71 ifstream in("test.bits");
72 array.load(in);
73
74 print(array);
75}
Space-efficient bit array implementation.
Contiguous array of bits.
Definition bitArray.H:189
void load(std::istream &input)
Loads an array of bits from a file.
Definition bitArray.H:590
constexpr size_t size() const noexcept
Returns the dimension of the bit array.
Definition bitArray.H:334
void save(std::ostream &output) const
Saves the bit sequence in a text file.
Definition bitArray.H:548
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
STL namespace.
void print(BitArray &array)
int main()