#include <assert.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <utility>
#include "bm.h"
#include "bmsparsevec.h"
#include "bmsparsevec_algo.h"
#include "bmundef.h"
using namespace std;
typedef bm::sparse_vector<unsigned, bm::bvector<> > svector_u32;
int main(void)
{
try
{
svector_u32::size_type pos;
cout << "sparse vectors without NULL:" << endl;
{
svector_u32 sv1, sv2;
sv1.push_back(1);
sv1.push_back(2);
sv1.push_back(2);
sv1.push_back(3);
sv2 = sv1;
bool found = bm::sparse_vector_find_first_mismatch(sv1, sv2, pos);
if (found)
std::cout << "Mismatch found." << endl; else
std::cout << "Mismatch not found" << endl;
sv2[2] = 0;
found = bm::sparse_vector_find_first_mismatch(sv1, sv2, pos);
if (found)
{
std::cout << "Mismatch found at: " << pos << endl; }
}
cout << endl << "sparse vectors with NULL:" << endl;
{
svector_u32 sv1(bm::use_null);
svector_u32 sv2(bm::use_null);
sv1[1] = 1;
sv1[2] = 2;
sv1.set_null(3); sv1[4] = 0;
sv2 = sv1;
bool found = bm::sparse_vector_find_first_mismatch(sv1, sv2, pos);
if (found)
std::cout << "Mismatch found." << endl; else
std::cout << "Mismatch not found" << endl;
sv2[4] = 10;
found = bm::sparse_vector_find_first_mismatch(sv1, sv2, pos);
if (found)
{
std::cout << "Mismatch found at: " << pos << endl; }
sv2[3] = 0;
found = bm::sparse_vector_find_first_mismatch(sv1, sv2, pos);
if (found)
{
std::cout << "Mismatch found at: " << pos << endl; }
}
}
catch(std::exception& ex)
{
std::cerr << ex.what() << std::endl;
return 1;
}
return 0;
}