Jive reference manual
BitSet.cpp
/************************************************************************
*
* This example demonstrates the use of the class BitSet.
*
************************************************************************/
#include <cstdlib>
#include <jem/base/System.h>
#include <jem/util/BitSet.h>
using namespace jem;
using namespace jem::io;
using namespace jem::util;
//-----------------------------------------------------------------------
// run
//-----------------------------------------------------------------------
int run ()
{
using std::rand;
Writer& out = System::out ();
const int N = 20;
BitSet a;
BitSet b;
BitSet c;
int i, j;
a.reserve ( N );
b.reserve ( N );
for ( i = 0; i < N; i++ )
{
j = (int) (N * (::rand() / (RAND_MAX + 1.0))); a.set(j);
j = (int) (N * (::rand() / (RAND_MAX + 1.0))); b.set(j);
j = (int) (N * (::rand() / (RAND_MAX + 1.0))); c.set(j);
}
print ( out, '\n' );
print ( out, "a : ", a, '\n' );
print ( out, "b : ", b, '\n' );
print ( out, "c : ", c, '\n' );
a.xorWith ( b );
print ( out, "a xor b = d : ", a, '\n' );
a.andWith ( b );
print ( out, "d and b = e : ", a, '\n' );
a.orWith ( b );
print ( out, "e or b = f : ", a, '\n' );
a.clear ( c );
print ( out, "a.clear(c) : ", a, "\n\n" );
return 0;
}
//-----------------------------------------------------------------------
// main
//-----------------------------------------------------------------------
int main ()
{
return System::exec ( & run );
}