BitMagic-C++
bvsample01_64.cpp

Example how to use bvector<> in 64-bit mode.

Example how to use bvector<> in 64-bit mode

/*
Copyright(c) 2002-2019 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
For more information please visit: http://bitmagic.io
*/
/** \example bvsample01_64.cpp
Example how to use bvector<> in 64-bit mode
*/
/*! \file bvsample01_64.cpp
\brief Example: how to use 64-bit mode
By default BitMagic uses 32-bit address mode even when if it is
compiled for 64-bit version. This way it supports 2^32-1 address space.
There are two ways to run BitMagic in 64-bit address mode:
1. define BM64ADDR in your project
Or
2. include "bm64.h"
Limitations:
- you CANNOT use 32-bit and 64-bit in the same compilation unit.
- Current implementation internally is 48-bit (which is a lot),
so your range will be [0..2^48-1]
- 32-bit vectors can be serialized and read as 64-bit, but
not vice versa.
*/
#include <iostream>
#include <assert.h>
#include "bm64.h"
#include "bmundef.h" /* clear the pre-proc defines from BM */
using namespace std;
int main(void)
{
try
{
bm::bvector<> bv { 1, 2, 3, bm::id_max-1 }; // Bitvector variable declaration with init list
cout << "BitCount = " << count << endl;
cout << "Max possible ID = " << bm::id_max-1 << endl;
bool range_found = bv.find_range(first, last);
assert(range_found);
(void)range_found; // to silence the warning on unused var
cout << "[" << first << ", " << last << "]" << endl;
bm::bvector<> bv_full;
bv_full.set(); // set the whole vector to 1111111....11111
auto full_count = bv_full.count();
cout << "Full vector bitcount = " << full_count << endl;
bv_full.set(bm::id_max - 1, false);
bv &= bv_full;
for (; en.valid(); ++en)
{
bm::id64_t idx = *en;
cout << idx << ", ";
}
cout << endl;
}
catch(std::exception& ex)
{
std::cerr << ex.what() << std::endl;
return 1;
}
return 0;
}
pre-processor un-defines to avoid global space pollution (internal)
Constant iterator designed to enumerate "ON" bits.
Definition bm.h:603
bool valid() const BMNOEXCEPT
Checks if iterator is still valid.
Definition bm.h:283
Bitvector Bit-vector container with runtime compression of bits.
Definition bm.h:115
size_type count() const BMNOEXCEPT
population count (count of ON bits)
Definition bm.h:2401
bool find_range(size_type &first, size_type &last) const BMNOEXCEPT
Finds dynamic range of bit-vector [first, last].
Definition bm.h:5139
bvector< Alloc > & set(size_type n, bool val=true)
Sets bit n if val is true, clears bit n if val is false.
Definition bm.h:4188
bvector_size_type size_type
Definition bm.h:121
enumerator first() const
Returns enumerator pointing on the first non-zero bit.
Definition bm.h:1871
const unsigned id_max
Definition bmconst.h:109
unsigned long long int id64_t
Definition bmconst.h:35
int main(void)
Definition sample1.cpp:43