#include <iostream>
#include <vector>
#include <cassert>
#include "bm.h"
#include "bm3vl.h"
#include "bmundef.h"
using namespace std;
static
void PrintKleeneVector(const bm::bvector<>& bv_v, const bm::bvector<>& bv_null)
{
bm::bvector<>::enumerator en_n = bv_null.first();
auto prev = *en_n;
if (prev > 0)
prev = 0;
for ( ;en_n.valid(); ++en_n)
{
auto curr = *en_n;
for (auto i = prev; i < curr; ++i)
cout << i << ": NULL" << endl;
bool v = bv_v.test(curr);
cout << curr << ": " << (v ? "true" : "false") << endl;
prev = curr + 1;
}
cout << endl;
}
static
void Set3VL_ValueDemo()
{
bm::bvector<> bv_v; bm::bvector<> bv_null;
int v = 0; for (unsigned i = 0; i < 10; ++i)
{
bm::set_value_kleene(bv_v, bv_null, i, v);
auto v1 = bm::get_value_kleene(bv_v, bv_null, i);
assert(v == v1); (void) v1;
v += 1;
if (v > 1)
v = -1;
}
BM_DECLARE_TEMP_BLOCK(tb)
bv_v.optimize(tb);
bv_null.optimize(tb);
PrintKleeneVector(bv_v, bv_null);
}
static
void Set3VL_ValueDemo2()
{
bm::bvector<> bv_v; bm::bvector<> bv_null;
{
bm::bvector<>::bulk_insert_iterator iit_v = bv_v.inserter();
bm::bvector<>::bulk_insert_iterator iit_n = bv_null.inserter();
for (unsigned i = 0; i < 13; i+=3)
{
if (i & 1) {
iit_v = i;
}
iit_n = i;
}
iit_v.flush();
iit_n.flush();
}
bm::init_kleene(bv_v, bv_null);
BM_DECLARE_TEMP_BLOCK(tb)
bv_v.optimize(tb);
bv_null.optimize(tb);
PrintKleeneVector(bv_v, bv_null);
}
static
void GenerateDemoVector(bm::bvector<>& bv_v, bm::bvector<>& bv_null)
{
int v = 0; for (unsigned i = 0; i < 10; ++i)
{
bm::set_value_kleene(bv_v, bv_null, i, v);
v += 1;
if (v > 1)
v = -1;
} BM_DECLARE_TEMP_BLOCK(tb)
bv_v.optimize(tb);
bv_null.optimize(tb);
}
static
void Set3VL_InvertDemo()
{
bm::bvector<> bv_v; bm::bvector<> bv_null;
GenerateDemoVector(bv_v, bv_null);
cout << "Input vector:" << endl;
PrintKleeneVector(bv_v, bv_null);
bm::invert_kleene(bv_v, bv_null);
cout << "Inverted vector:" << endl;
PrintKleeneVector(bv_v, bv_null);
}
static
void Set3VL_AndDemo()
{
bm::bvector<> bv_v1; bm::bvector<> bv_null1;
GenerateDemoVector(bv_v1, bv_null1);
bm::bvector<> bv_v2; bm::bvector<> bv_null2;
bm::set_value_kleene(bv_v2, bv_null2, 0, 0); bm::set_value_kleene(bv_v2, bv_null2, 1, 1); bm::set_value_kleene(bv_v2, bv_null2, 2, -1);
bm::bvector<> bv_v_t, bv_null_t;
bm::and_kleene(bv_v_t, bv_null_t, bv_v2, bv_null2, bv_v1, bv_null1);
bm::and_kleene(bv_v2, bv_null2, bv_v1, bv_null1);
bool b = bv_v_t.equal(bv_v2);
assert(b);
b = bv_null_t.equal(bv_null2);
assert(b);
cout << "AND vector:" << endl;
PrintKleeneVector(bv_v2, bv_null2);
}
static
void Set3VL_ORDemo()
{
bm::bvector<> bv_v1; bm::bvector<> bv_null1;
GenerateDemoVector(bv_v1, bv_null1);
bm::bvector<> bv_v2; bm::bvector<> bv_null2;
bm::set_value_kleene(bv_v2, bv_null2, 0, 1); bm::set_value_kleene(bv_v2, bv_null2, 1, 0); bm::set_value_kleene(bv_v2, bv_null2, 2, -1);
bm::bvector<> bv_v_t, bv_null_t;
bm::or_kleene(bv_v_t, bv_null_t, bv_v2, bv_null2, bv_v1, bv_null1);
bm::or_kleene(bv_v2, bv_null2, bv_v1, bv_null1);
bool b = bv_v_t.equal(bv_v2);
assert(b);
b = bv_null_t.equal(bv_null2);
assert(b);
cout << "OR vector:" << endl;
PrintKleeneVector(bv_v2, bv_null2);
}
int main(void)
{
try
{
cout << endl << "3VL Set values:" << endl << endl;
Set3VL_ValueDemo();
Set3VL_ValueDemo2();
cout << endl << "3VL Invert vector:" << endl << endl;
Set3VL_InvertDemo();
cout << endl << "3VL AND:" << endl << endl;
Set3VL_AndDemo();
cout << endl << "3VL OR:" << endl << endl;
Set3VL_ORDemo();
}
catch(std::exception& ex)
{
std::cerr << ex.what() << std::endl;
}
return 0;
}