#include "stdafx.h"

#include <time.h>

#ifdef _MSC_VER
#pragma hdrstop
#endif

using namespace std;

#include "../../Kernel/kernelincludes.h"
#include "../../Multilevel/Blif.h"
#include "../../Multilevel/Node.h"
#include "../../Multilevel/Signal.h"
#include "../../Multilevel/Network.h"

#define size 500
#define cycles 10000
#define vectors 10000

void Help()
{
}

void SetString( string &s )
{

	unsigned int i, k;

	s.resize(size);
	for ( i = 0; i < size; i++ ) {
		k = rand() % 3;
		switch (k) {
			case 0: s[i] = '0';
				break;
			case 1: s[i] = '1';
				break;
			case 2: s[i] = '-';
				break;
		}
	}
}

void SetBitvector( bitvector &bv )
{
	unsigned int i, k;

	bv.resize(size);
	for ( i = 0; i < size; i++ ) {
		k = rand() % 3;
		switch (k) {
			case 0: 
				bv.setbit(i, ZERO);
				break;
			case 1: 
				bv.setbit(i, ONE);
				break;
			case 2: 
				bv.setbit(i, DC);
				break;
		}
	}
}

int main(int argc, char* argv[])
{
	time_t tim;
	float t1, t2;


	SoPLA *source;
	unsigned int i, j, k;
	string s, s_r;
	bitvector bv1, bv2, bv_r;
	list<Cube>::iterator ti;

    srand((unsigned) time(&tim));
//    srand(3);
/*
//		Test of bitvector
//		=================


	t1 = GetMyCPUTime();
	for ( j = 0; j < cycles; j++ )
		SetString(s);

	t2 = GetMyCPUTime();
	cout << "string: create: " << t2-t1 << endl;

	t1 = GetMyCPUTime();
	for ( j = 0; j < cycles; j++ )
		SetBitvector(bv1);

	t2 = GetMyCPUTime();
	cout << "bitvector: create: " << t2-t1 << endl;

	t1 = GetMyCPUTime();
	k = 0;
	SetString(s);
	SetString(s_r);
	for ( j = 0; j < cycles; j++ ) {
		for ( i = 0; i < size; i++ )
			k += s[i] + s_r[i];
	}
	t2 = GetMyCPUTime();
	cout << "string: add: " << t2-t1 << endl;

	t1 = GetMyCPUTime();
	SetBitvector(bv1);
	SetBitvector(bv2);
	for ( j = 0; j < cycles; j++ ) {
		k = bv1.contains(bv2);
	}
	t2 = GetMyCPUTime();
	cout << "bitvector: contains: " << t2-t1 << endl;
*/

	source = new SoPLA(size, true);
	for ( i = 0; i < vectors; i++ ) {
		SetString(s);
		source->AppendTerm(s);
	}

	t1 = GetMyCPUTime();
	k = 0;
	for ( j = 0; j < cycles; j++ )
		for ( ti = source->getData()->begin(); ti != source->getData()->end(); ++ti )
			if ( ti->contains(source->getData()->front()) ) k++;
	t2 = GetMyCPUTime();
	cout << "bitvector: contains: " << t2-t1 << endl;

	t1 = GetMyCPUTime();
	k = 0;
	for ( j = 0; j < cycles; j++ )
		for ( ti = source->getData()->begin(); ti != source->getData()->end(); ++ti )
			if ( ti->contains(source->getData()->front().getCube()) ) k++;
	t2 = GetMyCPUTime();
	cout << "string: contains: " << t2-t1 << endl;

	t1 = GetMyCPUTime();
	k = 0;
	for ( j = 0; j < cycles; j++ )
		for ( ti = source->getData()->begin(); ti != source->getData()->end(); ++ti )
			if ( ti->And(source->getData()->front()) ) k++;
	t2 = GetMyCPUTime();
	cout << "bitvector: and: " << t2-t1 << endl;

	t1 = GetMyCPUTime();
	k = 0;
	for ( j = 0; j < cycles; j++ )
		for ( ti = source->getData()->begin(); ti != source->getData()->end(); ++ti )
			if ( ti->And(source->getData()->front().getCube()) ) k++;
	t2 = GetMyCPUTime();
	cout << "string: and: " << t2-t1 << endl;


	cout << "ee";



	return 0;
}
