示例#1
1
文件: gsbittab.c 项目: 99years/plan9
/*
 * byte_bit_run_length_N[B], for 0 <= N <= 7, gives the length of the
 * run of 1-bits starting at bit N in a byte with value B,
 * numbering the bits in the byte as 01234567.  If the run includes
 * the low-order bit (i.e., might be continued into a following byte),
 * the run length is increased by 8.
 */

#define t8(n) n,n,n,n,n+1,n+1,n+2,n+11
#define r8(n) n,n,n,n,n,n,n,n
#define r16(n) r8(n),r8(n)
#define r32(n) r16(n),r16(n)
#define r64(n) r32(n),r32(n)
#define r128(n) r64(n),r64(n)
const byte byte_bit_run_length_0[256] = {
    r128(0), r64(1), r32(2), r16(3), r8(4), t8(5)
};
const byte byte_bit_run_length_1[256] = {
    r64(0), r32(1), r16(2), r8(3), t8(4),
    r64(0), r32(1), r16(2), r8(3), t8(4)
};
const byte byte_bit_run_length_2[256] = {
    r32(0), r16(1), r8(2), t8(3),
    r32(0), r16(1), r8(2), t8(3),
    r32(0), r16(1), r8(2), t8(3),
    r32(0), r16(1), r8(2), t8(3)
};
const byte byte_bit_run_length_3[256] = {
    r16(0), r8(1), t8(2), r16(0), r8(1), t8(2),
    r16(0), r8(1), t8(2), r16(0), r8(1), t8(2),
    r16(0), r8(1), t8(2), r16(0), r8(1), t8(2),
示例#2
0
void tst_QSizeF::scale() {
    QSizeF t1(10.4, 12.8);
    t1.scale(60.6, 60.6, Qt::IgnoreAspectRatio);
    QCOMPARE(t1, QSizeF(60.6, 60.6));

    QSizeF t2(10.4, 12.8);
    t2.scale(43.52, 43.52, Qt::KeepAspectRatio);
    QCOMPARE(t2, QSizeF(35.36, 43.52));

    QSizeF t3(9.6, 12.48);
    t3.scale(31.68, 31.68, Qt::KeepAspectRatioByExpanding);
    QCOMPARE(t3, QSizeF(31.68, 41.184));

    QSizeF t4(12.8, 10.4);
    t4.scale(43.52, 43.52, Qt::KeepAspectRatio);
    QCOMPARE(t4, QSizeF(43.52, 35.36));

    QSizeF t5(12.48, 9.6);
    t5.scale(31.68, 31.68, Qt::KeepAspectRatioByExpanding);
    QCOMPARE(t5, QSizeF(41.184, 31.68));

    QSizeF t6(0.0, 0.0);
    t6.scale(200, 240, Qt::IgnoreAspectRatio);
    QCOMPARE(t6, QSizeF(200, 240));

    QSizeF t7(0.0, 0.0);
    t7.scale(200, 240, Qt::KeepAspectRatio);
    QCOMPARE(t7, QSizeF(200, 240));

    QSizeF t8(0.0, 0.0);
    t8.scale(200, 240, Qt::KeepAspectRatioByExpanding);
    QCOMPARE(t8, QSizeF(200, 240));
}
示例#3
0
文件: struct.c 项目: 4ker/8cc
void testmain() {
    print("struct");
    t1();
    t2();
    t3();
    t4();
    t5();
    t6();
    t7();
    t8();
    t9();
    t10();
    t11();
    t12();
    t13();
    t14();
    unnamed();
    assign();
    arrow();
    incomplete();
    bitfield_basic();
    bitfield_mix();
    bitfield_union();
    bitfield_unnamed();
    bitfield_initializer();
    test_offsetof();
    flexible_member();
    empty_struct();
}
示例#4
0
int main() {
    TreeNode root1(1);
    TreeNode root2(1);
	TreeNode t2(2);
	TreeNode t3(3);
	TreeNode t4(4);
	TreeNode t5(5);
	TreeNode t6(6);
	TreeNode t7(7);
	TreeNode t8(8);
	TreeNode t9(9);
	
	root1.left = &t2;
	root1.right = &t3;
	root2.left = &t2;
	root2.right = &t3;
	t2.left = &t4;
	t2.right = &t5;
	t3.right = &t6;
	t4.left = &t7;
	t4.right = &t8;
	t8.left = &t9;
	
	Solution s;
	std::cout << s.isSameTree(&root1, &root2) << std::endl;
    
	return 0;
}
示例#5
0
int main(void)
{
	vector<int> ret;

	TreeNode root(1);
	TreeNode t2(2);
	TreeNode t3(3);
	TreeNode t4(4);
	TreeNode t5(5);
	TreeNode t6(6);
	TreeNode t7(7);
	TreeNode t8(8);
	TreeNode t9(9);
	TreeNode t10(10);

	root.left = &t2;
	root.right = &t3;
	t2.left = &t4;
	t3.left = &t5;
	t3.right = &t6;
	t5.left = &t7;
	t6.left = &t8;
	t6.right = &t9;
	t8.left = &t10;

	Solution s;
	ret = s.preorderTraversal(&root);
	for(auto it = ret.begin(); it != ret.end(); ++it)
	{
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
示例#6
0
void RatioPrint2(const char* aTitle, const SRatio& aR1, const SRatio& aR2)
	{
	TPtrC8 t8((const TUint8*)aTitle);
	TBuf<256> t16;
	t16.Copy(t8);
	test.Printf(_L("%S: %08x %04x   %08x %04x\n"), &t16, aR1.iM, TUint16(aR1.iX), aR2.iM, TUint16(aR2.iX));
	}
示例#7
0
void
test_types()
{
  std::cout << "--- types ---\n";
  Void_type t1;
  std::cout << t1 << '\n'; // void

  Boolean_type t2;
  std::cout << t2 << '\n'; // bool

  Integer_type t3;
  std::cout << t3 << '\n'; // int

  Float_type t4;
  std::cout << t4 << '\n'; // double

  Function_type t5({&t2, &t3}, t2);
  std::cout << t5 << '\n'; // (bool, int32) -> bool

  Pointer_type t6(t2);
  std::cout << t6 << '\n'; // bool*;

  Reference_type t7(t5);
  std::cout << t7 << '\n'; // ((bool, int32) -> bool)&;

  Function_type t8({}, t1);
  std::cout << t8 << '\n'; // () -> void

  Sequence_type t9(*new Pointer_type(t8));
  std::cout << t9 << '\n'; // (() -> void)*[]
}
示例#8
0
void rgb( uint8_t h, uint8_t s, uint8_t v,
		uint8_t *r, uint8_t *g, uint8_t *b )
{
	uint8_t f, hi;

	hi = hi8( h );
	f = f8( h );

	switch ( hi ) {
	case 0:
		*r = v;
		*g = t8( v, s, f );
		*b = p8( v, s );
		break;
	case 1:
		*r = q8( v, s, f );
		*g = v;
		*b = p8( v, s );
		break;
	case 2:
		*r = p8( v, s );
		*g = v;
		*b = t8( v, s, f );
		break;
	case 3:
		*r = p8( v, s );
		*g = q8( v, s, f );
		*b = v;
		break;
	case 4:
		*r = t8( v, s, f );
		*g = p8( v, s );
		*b = v;
		break;
	case 5:
		*r = v;
		*g = p8( v, s );
		*b = q8( v, s, f );
		break;
	default:
		/*	not reached	*/
		break;
	}
}
示例#9
0
void tst_QSize::scale()
{
    QSize t1( 10, 12 );
    t1.scale( 60, 60, Qt::IgnoreAspectRatio );
    QCOMPARE( t1, QSize(60, 60) );

    QSize t2( 10, 12 );
    t2.scale( 60, 60, Qt::KeepAspectRatio );
    QCOMPARE( t2, QSize(50, 60) );

    QSize t3( 10, 12 );
    t3.scale( 60, 60, Qt::KeepAspectRatioByExpanding );
    QCOMPARE( t3, QSize(60, 72) );

    QSize t4( 12, 10 );
    t4.scale( 60, 60, Qt::KeepAspectRatio );
    QCOMPARE( t4, QSize(60, 50) );

    QSize t5( 12, 10 );
    t5.scale( 60, 60, Qt::KeepAspectRatioByExpanding );
    QCOMPARE( t5, QSize(72, 60) );

    // test potential int overflow
    QSize t6(88473, 88473);
    t6.scale(141817, 141817, Qt::KeepAspectRatio);
    QCOMPARE(t6, QSize(141817, 141817));

    QSize t7(800, 600);
    t7.scale(400, INT_MAX, Qt::KeepAspectRatio);
    QCOMPARE(t7, QSize(400, 300));

    QSize t8(800, 600);
    t8.scale(INT_MAX, 150, Qt::KeepAspectRatio);
    QCOMPARE(t8, QSize(200, 150));

    QSize t9(600, 800);
    t9.scale(300, INT_MAX, Qt::KeepAspectRatio);
    QCOMPARE(t9, QSize(300, 400));

    QSize t10(600, 800);
    t10.scale(INT_MAX, 200, Qt::KeepAspectRatio);
    QCOMPARE(t10, QSize(150, 200));

    QSize t11(0, 0);
    t11.scale(240, 200, Qt::IgnoreAspectRatio);
    QCOMPARE(t11, QSize(240, 200));

    QSize t12(0, 0);
    t12.scale(240, 200, Qt::KeepAspectRatio);
    QCOMPARE(t12, QSize(240, 200));

    QSize t13(0, 0);
    t13.scale(240, 200, Qt::KeepAspectRatioByExpanding);
    QCOMPARE(t13, QSize(240, 200));
}
示例#10
0
int main(int argc, char *argv[])
{
   int i, t, c, pi;

   char test[64];

   if (argc > 1)
   {
      t = 0;

      for (i=0; i<strlen(argv[1]); i++)
      {
         c = tolower(argv[1][i]);

         if (!strchr(test, c))
         {
            test[t++] = c;
            test[t] = 0;
         }
      }
   }
   else strcat(test, "0123456789");

   pi = pigpio_start(0, 0);

   if (pi < 0)
   {
      fprintf(stderr, "pigpio initialisation failed (%d).\n", pi);
      return 1;
   }

   printf("Connected to pigpio daemon (%d).\n", pi);

   if (strchr(test, '0')) t0(pi);
   if (strchr(test, '1')) t1(pi);
   if (strchr(test, '2')) t2(pi);
   if (strchr(test, '3')) t3(pi);
   if (strchr(test, '4')) t4(pi);
   if (strchr(test, '5')) t5(pi);
   if (strchr(test, '6')) t6(pi);
   if (strchr(test, '7')) t7(pi);
   if (strchr(test, '8')) t8(pi);
   if (strchr(test, '9')) t9(pi);
   if (strchr(test, 'a')) ta(pi);
   if (strchr(test, 'b')) tb(pi);
   if (strchr(test, 'c')) tc(pi);

   pigpio_stop(pi);

   return 0;
}
示例#11
0
void rgb( uint8_t h, uint8_t s, uint8_t v,
		uint8_t *r, uint8_t *g, uint8_t *b )
{
	uint8_t f, hi;
    int16_t p, q, t;

	hi = hi8( h );
    f = f8( h );
    p = p8( v, s );
    q = q8( v, s, f );
    t = t8( v, s, f );

	switch ( hi ) {
	case 0:
		*r = v;
        *g = t;
        *b = p;
        break;
	case 1:
        *r = q;
		*g = v;
        *b = p;
		break;
	case 2:
        *r = p;
		*g = v;
        *b = t;
		break;
	case 3:
        *r = p;
        *g = q;
		*b = v;
		break;
	case 4:
        *r = t;
        *g = p;
		*b = v;
		break;
	case 5:
		*r = v;
        *g = p;
        *b = q;
		break;
	default:
		exit( EXIT_FAILURE );
		break;
	}
}
示例#12
0
void TestTuple8()
{
	test_db_config::DbConfig config;
	bool bRet = config.Init();
	assert( bRet == true );
	occiwrapper::ConnectionInfo info( config.GetStrIp(), 1521, config.GetUserName(), config.GetPassword(), config.GetSid() );
	occiwrapper::SessionFactory sf;
	occiwrapper::Session s = sf.Create( info );
	string strErrMsg;

	struct tm objTm;
	objTm.tm_year = 2014 - 1900;
	objTm.tm_mon = 11;
	objTm.tm_mday = 30;
	objTm.tm_hour = 10;
	objTm.tm_min = 43;
	objTm.tm_sec = 0;

	s << strCreateTable, now, bRet, strErrMsg;
	s << "truncate table tbl_test_tuple_elements", now, bRet, strErrMsg;
	assert( bRet );

	// test 6 elements
	tuple< int, float, string, struct tm, struct tm, double, double, string > t8( 1, 1.1, "str1", objTm, objTm, 1.2, 2.5, "str8" );
	s << "insert into tbl_test_tuple_elements( t1, t2, t3, t4, t5, t6, t7, t8 ) values ( :1, :2, :3, :4, :5, :6, :7, :8 )", use( t8 ), now, bRet, strErrMsg;
	assert( bRet );

	tuple< int, float, string, struct tm, struct tm, double, double, string > t8Out;
	s << "select t1, t2, t3, t4, t5, t6, t7, t8 from tbl_test_tuple_elements", into( t8Out ), now, bRet, strErrMsg;
	assert( bRet );
	assert( get< 0 >( t8Out ) == 1 );
	assert( get< 1 >( t8Out ) == ( float )1.1 );
	assert( get< 2 >( t8Out ) == "str1" );
	assert( get< 3 >( t8Out ).tm_mon == 11 );
	assert( get< 4 >( t8Out ).tm_min == 43 );
	//assert( get< 3 >( t8Out ) == get< 4 >( t8Out ) );
	assert( get< 5 >( t8Out ) == 1.2 );
	assert( get< 6 >( t8Out ) == 2.5 );
	assert( get< 7 >( t8Out ) == "str8" );

	s << "drop table tbl_test_tuple_elements", now, bRet, strErrMsg;
	assert( bRet );
}
示例#13
0
文件: function.c 项目: davecheney/8cc
void testmain(void) {
    print("function");

    expect(77, t1());
    t2(79);
    t3(1, 2, 3, 4, 5, 6);
    t4();
    t5();
    expect(3, t6());
    expect(12, t7(3, 4));
    t8(23);
    t9();
    expect(7, t10(3, 4.0));
    func_ptr_call();
    func_name();
    empty();
    empty2();
    test_bool();
    test_struct();
}
示例#14
0
int main(){
	t1();
	t2();
	t3();
	t4();
	t5();
	t6();
	t7();
	t8();
	t9();
	t10();
	t11();
	t12();
	t13();
	t14();
	t15();
	t16();
	t17();
	return 0;
}
示例#15
0
int main(void){

	printf("Running unit tests...\n");
	initArrays();
	t1();
	t2();
	t3();
	t4();
	t5();
	t6();
	t7();
	t8();
	t9();
	t10();
	t11();
	t12();
	t13();
	t14();

	return 1;
}
示例#16
0
int main(){
    TreeNode t0(15);
    TreeNode t1(10);
    TreeNode t2(20);
    TreeNode t3(8);
    TreeNode t4(12);
    TreeNode t5(16);
    TreeNode t6(25);
    TreeNode t7(13);
    TreeNode t8(17);
    t0.left = &t1;
    t0.right = &t2;
    t1.left = &t3;
    t1.right = &t4;
    t2.left = &t5;
    t2.right = &t6;
    t4.right = &t7;
    t5.right = &t8;
    cout<<lca(&t0,&t3,&t7)->val<<endl;
    return 0;
}
int main() {
	TreeNode t1(1), t2(2), t3(3), t4(4), t5(5), t6(6), t7(7), t8(8), t9(9);
	t4.left = &t2;
	t4.right = &t5;

	t2.left = &t1;
	t2.right = &t3;

	t5.right = &t9;

	t9.left = &t7;
	t7.left = &t6;
	t7.right = &t8;
	
	Solution s;
	bool ret = s.isBalanced(&t4);
	
	printf("Return value is %s\n", ret ? "true":"false");

	return 0;
}
示例#18
0
文件: time.cpp 项目: jrwilson/ioa
static const char*
ctor ()
{
  std::cout << __func__ << std::endl;

  ioa::time t1 (1, 500000);
  mu_assert (t1.sec () == 1);
  mu_assert (t1.usec () == 500000);

  ioa::time t2 (-1, 500000);
  mu_assert (t2.sec () == 0);
  mu_assert (t2.usec () == -500000);

  ioa::time t3 (1, -500000);
  mu_assert (t3.sec () == 0);
  mu_assert (t3.usec () == 500000);

  ioa::time t4 (-1, -500000);
  mu_assert (t4.sec () == -1);
  mu_assert (t4.usec () == -500000);

  ioa::time t5 (1, 5000000);
  mu_assert (t5.sec () == 6);
  mu_assert (t5.usec () == 0);

  ioa::time t6 (-1, 5000000);
  mu_assert (t6.sec () == 4);
  mu_assert (t6.usec () == 0);

  ioa::time t7 (1, -5000000);
  mu_assert (t7.sec () == -4);
  mu_assert (t7.usec () == 0);

  ioa::time t8 (-1, -5000000);
  mu_assert (t8.sec () == -6);
  mu_assert (t8.usec () == 0);

  return 0;
}
示例#19
0
文件: function.c 项目: 4ker/8cc
void testmain() {
    print("function");

    expect(77, t1());
    t2(79);
    t3(1, 2, 3, 4, 5, 6);
    t4();
    t5();
    expect(3, t6());
    expect(12, t7(3, 4));
    expect(77, (1 ? t1 : t6)());
    expect(3, (0 ? t1 : t6)());
    t8(23);
    t9();
    expect(7, t10(3, 4.0));
    func_ptr_call();
    func_name();
    local_static();
    empty();
    empty2();
    test_bool();
    test_struct();
    test_funcdesg();
}
示例#20
0
文件: CTitanic.cpp 项目: rroc/rtdof
//Define vertices and triangles
void CTitanic::init(float aScale)
	{
	this->clearMesh();

	TVector3 v0(-4,2,2);
	this->iVertices.push_back(v0*aScale);

	TVector3 v1(-3,1,0);
	this->iVertices.push_back(v1*aScale);

	TVector3 v2(-3,-1,0);
	this->iVertices.push_back(v2*aScale);

	TVector3 v3(-4,-2,2);
	this->iVertices.push_back(v3*aScale);

	TVector3 v4(3,2,2);
	this->iVertices.push_back(v4*aScale);

	TVector3 v5(3,1,0);
	this->iVertices.push_back(v5*aScale);

	TVector3 v6(3,-1,0);
	this->iVertices.push_back(v6*aScale);

	TVector3 v7(3,-2,2);
	this->iVertices.push_back(v7*aScale);

	TVector3 v8(5,0,2);
	this->iVertices.push_back(v8*aScale);

/*
	TTriangle t0(0,2,1);
	this->iTriangles.push_back(t0);


	TTriangle t1(0,3,2);
	this->iTriangles.push_back(t1);


	TTriangle t2(0,1,4);
	this->iTriangles.push_back(t2);


	TTriangle t3(1,5,4);
	this->iTriangles.push_back(t3);


	TTriangle t4(1,6,5);
	this->iTriangles.push_back(t4);


	TTriangle t5(1,2,6);
	this->iTriangles.push_back(t5);


	TTriangle t6(2,3,6);
	this->iTriangles.push_back(t6);


	TTriangle t7(3,7,6);
	this->iTriangles.push_back(t7);


	TTriangle t8(4,5,8);
	this->iTriangles.push_back(t8);


	TTriangle t9(5,6,8);
	this->iTriangles.push_back(t9);


	TTriangle t10(6,7,8);
	this->iTriangles.push_back(t10);


	TTriangle t11(0,4,3);
	this->iTriangles.push_back(t11);


	TTriangle t12(3,4,7);
	this->iTriangles.push_back(t12);


	TTriangle t13(4,8,7);
	this->iTriangles.push_back(t13);

*/

	TTriangle t0(0,1,2);
	this->iTriangles.push_back(t0);

	TTriangle t1(0,2,3);
	this->iTriangles.push_back(t1);

	TTriangle t2(0,4,1);
	this->iTriangles.push_back(t2);

	TTriangle t3(1,4,5);
	this->iTriangles.push_back(t3);

	TTriangle t4(1,5,6);
	this->iTriangles.push_back(t4);

	TTriangle t5(1,6,2);
	this->iTriangles.push_back(t5);

	TTriangle t6(2,6,3);
	this->iTriangles.push_back(t6);

	TTriangle t7(3,6,7);
	this->iTriangles.push_back(t7);

	TTriangle t8(4,8,5);
	this->iTriangles.push_back(t8);

	TTriangle t9(5,8,6);
	this->iTriangles.push_back(t9);

	TTriangle t10(6,8,7);
	this->iTriangles.push_back(t10);

	TTriangle t11(0,3,4);
	this->iTriangles.push_back(t11);

	TTriangle t12(3,7,4);
	this->iTriangles.push_back(t12);

	TTriangle t13(4,7,8);
	this->iTriangles.push_back(t13);
	}
示例#21
0
int main() {

	/** Setup test environ */

	setupTestTree();
	
	std::vector<int16_t> v201501, v201502, v201503;
	/** (1420070400) NO_DATA (1420074000) 75 (1420077600) NO_DATA (1422748800) */
	for (int i = 0; i < 267840; ++i) {
		if (i < 360 || i > 720) v201501.push_back(-32768);
		else v201501.push_back(75);
	}
	for (int i = 0; i < 241920; ++i) {
		if (i > 720 && i < 1080) v201502.push_back(-32768);
		else v201502.push_back(85);

	}
	for (int i = 0; i < 267840; ++i) {
		if (i < 360) v201503.push_back(-32768);
		else v201503.push_back(95);
		//v201503.push_back(-32768);
	}

	createSzCacheFile("TestA/TestB/TestC/201501.szc", v201501);
	createSzCacheFile("TestA/TestB/TestC/201502.szc", v201502);
	createSzCacheFile("TestA/TestB/TestC/201503.szc", v201503);

	/** Test */

	SzCache szc("./",2);

	/** availableRange() */
	SzCache::SzRange szr = szc.availableRange();
	std::cout << "SzCache::availableRange(): (" << szr.first << "," << szr.second << ")\n";
	std::cout << "= ( " << time2str(szr.first) << " , " << time2str(szr.second) << " )\n";
	std::cout << "\n";

	SzCache::SzTime t1(1420070400 );
	SzCache::SzTime t2(1420070400 + 3600);
	SzCache::SzTime t3(1420070400 + 3600 + 3600);
	SzCache::SzTime t4(1420070400 + 2678400);
	SzCache::SzTime t5(1420070400 + 2678400 + 3600 + 3600);
	SzCache::SzTime t6(1420070400 + 2678400 + 3600 + 3600 + 3600);
	SzCache::SzTime t7(1420070400 + 2678400 + 2419200);
	SzCache::SzTime t8(1420070400 + 2678400 + 2419200 + 3600);
	SzCache::SzPath szp1("TestA/TestB/TestC");

	try {
		SzCache::SzSearchResult ssr = szc.searchInPlace(t1,szp1);
		std::cout << "SzCache::searchInPlace("<<t1<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!");

		ssr = szc.searchInPlace(t2,szp1);
		std::cout << "SzCache::searchInPlace("<<t2<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != t2) throw std::logic_error("Assertion failed!");

		ssr = szc.searchInPlace(t2-10,szp1);
		std::cout << "SzCache::searchInPlace("<<t2-10<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!");

		ssr = szc.searchInPlace(t3,szp1);
		std::cout << "SzCache::searchInPlace("<<t3<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != t3) throw std::logic_error("Assertion failed!");

		ssr = szc.searchInPlace(t3+10,szp1);
		std::cout << "SzCache::searchInPlace("<<t3+10<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!");

		ssr = szc.searchInPlace(t4,szp1);
		std::cout << "SzCache::searchInPlace("<<t4<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != t4) throw std::logic_error("Assertion failed!");

		ssr = szc.searchInPlace(t5,szp1);
		std::cout << "SzCache::searchInPlace("<<t5<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != t5) throw std::logic_error("Assertion failed!");

		ssr = szc.searchInPlace(t5+10,szp1);
		std::cout << "SzCache::searchInPlace("<<t5+10<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!");

		ssr = szc.searchInPlace(t6,szp1);
		std::cout << "SzCache::searchInPlace("<<t6<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != t6) throw std::logic_error("Assertion failed!");

		ssr = szc.searchInPlace(t6-10,szp1);
		std::cout << "SzCache::searchInPlace("<<t6-10<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!");

		ssr = szc.searchInPlace(t7,szp1);
		std::cout << "SzCache::searchInPlace("<<t7<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!");

		ssr = szc.searchInPlace(t8,szp1);
		std::cout << "SzCache::searchInPlace("<<t8<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != t8) throw std::logic_error("Assertion failed!");

		ssr = szc.searchInPlace(t8-10,szp1);
		std::cout << "SzCache::searchInPlace("<<t8-10<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!");

		ssr = szc.searchRight(t2-50,t3,szp1); 
		std::cout << "SzCache::searcRight("<<t2-50<<","<<t3<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != t2) throw std::logic_error("Assertion failed!");

		ssr = szc.searchRight(t2+50,t4,szp1); 
		std::cout << "SzCache::searcRight("<<t2+50<<","<<t4<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != (t2+50)) throw std::logic_error("Assertion failed!");
		
		ssr = szc.searchRight(t3+10,t3+50,szp1); 
		std::cout << "SzCache::searcRight("<<t3+10<<","<<t3+50<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!");

		ssr = szc.searchRight(t4-100,t5,szp1); 
		std::cout << "SzCache::searcRight("<<t4-100<<","<<t5<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != t4) throw std::logic_error("Assertion failed!");

		ssr = szc.searchLeft(t7+100,t6,szp1); 
		std::cout << "SzCache::searchLeft("<<t7+100<<","<<t6<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != (t7-10)) throw std::logic_error("Assertion failed!");

		ssr = szc.searchLeft(t6+100,t5,szp1); 
		std::cout << "SzCache::searchLeft("<<t6+100<<","<<t5<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != (t6+100)) throw std::logic_error("Assertion failed!");

		ssr = szc.searchLeft(t3+100,t3+10,szp1); 
		std::cout << "SzCache::searchLeft("<<t3+100<<","<<t3+10<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!");

		ssr = szc.searchLeft(t3+100,t3+10,szp1); 
		std::cout << "SzCache::searchLeft("<<t3+100<<","<<t3+10<<","<<szp1<<"):\n"
			<< "= ( " << std::get<0>(ssr) << " , " << std::get<1>(ssr) << " , " << std::get<2>(ssr) << " )\n\n";
		if(std::get<0>(ssr) != -1) throw std::logic_error("Assertion failed!");
		
		std::vector<int16_t> vals;
		
		SzCache::SzTime wtime = szc.writeData(vals, t2-50, t2+50, szp1);
		while( wtime < t2+50 ) 
			wtime = szc.writeData(vals, wtime, t2+50, szp1);
		std::cout << "writeData(" << t2-50 << "," << t2+50 << "):\n";
		for (unsigned int i = 0; i < vals.size(); i++) {
			std::cout << vals[i] << std::endl;
			if ((i < 5) && (vals[i] != SzCache::cSzCacheNoData))
				throw std::logic_error("Assertion failed!");
			if ((i > 5) && (vals[i] != 75))
				throw std::logic_error("Assertion failed!");
		}
		std::cout << std::endl;
		vals.clear();

		wtime = szc.writeData(vals, t4-50, t4+50, szp1);
		while( wtime < t4+50 ) 
			wtime = szc.writeData(vals, wtime, t4+50, szp1);
		std::cout << "writeData(" << t4-50 << "," << t4+50 << "):\n";
		for (unsigned int i = 0; i < vals.size(); i++) {
			std::cout << vals[i] << std::endl;	
			if ((i < 5) && (vals[i] != SzCache::cSzCacheNoData))
				throw std::logic_error("Assertion failed!");
			if ((i > 5) && (vals[i] != 85))
				throw std::logic_error("Assertion failed!");
		}
		std::cout << std::endl;
		vals.clear();

		wtime = szc.writeData(vals, t7-50, t7+50, szp1);
		while( wtime < t7+50 ) 
			wtime = szc.writeData(vals, wtime, t7+50, szp1);
		std::cout << "writeData(" << t7-50 << "," << t7+50 << "):\n";
		for (unsigned int i = 0; i < vals.size(); i++) {
			std::cout << vals[i] << std::endl;
			if ((i < 5) && (vals[i] != 85))
				throw std::logic_error("Assertion failed!");
			if ((i > 5) && (vals[i] != SzCache::cSzCacheNoData))
				throw std::logic_error("Assertion failed!");
		}
		std::cout << std::endl;
		vals.clear();

		

	} catch (std::logic_error& le) {
		removeSzCacheFile("TestA/TestB/TestC/201501.szc");
		removeSzCacheFile("TestA/TestB/TestC/201502.szc");
		removeSzCacheFile("TestA/TestB/TestC/201503.szc");
		removeTestTree();

		std::cout << "Assertion has failed!" << std::endl;
		return -1;
	}
		
	std::cout << "All assertions valid: Test PASSED" << std::endl;
	/** Remove test environ */

	removeSzCacheFile("TestA/TestB/TestC/201501.szc");
	removeSzCacheFile("TestA/TestB/TestC/201502.szc");
	removeSzCacheFile("TestA/TestB/TestC/201503.szc");
	removeTestTree();
	
	return 0;
}
示例#22
0
int main(int argc, char * const argv[])
{
        int opt_index, c;
        static struct option long_opts[] = {
                {"target", 1, 0, 0},
                {"dumpfile", 1, 0, 0},
                {"ssh", 1, 0, 0},
                {0, 0, 0, 0}
        };

        if (argc < 4 - (getenv(ENV_LUSTRE_MNTTGT)||getenv(ENV_LUSTRE_DUMPFILE)))
                usage(argv[0]);

        while ((c = getopt_long(argc, argv, "s:b:f:", long_opts, &opt_index)) != -1) {
                switch (c) {
                case 0: {
                        if (!optarg[0])
                                usage(argv[0]);

                        if (!strcmp(long_opts[opt_index].name, "target")) {
                                setenv(ENV_LUSTRE_MNTTGT, optarg, 1);
                        } else if (!strcmp(long_opts[opt_index].name, "dumpfile")) {
                                setenv(ENV_LUSTRE_DUMPFILE, optarg, 1);
                        } else if (!strcmp(long_opts[opt_index].name, "ssh")) {
                                safe_strncpy(ssh_cmd, optarg, MAX_STRING_SIZE);
                        } else
                                usage(argv[0]);
                        break;
                }
                case 's':
                        safe_strncpy(mds_server, optarg, MAX_STRING_SIZE);
                        break;
                case 'b':
                        safe_strncpy(barrier_script, optarg, MAX_STRING_SIZE);
                        break;
                case 'f':
                        safe_strncpy(failover_script, optarg, MAX_STRING_SIZE);
                        break;
                default:
                        usage(argv[0]);
                }
        }

        if (optind != argc)
                usage(argv[0]);
        if (!strlen(mds_server) || !strlen(barrier_script) ||
            !strlen(failover_script))
                usage(argv[0]);

        /* default to using ssh */
        if (!strlen(ssh_cmd)) {
                safe_strncpy(ssh_cmd, "ssh", MAX_STRING_SIZE);
        }

        test_ssh();

        /* prepare remote command */
        sprintf(barrier_cmd, "%s %s \"%s\"", 
                ssh_cmd, mds_server, barrier_script);
        sprintf(failover_cmd, "%s %s \"%s\"", 
                ssh_cmd, mds_server, failover_script);

        setenv(ENV_LUSTRE_TIMEOUT, "10", 1);

        __liblustre_setup_();

        t0();
        t1();
        t2a();
        t2b();
        t3a();
        t3b();
        t4();
        t5();
        t6();
        t7();
        t8();
        t9();
        t10();

	printf("liblustre is about shutdown\n");
        __liblustre_cleanup_();

	printf("complete successfully\n");
	return 0;
}
示例#23
0
/* ==================================== */
int32_t lattribute(
        struct xvimage *img, /* image de depart */
        int32_t connex,          /* 4, 8  */
        int32_t typregion,       /* = <LABMIN | LABMAX | LABPLATEAU> */
        int32_t attrib,          /* 0: surface, 1: perimetre, 2: circularite, 3: nb. trous, 
                                4: excentricite, 5: orientation, 6: diamètre vertical, 7: diamètre horizontal */
        int32_t seuil,           /* en dessous (<=) de seuil, l'attribut est mis a 0 */
        struct xvimage *lab, /* resultat: image d'attributs */
        int32_t *nlabels)        /* resultat: nombre de regions traitees */
/* ==================================== */
#undef F_NAME
#define F_NAME "lattribute"
{
  int32_t k, l;
  index_t w, x, y, z;
  uint8_t *SOURCE = UCHARDATA(img);
  int32_t *LABEL = SLONGDATA(lab);
  index_t rs = rowsize(img);
  index_t cs = colsize(img);
  index_t d = depth(img);
  index_t N = rs * cs;          /* taille image */
  Lifo * LIFO;
  int32_t label;
  int32_t area;
  int32_t perim;
  int32_t min, max;
  int32_t val_attrib;
  double mx1, my1; // cumuls des variables x et y
  double mx2, my2, mxy2; // cumuls des x^2, y^2 et xy
  int32_t incr_vois;

  if (datatype(lab) != VFF_TYP_4_BYTE) 
  {
    fprintf(stderr, "%s: le resultat doit etre de type VFF_TYP_4_BYTE\n", F_NAME);
    return 0;
  }

  if ((rowsize(lab) != rs) || (colsize(lab) != cs) || (depth(lab) != d))
  {
    fprintf(stderr, "%s: tailles images incompatibles\n", F_NAME);
    return 0;
  }

  if (depth(img) != 1) 
  {
    fprintf(stderr, "%s: cette version ne traite pas les images volumiques\n", F_NAME);
    exit(0);
  }

  switch (connex)
  {
    case 4: incr_vois = 2; break;
    case 8: incr_vois = 1; break;
    default: 
      fprintf(stderr, "%s: mauvaise connexite: %d\n", F_NAME, connex);
      return 0;
  } /* switch (connex) */

  /* le LABEL initialement est mis a NONMARQUE */
  for (x = 0; x < N; x++) LABEL[x] = NONMARQUE;

  LIFO = CreeLifoVide(N);
  if (LIFO == NULL)
    {   fprintf(stderr, "%s: CreeLifoVide failed\n", F_NAME);
      return(0);
  }

  *nlabels = 0;

if ((typregion == LABMIN) || (typregion == LABMAX))
{
  for (x = 0; x < N; x++)
  {
    if (LABEL[x] == NONMARQUE)   /* on trouve un point x non etiquete */
    {
      *nlabels += 1;
      LABEL[x] = MARQUE;
#ifdef DEBUGTROU
printf("AMORCE p=%d,%d h=%d set LABEL = %d\n", x%rs, x/rs, SOURCE[x], LABEL[x]);
#endif
      switch (attrib)            /* on initialise les attributs de cette composante */
      {
	case AREA: val_attrib = 0; break;
	case PERIM: val_attrib = 0; break;
	case TROUS: val_attrib = 0; break;
	case CIRC: area = perim = 0; break;
	case EXCEN: 
	case ORIEN: area = 0; mx1 = my1 = mx2 = my2 = mxy2 = 0.0; break;
        case VDIAM: min = cs-1; max = 0; break;
        case HDIAM: min = rs-1; max = 0; break;
        default: 
          fprintf(stderr, "%s: mauvais attribut: %d\n", F_NAME, attrib);
          return 0;
      } /* switch (attrib) */
      LifoPush(LIFO, x);         /* on va parcourir le plateau auquel appartient x */
      while (! LifoVide(LIFO))
      {
        w = LifoPop(LIFO);
        label = LABEL[w];
        if (label == MARQUE)     /* c'est une propagation de "marquage" : pour l'instant, */
	{                        /* on croit qu'on est dans un extremum */         
          switch (attrib)
          {
  	    case AREA: val_attrib++; break;
  	    case VDIAM: if (w/rs < min) min = w/rs; else if (w/rs > max) max = w/rs; break;
  	    case HDIAM: if (w%rs < min) min = w%rs; else if (w%rs > max) max = w%rs; break;
  	    case EXCEN:
  	    case ORIEN: area++; mx1 += w%rs; my1 += w/rs; mxy2 += (w%rs) * (w/rs);
                        mx2 += (w%rs) * (w%rs); my2 += (w/rs) * (w/rs); break;
  	    case PERIM: 
              if (w%rs==rs-1) val_attrib++; /* point de bord */
              if (w<rs)       val_attrib++; /* point de bord */
              if (w%rs==0)    val_attrib++; /* point de bord */
              if (w>=N-rs)    val_attrib++; /* point de bord */
              for (k = 0; k < 8; k += 2) /* 4-connexite obligatoire */
              {
                y = voisin(w, k, rs, N);
                if ((y != -1) && (SOURCE[y] != SOURCE[w])) val_attrib++;
              } /* for k */
            break;
            case CIRC:
              area++;
              if (w%rs==rs-1) perim++; /* point de bord */
              if (w<rs)       perim++; /* point de bord */
              if (w%rs==0)    perim++; /* point de bord */
              if (w>=N-rs)    perim++; /* point de bord */
              for (k = 0; k < 8; k += 2) /* 4-connexite obligatoire */
              {
                y = voisin(w, k, rs, N);
                if ((y != -1) && (SOURCE[y] != SOURCE[w])) perim++;
              } /* for k */
              break;
	  } /* switch (attrib) */
          for (k = 0; k < 8; k += incr_vois)
          {
            y = voisin(w, k, rs, N);
            if (y != -1)
            {
              if (((typregion == LABMIN) && (SOURCE[y] < SOURCE[w])) || 
                  ((typregion == LABMAX) && (SOURCE[y] > SOURCE[w])))
              {   /* w non dans un minimum (resp. maximum) */
                if (label == MARQUE)
		{
                  label = NONEXTREM;
                  *nlabels -= 1;
                  LABEL[w] = label;
                  LifoPush(LIFO, w);
		}
              } 
              else
              if ((SOURCE[y] == SOURCE[w]) && (LABEL[y] == NONMARQUE))
              {
                LABEL[y] = label;
#ifdef DEBUGTROU
printf(" p=%d,%d h=%d set LABEL = %d\n", y%rs, y/rs, SOURCE[y], LABEL[y]);
#endif
                LifoPush(LIFO, y);
                if (attrib == TROUS)
	        {
                  int32_t masque = 0, imasque = 1;
                  /* fabrique le masque des voisins de y MARQUES */
                  for (l = 0; l < 8; l += 1)
                  {
                    z = voisin(y, l, rs, N);
                    if ((z != -1) && (LABEL[z] == MARQUE))
                      masque |= imasque; 
                    imasque = imasque << 1;
                  } /* for k ... */
#ifdef DEBUGTROU
printf(" p=%d,%d h=%d masque=%x t4m=%d t8b=%d\n", y%rs, y/rs, SOURCE[y], masque, t4(masque), t8b(masque));
#endif
                  if (connex == 4) 
                    { val_attrib += (t4(masque) - 1); if (t8b(masque) == 0) val_attrib--; }
                  else
                    { val_attrib += (t8(masque) - 1); if (t4b(masque) == 0) val_attrib--; }
	        } /* if (attrib == TROUS) */
              } /* if ((SOURCE[y] == SOURCE[w]) && (LABEL[y] == NONMARQUE)) */
            } /* if (y != -1) */
          } /* for k ... */
	} /* if (label == MARQUE) */
        else                           /* propagation de "demarquage" */
	{
          for (k = 0; k < 8; k += incr_vois)
          {
            y = voisin(w, k, rs, N);
            if (y != -1)
            {
              if ((SOURCE[y] == SOURCE[w]) && (LABEL[y] != NONEXTREM))
              {
                LABEL[y] = NONEXTREM;
                LifoPush(LIFO, y);
              } /* if .. */
            } /* if (y != -1) */
          } /* for k ... */
	} /* else if (label == MARQUE) */
      } /* while (! LifoVide(LIFO)) */

      if (label == MARQUE)
      {
        if (attrib == CIRC) 
	{
          val_attrib = (int32_t)(256 * 4 * M_PI * (double)area / (double)(perim * perim));
          if (val_attrib > 255)
	  {
            fprintf(stderr, "WARNING: indice de circularite > 255 : %d, a=%d, p=%d\n", 
                            val_attrib, area, perim);
            val_attrib = 255;
	  }
	}
        if (attrib == EXCEN) val_attrib = excentricity(mx1, my1, mx2, my2, mxy2, area);
        if (attrib == ORIEN) val_attrib = orientation(mx1, my1, mx2, my2, mxy2, area);
        if (attrib == VDIAM) val_attrib = max - min + 1;
        if (attrib == HDIAM) val_attrib = max - min + 1;
        if (val_attrib <= seuil) val_attrib = 0;
#ifdef VERBOSE
printf("valeur attribut = %d\n", val_attrib);
#endif
        LifoPush(LIFO, x);         /* on re-parcourt le plateau pour propager l'attribut */
        LABEL[x] = val_attrib;
        while (! LifoVide(LIFO))
        {
          w = LifoPop(LIFO);
          for (k = 0; k < 8; k += incr_vois)
          {
            y = voisin(w, k, rs, N);
            if ((y != -1) && (LABEL[y] == MARQUE)) 
            {
              LABEL[y] = val_attrib;
              LifoPush(LIFO, y);
	    }
          } /* for k ... */
	} /* while (! LifoVide(LIFO)) */
      } /* if (label == MARQUE) */

    } /* if (LABEL[x] != -1) */
  } /* for (x = 0; x < N; x++) */
} /* if ((typregion == LABMIN) || (typregion == LABMAX)) */
else
{
  if (attrib == TROUS)
  {
    fprintf(stderr, "%s: attribut TROUS non compatible avec typreg = PLA\n", F_NAME);
    return 0;
  }
  for (x = 0; x < N; x++)
  {
    if (LABEL[x] == NONMARQUE)
    {
      *nlabels += 1;
      LABEL[x] = *nlabels;
      switch (attrib)            /* on initialise les attributs de cette composante */
      {
	case AREA: val_attrib = 0; break;
        case VDIAM: min = cs-1; max = 0; break;
        case HDIAM: min = rs-1; max = 0; break;
	case PERIM: val_attrib = 0; break;
	case CIRC: area = perim = 0; break;
	case EXCEN: 
	case ORIEN: area = 0; mx1 = my1 = mx2 = my2 = mxy2 = 0.0; break;
        default: 
          fprintf(stderr, "%s: mauvais attribut: %d\n", F_NAME, attrib);
          return 0;
      } /* switch (attrib) */
      LifoPush(LIFO, x);
      while (! LifoVide(LIFO))
      {
        w = LifoPop(LIFO);
        switch (attrib)
        {
	  case AREA: val_attrib++; break;
  	  case VDIAM: if (w/rs < min) min = w/rs; else if (w/rs > max) max = w/rs; break;
  	  case HDIAM: if (w%rs < min) min = w%rs; else if (w%rs > max) max = w%rs; break;
	  case EXCEN:
	  case ORIEN: area++; mx1 += w%rs; my1 += w/rs; mxy2 += (w%rs) * (w/rs);
                      mx2 += (w%rs) * (w%rs); my2 += (w/rs) * (w/rs); break;
  	  case PERIM: 
            if (w%rs==rs-1) val_attrib++; /* point de bord */
            if (w<rs)       val_attrib++; /* point de bord */
            if (w%rs==0)    val_attrib++; /* point de bord */
            if (w>=N-rs)    val_attrib++; /* point de bord */
            for (k = 0; k < 8; k += 2) /* 4-connexite obligatoire */
            {
              y = voisin(w, k, rs, N);
              if ((y != -1) && (SOURCE[y] != SOURCE[w])) val_attrib++;
            } /* for k */
          break;
          case CIRC:
            area++;
            if (w%rs==rs-1) perim++; /* point de bord */
            if (w<rs)       perim++; /* point de bord */
            if (w%rs==0)    perim++; /* point de bord */
            if (w>=N-rs)    perim++; /* point de bord */
            for (k = 0; k < 8; k += 2) /* 4-connexite obligatoire */
            {
              y = voisin(w, k, rs, N);
              if ((y != -1) && (SOURCE[y] != SOURCE[w])) perim++;
            } /* for k */
            break;
	} /* switch (attrib) */

        for (k = 0; k < 8; k += incr_vois)
        {
          y = voisin(w, k, rs, N);
          if ((y != -1) && (LABEL[y] == NONMARQUE) && (SOURCE[y] == SOURCE[w]))
          {
            LABEL[y] = MARQUE;
            LifoPush(LIFO, y);
          } /* if y ... */
        } /* for k ... */
      } /* while (! LifoVide(LIFO)) */

      if (attrib == CIRC) 
      {
        val_attrib = (int32_t)(256 * 4 * M_PI * (double)area / (double)(perim * perim));
        if (val_attrib > 255)
	{
          fprintf(stderr, "WARNING: indice de circularite > 255 : %d, a=%d, p=%d\n", 
                          val_attrib, area, perim);
          val_attrib = 255;
	}
      }
      if (attrib == EXCEN) val_attrib = excentricity(mx1, my1, mx2, my2, mxy2, area);
      if (attrib == ORIEN) val_attrib = orientation(mx1, my1, mx2, my2, mxy2, area);
      if (attrib == VDIAM) val_attrib = max - min + 1;
      if (attrib == HDIAM) val_attrib = max - min + 1;
      if (val_attrib <= seuil) val_attrib = 0;

      LifoPush(LIFO, x);         /* on re-parcourt le plateau pour propager l'attribut */
      LABEL[x] = val_attrib;
      while (! LifoVide(LIFO))
      {
        w = LifoPop(LIFO);
        for (k = 0; k < 8; k += incr_vois)
        {
          y = voisin(w, k, rs, N);
          if ((y != -1) && (LABEL[y] == MARQUE)) 
          {
            LABEL[y] = val_attrib;
            LifoPush(LIFO, y);
	  }
        } /* for k ... */
      } /* while (! LifoVide(LIFO)) */
    } /* if (LABEL[x] == NONMARQUE) */
  } /* for (x = 0; x < N; x++) */
} /* else if ((typregion == LABMIN) || (typregion == LABMAX)) */

  LifoTermine(LIFO);

  *nlabels += 1; /* pour le niveau 0 */
  return(1);
} // lattribute()
示例#24
0
int main(){
	vector< string > Flds;
	Flds.push_back("NAME");
	Flds.push_back("UIN");
	Flds.push_back("MAJOR");
	cout<<" Table Created\n\n";
	Table t(Flds);
	t.show();
	
	cout<<"Adding two rows to the table\n\n";
	
	Flds[0] = "Jane Doe";
	Flds[1] = "101010101";
	Flds[2] = "CSCE";
	bool test1 = t.addEntry(Flds);
	if(test1) cout<<"Added row 1 successfully...\n";
	else cout<<"FAILED to add row 1\n";
	
	Flds[0] = "John Smith";
	Flds[1] = "010101010";
	Flds[2] = "CPSC";
	bool test2 = t.addEntry(Flds);
	if(test2) cout<<"Added row 2 successfully...\n\n";
	else cout<<"FAILED to add row 2\n\n";
	t.show();

	Flds[0]=("NAME");
	Flds[1]=("UIN");
	Flds[2]=("MAJOR");
	Table t2(Flds);
	Flds[0]=("Paul Gaughan");
	Flds[1]=("519001954");
	Flds[2]=("ECEN"); 
	t2.addEntry(Flds);
	Flds[0] = "John Smith";
	Flds[1] = "010101010";
	Flds[2] = "CPSC";
	t2.addEntry(Flds);
	cout<< "Created second table:\n\n";
	t2.show();
	
	Table t3(t);
	bool test3 = t3.setUnion(t2);
	if(	test3){ cout<<"\nTable 3: Set Union of first and second Tables:\n\n";	t3.show();}
	else cout<<"\n Set Union Failed.  Size mismatch.\n";
	
	Table t4(t);
	bool test4 = t4.setDifference(t2);
	if(	test4){ cout<<"\nTable 4: Set Difference of first and second Tables:\n\n";	t4.show();}
	else cout<<"\n Set Difference Failed.  Size mismatch.\n";
	
	Table t5(t);
	cout<<"\nTable 5: Computing Cartesian Product of first and second tables:\n\n";
	t5.crossProduct(t2);
	t5.show();
	
	cout<<"\n\nAttempting to compute set Union and Difference of first and fifth Tables\n\n";
	bool test6 = t5.setUnion(t);
	bool test7 = t5.setDifference(t);
	cout<<"Result:  Union Allowed?: " << test6<<"  Diff Allowed?: "<<test7<<endl;
	
	cout<<"\nTable 6: Projection of Names column from Table 3\n\n";
	vector<int> columns;
	columns.push_back(0);
	Table t6 = *(t3.projection(columns));
	t6.show();
	
	cout<<"\nTable 7: Selecting Row with Name = Paul Gaughan from Table 3\n\n";
	Table t7 = *(t3.rowQuerry("Paul Gaughan", "NAME"));
	t7.show();
	
	cout<<"\nTable 8: Renaming UIN column in Table 1 to NUMBER\n\n";
	Table t8(t);
	bool test8 = t8.update("NAME", "UIN", "NUMBER");
	t8.show();

	cout<<"\n Table 9: Removing row with Key = Jane Doe from Table 1\n\n";
	Table t9(t);
	vector< string > temp = t9.removeRow("Jane Doe");
	t9.show();
	bool test9 = false;
	if (temp[0].compare("Jane Doe")==0) test9 = true;
	
	cout<<"\n\n\n\n";
	if(test1 && test2 && test3 && test4 && (!test6) &&(!test7) && test8 && test9){
		cout<<"ALL TESTS PASSED!\n";
	}else cout<<"\nFAIL!";
	
}
示例#25
0
void CIcosahedron::init( float s  ){

	this->clearMesh();
	float p = ((1.0 + sqrt(5.0))/2.0)*s;

	TVector3 v0(s,0.0,p);
	this->iVertices.push_back(v0);
	TVector3 v1(-s,0.0,p);
	this->iVertices.push_back(v1);
	TVector3 v2(s,0.0,-p);
	this->iVertices.push_back(v2);
	TVector3 v3(-s,0.0,-p);
	this->iVertices.push_back(v3);
	TVector3 v4(0.0,p,s);
	this->iVertices.push_back(v4);
	TVector3 v5(0,-p,s);
	this->iVertices.push_back(v5);
	TVector3 v6(0,p,-s);
	this->iVertices.push_back(v6);
	TVector3 v7(0.0,-p,-s);
	this->iVertices.push_back(v7);
	TVector3 v8(p,s,0.0);
	this->iVertices.push_back(v8);
	TVector3 v9(-p,s,0.0);
	this->iVertices.push_back(v9);
	TVector3 v10(p,-s,0.0);
	this->iVertices.push_back(v10);
	TVector3 v11(-p,-s,0.0);
	this->iVertices.push_back(v11);


	TTriangle t0(0,4,1);
	this->iTriangles.push_back(t0);

	TTriangle t1(0,1,5);
	this->iTriangles.push_back(t1);

	TTriangle t2(0,5,10);
	this->iTriangles.push_back(t2);

	TTriangle t3(0,10,8);
	this->iTriangles.push_back(t3);

	TTriangle t4(0,8,4);
	this->iTriangles.push_back(t4);

	TTriangle t5(4,8,6);
	this->iTriangles.push_back(t5);

	TTriangle t6(4,6,9);
	this->iTriangles.push_back(t6);

	TTriangle t7(4,9,1);
	this->iTriangles.push_back(t7);

	TTriangle t8(1,9,11);
	this->iTriangles.push_back(t8);

	TTriangle t9(1,11,5);
	this->iTriangles.push_back(t9);

	TTriangle t10(2,7,3);
	this->iTriangles.push_back(t10);

	TTriangle t11(2,3,6);
	this->iTriangles.push_back(t11);

	TTriangle t12(2,6,8);
	this->iTriangles.push_back(t12);

	TTriangle t13(2,8,10);
	this->iTriangles.push_back(t13);

	TTriangle t14(2,10,7);
	this->iTriangles.push_back(t14);

	TTriangle t15(7,10,5);
	this->iTriangles.push_back(t15);

	TTriangle t16(7,5,11);
	this->iTriangles.push_back(t16);

	TTriangle t17(7,11,3);
	this->iTriangles.push_back(t17);

	TTriangle t18(3,11,9);
	this->iTriangles.push_back(t18);

	TTriangle t19(3,9,6);
	this->iTriangles.push_back(t19);
	}
示例#26
0
文件: URI.cpp 项目: coredumped/X-VR2
		void URI::parse(){
			/*              hierarchycal-part
			 *          ____________|____________
			 *         /                         \
			 *   foo://example.com:8042/over/there?name=ferret#nose
      		 *   \_/   \______________/\_________/ \_________/ \__/
      		 *    |          |            |            |        |
      		 * scheme     authority     path          query   fragment
      		 *    |   ____________________|___
      		 *   / \ /                        \
      		 *   urn:example:animal:ferret:nose
      		 */
			size_t pos = 0;
			_scheme.clear();
			_port = -1;
			_path.clear();
			_fragment.clear();
			_query_string.clear();
			_param_string.clear();
			query.lock();
			query.clear();
			query.unlock();
			
			String hier_part;
			String non_hier_part;
			String __uri = _uri;
			
			pos = __uri.find(_scheme_div, 0);
			if(pos == __uri.npos){
				//Path is relative
				if(!__uri.startsWith("//")){
					__uri.insert(0, "//");
				}
				
			}
			else{
				_scheme = __uri.substr(0, pos + 1);
				__uri.biteLeft(pos + 1);
			}
			
			if(__uri.startsWith("//")){
				//Might be an URL
				__uri.biteLeft(2);
				if(__uri.find('?', 0) != __uri.npos){
					xvr2::Tokenizer t1(__uri, "?");
					hier_part = t1.next();
					non_hier_part = t1.next();
				}
				else if(__uri.find('#', 0) != __uri.npos){
					xvr2::Tokenizer t1(__uri, "#");
					hier_part = t1.next();
					non_hier_part = t1.next();
				}
				else{
					hier_part = __uri;
				}
				String address;
				//Now we got hierachical and non-hierarchical parts
				//Process hierarchical part
				if((pos = hier_part.find('/')) != hier_part.npos){
					address = hier_part.substr(0, pos);
					hier_part.biteLeft(pos);
					_path = hier_part;
				}
				else{
					address = hier_part;
				}
				if(address.size() > 0){
					String hostinfo;
					if((pos = address.find('@', 0)) != address.npos){
						Tokenizer t2(address, "@");
						String authinfo = t2.next();
						hostinfo = t2.next();
						if((pos = authinfo.find(':', 0)) == address.npos){
							_user = authinfo;
						}
						else{
							Tokenizer t3(authinfo, ":");
							_user = t3.next();
							_password = t3.next();
						}
					}
					else{
						_user.clear();
						_password.clear();
						hostinfo = address;
					}
					if(hostinfo.size() > 0){
						if(hostinfo.find(':', 0) == address.npos){
							//Only has the ip_address or hostname
							_host = hostinfo;
						}
						else{
							//Has hostname plus port information
							Tokenizer t4(hostinfo, ":");
							_host = t4.next();
							String tmpp = t4.next();
							_port = tmpp.toInt();
						}
					}
				}
				//TODO: Process non-hierarchical part
				if(non_hier_part.size() > 0){
					if(non_hier_part.find('#') == non_hier_part.npos){
						//Does not have a fragment
						_query_string = non_hier_part;
					}
					else{
						//Have a fragment
						Tokenizer t5(non_hier_part, "#");
						_query_string = t5.next();
						_fragment = t5.next();
					}
				}
				
				if(_path.find(';', 0) != _path.npos){
					//Has parameters, retrieve them
					Tokenizer t6(_path, ";");
					_path = t6.next();
					_param_string = t6.next();
				}
			}
			else{
				//Might be an URN
				throw xvr2::Net::URIParseException(_uri, "Resource is not a URI, looks more like a URN");
			}
			if(_scheme.size() > 0){
				_scheme.toLowerCase();
			}
			if(_port == -1){
				_scheme_port.lock();
				_port = _scheme_port[_scheme.c_str()];
				_scheme_port.unlock();
			}
			if(_query_string.size() > 0){
				//Fill in the query map
				Tokenizer t7(_query_string, "&");
				while(!t7.finished()){
					String q1 = t7.next();
					Tokenizer t8(q1, "=");
					try{
						String var = t8.next();
						String val = t8.next();
						query[var] = val;
					}
					catch(NoMoreTokens &nmt){
						StringBuffer sb;
						sb << "Malformed query in URI: " << q1; 
						throw URIParseException(_uri, sb.toString());
					}
				}
			}
		}
int main() {

	
	auto variance = 0;
	auto varianceSquared = 0;
	auto varianceSum = 0;
	auto standardDeviation = 0.0;
	std::vector<int> timeVector;
	std::vector<std::tuple<int, int, int>  > pixels;
	std::vector<std::tuple<int, int, int>  > pixels2;
	std::vector<std::tuple<int, int, int>  > pixels3;
	std::vector<std::tuple<int, int, int>  > pixels4;
	std::vector<std::tuple<int, int, int>  > pixels5;
	std::vector<std::tuple<int, int, int>  > pixels6;
	std::vector<std::tuple<int, int, int>  > pixels7;
	std::vector<std::tuple<int, int, int>  > pixels8;

	std::ofstream fout("output.ppm", std::ofstream::out);
	fout << "P3" << std::endl; // PPM file
	fout << imageWidth << " " << imageHeight << std::endl; //Image Dimensions
	fout << "256" << std::endl; // Max RGB pixel value

	std::cout << "Serial timing:" << std::endl;
	for (int x = 0; x < 5; x++) {
		auto startTime = std::chrono::steady_clock::now();
		pixels.clear();
		std::thread t([&]() {drawMandelBrot(pixels, 0, imageHeight); });
		t.join();

		auto endTime = std::chrono::steady_clock::now();
		auto time = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
		std::cout << int(time.count()) << " ms" << std::endl;
		timeVector.push_back(int(time.count()));
	}

	auto sum = std::accumulate(timeVector.begin(), timeVector.end(), 0);
	auto average = sum / timeVector.size();

	for (auto n : timeVector) {
		variance = n - average;
		varianceSquared = variance * variance;
		varianceSum += varianceSquared;
	}

	standardDeviation = sqrt(varianceSum / timeVector.size());
	std::cout << "Average: " << average << " ms" << std::endl;
	std::cout << "Standard Deviation: " << standardDeviation << " ms" << std::endl;
	std::cout << std::endl;

	//reset variables for accurate standard deviation
	variance = 0;
	varianceSquared = 0;
	varianceSum = 0;
	standardDeviation = 0.0;

	std::cout << "Serial timing:" << std::endl;
	timeVector.clear();
	for (int x = 0; x < 5; x++) {
		auto startTime = std::chrono::steady_clock::now();
		pixels.clear();
		std::thread t([&]() {drawMandelBrot(pixels, 0, imageHeight); });
		t.join();

		auto endTime = std::chrono::steady_clock::now();
		auto time = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
		std::cout << int(time.count()) << " ms" << std::endl;
		timeVector.push_back(int(time.count()));
	}

	auto sum10 = std::accumulate(timeVector.begin(), timeVector.end(), 0);
	auto average10 = sum10 / timeVector.size();

	for (auto n : timeVector) {
		variance = n - average10;
		varianceSquared = variance * variance;
		varianceSum += varianceSquared;
	}

	standardDeviation = sqrt(varianceSum / timeVector.size());
	std::cout << "Average: " << average10 << " ms" << std::endl;
	std::cout << "Standard Deviation: " << standardDeviation << " ms" << std::endl;
	std::cout << std::endl;

	//reset variables for accurate standard deviation
	variance = 0;
	varianceSquared = 0;
	varianceSum = 0;
	standardDeviation = 0.0;

	std::cout << "2 Parallel Threads timing:" << std::endl;
	timeVector.clear();
	for (int x = 0; x < 5; x++) {
		auto startTime = std::chrono::steady_clock::now();
		pixels.clear();
		pixels2.clear();
		std::thread t1([&]() {drawMandelBrot(pixels, 0, imageHeight / 2); });
		std::thread t2([&]() {drawMandelBrot(pixels2, (imageHeight / 2) + 1, imageHeight); });
		t1.join();
		t2.join();

		auto endTime = std::chrono::steady_clock::now();
		auto time = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
		std::cout << int(time.count()) << " ms" << std::endl;
		timeVector.push_back(int(time.count()));
	}
	pixels.insert(pixels.end(), pixels2.begin(), pixels2.end());
	double sum2 = std::accumulate(timeVector.begin(), timeVector.end(), 0);
	double average2 = sum2 / timeVector.size();
	double speedUp2 = average / average2;
	double efficiency2 = speedUp2 / 2;

	for (auto n : timeVector) {
		variance = n - average2;
		varianceSquared = variance * variance;
		varianceSum += varianceSquared;
	}

	standardDeviation = sqrt(varianceSum / timeVector.size());
	std::cout << "Average: " << average2 << " ms" << std::endl;
	std::cout << "Standard Deviation: " << standardDeviation << " ms" << std::endl;
	std::cout << "Speed Up: " << speedUp2 << std::endl;
	std::cout << "Efficiency: " << efficiency2 << std::endl;
	std::cout << std::endl;

	//reset variables for accurate standard deviation
	variance = 0;
	varianceSquared = 0;
	varianceSum = 0;
	standardDeviation = 0.0;

	std::cout << "3 Parallel Threads timing:" << std::endl;
	timeVector.clear();
	for (int x = 0; x < 5; x++) {
		auto startTime = std::chrono::steady_clock::now();
		pixels.clear();
		pixels2.clear();
		pixels3.clear();
		std::thread t1([&]() {drawMandelBrot(pixels, 0, imageHeight / 3); });
		std::thread t2([&]() {drawMandelBrot(pixels2, ((imageHeight / 3) + 1), (imageHeight / 3) * 2 ); });
		std::thread t3([&]() {drawMandelBrot(pixels3, (((imageHeight / 3) * 2) + 1), imageHeight); });
		t1.join();
		t2.join();
		t3.join();

		auto endTime = std::chrono::steady_clock::now();
		auto time = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
		std::cout << int(time.count()) << " ms" << std::endl;
		timeVector.push_back(int(time.count()));
	}
	
	pixels.insert(pixels.end(), pixels2.begin(), pixels2.end());	
	pixels.insert(pixels.end(), pixels3.begin(), pixels3.end());	
	double sum3 = std::accumulate(timeVector.begin(), timeVector.end(), 0);
	double average3 = sum3 / timeVector.size();
	double speedUp3 = average / average3;
	double efficiency3 = speedUp3 / 3;

	for (auto n : timeVector) {
		variance = n - average3;
		varianceSquared = variance * variance;
		varianceSum += varianceSquared;
	}

	standardDeviation = sqrt(varianceSum / timeVector.size());
	std::cout << "Average: " << average3 << " ms" << std::endl;
	std::cout << "Standard Deviation: " << standardDeviation << " ms" << std::endl;
	std::cout << "Speed Up: " << speedUp3 << std::endl;
	std::cout << "Efficiency: " << efficiency3 << std::endl;
	std::cout << std::endl;

	//reset variables for accurate standard deviation
	variance = 0;
	varianceSquared = 0;
	varianceSum = 0;
	standardDeviation = 0.0;

	std::cout << "4 Parallel Threads timing:" << std::endl;
	timeVector.clear();
	for (int x = 0; x < 5; x++) {
		auto startTime = std::chrono::steady_clock::now();
		pixels.clear();
		pixels2.clear();
		pixels3.clear();
		pixels4.clear();
		std::thread t1([&]() {drawMandelBrot(pixels, 0, imageHeight / 4); });
		std::thread t2([&]() {drawMandelBrot(pixels2, ((imageHeight / 4) + 1), imageHeight / 2); });
		std::thread t3([&]() {drawMandelBrot(pixels3, ((imageHeight / 2) + 1), (imageHeight / 4) * 3); });
		std::thread t4([&]() {drawMandelBrot(pixels4, (((imageHeight / 4) * 3) + 1), imageHeight); });
		t1.join();
		t2.join();
		t3.join();
		t4.join();

		auto endTime = std::chrono::steady_clock::now();
		auto time = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
		std::cout << int(time.count()) << " ms" << std::endl;
		timeVector.push_back(int(time.count()));
	}

	pixels.insert(pixels.end(), pixels2.begin(), pixels2.end());
	pixels.insert(pixels.end(), pixels3.begin(), pixels3.end());
	pixels.insert(pixels.end(), pixels4.begin(), pixels4.end());
	double sum4 = std::accumulate(timeVector.begin(), timeVector.end(), 0);
	double average4 = sum4 / timeVector.size();
	double speedUp4 = average / average4;
	double efficiency4 = speedUp4 / 4;

	for (auto n : timeVector) {
		variance = n - average4;
		varianceSquared = variance * variance;
		varianceSum += varianceSquared;
	}

	standardDeviation = sqrt(varianceSum / timeVector.size());
	std::cout << "Average: " << average4 << " ms" << std::endl;
	std::cout << "Standard Deviation: " << standardDeviation << " ms" << std::endl;
	std::cout << "Speed Up: " << speedUp4 << std::endl;
	std::cout << "Efficiency: " << efficiency4 << std::endl;
	std::cout << std::endl;

	//reset variables for accurate standard deviation
	variance = 0;
	varianceSquared = 0;
	varianceSum = 0;
	standardDeviation = 0.0;

	std::cout << "5 Parallel Threads timing:" << std::endl;
	timeVector.clear();
	for (int x = 0; x < 5; x++) {
		auto startTime = std::chrono::steady_clock::now();
		pixels.clear();
		pixels2.clear();
		pixels3.clear();
		pixels4.clear();
		pixels5.clear();
		std::thread t1([&]() {drawMandelBrot(pixels, 0, imageHeight / 5); });
		std::thread t2([&]() {drawMandelBrot(pixels2, ((imageHeight / 5) + 1), (imageHeight / 5) * 2); });
		std::thread t3([&]() {drawMandelBrot(pixels3, (((imageHeight / 5) * 2)+ 1), (imageHeight / 5) * 3); });
		std::thread t4([&]() {drawMandelBrot(pixels4, (((imageHeight / 5) * 3) + 1), (imageHeight / 5) * 4); });
		std::thread t5([&]() {drawMandelBrot(pixels5, (((imageHeight / 5) * 4) + 1), imageHeight); });
		t1.join();
		t2.join();
		t3.join();
		t4.join();
		t5.join();

		auto endTime = std::chrono::steady_clock::now();
		auto time = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
		std::cout << int(time.count()) << " ms" << std::endl;
		timeVector.push_back(int(time.count()));
	}

	pixels.insert(pixels.end(), pixels2.begin(), pixels2.end());
	pixels.insert(pixels.end(), pixels3.begin(), pixels3.end());
	pixels.insert(pixels.end(), pixels4.begin(), pixels4.end());
	pixels.insert(pixels.end(), pixels5.begin(), pixels5.end());
	double sum5 = std::accumulate(timeVector.begin(), timeVector.end(), 0);
	double average5 = sum5 / timeVector.size();
	double speedUp5 = average / average5;
	double efficiency5 = speedUp5 / 5;

	for (auto n : timeVector) {
		variance = n - average5;
		varianceSquared = variance * variance;
		varianceSum += varianceSquared;
	}

	standardDeviation = sqrt(varianceSum / timeVector.size());
	std::cout << "Average: " << average5 << " ms" << std::endl;
	std::cout << "Standard Deviation: " << standardDeviation << " ms" << std::endl;
	std::cout << "Speed Up: " << speedUp5 << std::endl;
	std::cout << "Efficiency: " << efficiency5 << std::endl;
	std::cout << std::endl;

	//reset variables for accurate standard deviation
	variance = 0;
	varianceSquared = 0;
	varianceSum = 0;
	standardDeviation = 0.0;

	std::cout << "6 Parallel Threads timing:" << std::endl;
	timeVector.clear();
	for (int x = 0; x < 5; x++) {
		auto startTime = std::chrono::steady_clock::now();
		pixels.clear();
		pixels2.clear();
		pixels3.clear();
		pixels4.clear();
		pixels5.clear();
		pixels6.clear();
		std::thread t1([&]() {drawMandelBrot(pixels, 0, imageHeight / 6); });
		std::thread t2([&]() {drawMandelBrot(pixels2, ((imageHeight / 6) + 1), imageHeight / 3); });
		std::thread t3([&]() {drawMandelBrot(pixels3, ((imageHeight / 3) + 1), (imageHeight / 2)); });
		std::thread t4([&]() {drawMandelBrot(pixels4, ((imageHeight / 2) + 1), (imageHeight / 3) * 2); });
		std::thread t5([&]() {drawMandelBrot(pixels5, (((imageHeight / 3) * 2) + 1), (imageHeight / 6) * 5); });
		std::thread t6([&]() {drawMandelBrot(pixels6, (((imageHeight / 6) * 5) + 1), imageHeight); });
		t1.join();
		t2.join();
		t3.join();
		t4.join();
		t5.join();
		t6.join();

		auto endTime = std::chrono::steady_clock::now();
		auto time = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
		std::cout << int(time.count()) << " ms" << std::endl;
		timeVector.push_back(int(time.count()));
	}

	pixels.insert(pixels.end(), pixels2.begin(), pixels2.end());
	pixels.insert(pixels.end(), pixels3.begin(), pixels3.end());
	pixels.insert(pixels.end(), pixels4.begin(), pixels4.end());
	pixels.insert(pixels.end(), pixels5.begin(), pixels5.end());
	pixels.insert(pixels.end(), pixels6.begin(), pixels6.end());
	double sum6 = std::accumulate(timeVector.begin(), timeVector.end(), 0);
	double average6 = sum6 / timeVector.size();
	double speedUp6 = average / average6;
	double efficiency6 = speedUp6 / 6;

	for (auto n : timeVector) {
		variance = n - average6;
		varianceSquared = variance * variance;
		varianceSum += varianceSquared;
	}

	standardDeviation = sqrt(varianceSum / timeVector.size());
	std::cout << "Average: " << average6 << " ms" << std::endl;
	std::cout << "Standard Deviation: " << standardDeviation << " ms" << std::endl;
	std::cout << "Speed Up: " << speedUp6 << std::endl;
	std::cout << "Efficiency: " << efficiency6 << std::endl;
	std::cout << std::endl;

	//reset variables for accurate standard deviation
	variance = 0;
	varianceSquared = 0;
	varianceSum = 0;
	standardDeviation = 0.0;

	std::cout << "7 Parallel Threads timing:" << std::endl;
	timeVector.clear();
	for (int x = 0; x < 5; x++) {
		auto startTime = std::chrono::steady_clock::now();
		pixels.clear();
		pixels2.clear();
		pixels3.clear();
		pixels4.clear();
		pixels5.clear();
		pixels6.clear();
		pixels7.clear();
		std::thread t1([&]() {drawMandelBrot(pixels, 0, imageHeight / 7); });
		std::thread t2([&]() {drawMandelBrot(pixels2, ((imageHeight / 7) + 1), (imageHeight / 7) * 2); });
		std::thread t3([&]() {drawMandelBrot(pixels3, (((imageHeight / 7) * 2) + 1), (imageHeight / 7) * 3); });
		std::thread t4([&]() {drawMandelBrot(pixels4, (((imageHeight / 7) * 3) + 1), (imageHeight / 7) * 4); });
		std::thread t5([&]() {drawMandelBrot(pixels5, (((imageHeight / 7) * 4) + 1), (imageHeight / 7) * 5); });
		std::thread t6([&]() {drawMandelBrot(pixels6, (((imageHeight / 7) * 5) + 1), (imageHeight / 7) * 6); });
		std::thread t7([&]() {drawMandelBrot(pixels7, (((imageHeight / 7) * 6) + 1), imageHeight); });
		t1.join();
		t2.join();
		t3.join();
		t4.join();
		t5.join();
		t6.join();
		t7.join();

		auto endTime = std::chrono::steady_clock::now();
		auto time = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
		std::cout << int(time.count()) << " ms" << std::endl;
		timeVector.push_back(int(time.count()));
	}

	pixels.insert(pixels.end(), pixels2.begin(), pixels2.end());
	pixels.insert(pixels.end(), pixels3.begin(), pixels3.end());
	pixels.insert(pixels.end(), pixels4.begin(), pixels4.end());
	pixels.insert(pixels.end(), pixels5.begin(), pixels5.end());
	pixels.insert(pixels.end(), pixels6.begin(), pixels6.end());
	pixels.insert(pixels.end(), pixels7.begin(), pixels7.end());
	double sum7 = std::accumulate(timeVector.begin(), timeVector.end(), 0);
	double average7 = sum7 / timeVector.size();
	double speedUp7 = average / average7;
	double efficiency7 = speedUp7 / 7;

	for (auto n : timeVector) {
		variance = n - average7;
		varianceSquared = variance * variance;
		varianceSum += varianceSquared;
	}

	standardDeviation = sqrt(varianceSum / timeVector.size());
	std::cout << "Average: " << average7 << " ms" << std::endl;
	std::cout << "Standard Deviation: " << standardDeviation << " ms" << std::endl;
	std::cout << "Speed Up: " << speedUp7 << std::endl;
	std::cout << "Efficiency: " << efficiency7 << std::endl;
	std::cout << std::endl;

	//reset variables for accurate standard deviation
	variance = 0;
	varianceSquared = 0;
	varianceSum = 0;
	standardDeviation = 0.0;

	std::cout << "8 Parallel Threads timing:" << std::endl;
	timeVector.clear();
	for (int x = 0; x < 5; x++) {
		auto startTime = std::chrono::steady_clock::now();
		pixels.clear();
		pixels2.clear();
		pixels3.clear();
		pixels4.clear();
		pixels5.clear();
		pixels6.clear();
		pixels7.clear();
		pixels8.clear();
		std::thread t1([&]() {drawMandelBrot(pixels, 0, imageHeight / 8); });
		std::thread t2([&]() {drawMandelBrot(pixels2, ((imageHeight / 8) + 1), imageHeight / 4); });
		std::thread t3([&]() {drawMandelBrot(pixels3, ((imageHeight / 4) + 1), (imageHeight / 8) * 3); });
		std::thread t4([&]() {drawMandelBrot(pixels4, (((imageHeight / 8) * 3) + 1), (imageHeight / 8) * 4); });
		std::thread t5([&]() {drawMandelBrot(pixels5, (((imageHeight / 8) * 4) + 1), (imageHeight / 8) * 5); });
		std::thread t6([&]() {drawMandelBrot(pixels6, (((imageHeight / 8) * 5) + 1), (imageHeight / 8) * 6); });
		std::thread t7([&]() {drawMandelBrot(pixels7, (((imageHeight / 8) * 6) + 1), (imageHeight / 8) * 7); });
		std::thread t8([&]() {drawMandelBrot(pixels8, (((imageHeight / 8) * 7) + 1), imageHeight); });
		t1.join();
		t2.join();
		t3.join();
		t4.join();
		t5.join();
		t6.join();
		t7.join();
		t8.join();

		auto endTime = std::chrono::steady_clock::now();
		auto time = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
		std::cout << int(time.count()) << " ms" << std::endl;
		timeVector.push_back(int(time.count()));
	}

	pixels.insert(pixels.end(), pixels2.begin(), pixels2.end());
	pixels.insert(pixels.end(), pixels3.begin(), pixels3.end());
	pixels.insert(pixels.end(), pixels4.begin(), pixels4.end());
	pixels.insert(pixels.end(), pixels5.begin(), pixels5.end());
	pixels.insert(pixels.end(), pixels6.begin(), pixels6.end());
	pixels.insert(pixels.end(), pixels7.begin(), pixels7.end());
	pixels.insert(pixels.end(), pixels8.begin(), pixels8.end());
	double sum8 = std::accumulate(timeVector.begin(), timeVector.end(), 0);
	double average8 = sum8 / timeVector.size();
	double speedUp8 = average / average8;
	double efficiency8 = speedUp8 / 8;

	for (auto n : timeVector) {
		variance = n - average8;
		varianceSquared = variance * variance;
		varianceSum += varianceSquared;
	}

	standardDeviation = sqrt(varianceSum / timeVector.size());
	std::cout << "Average: " << average8 << " ms" << std::endl;
	std::cout << "Standard Deviation: " << standardDeviation << " ms" << std::endl;
	std::cout << "Speed Up: " << speedUp8 << std::endl;
	std::cout << "Efficiency: " << efficiency8 << std::endl;
	std::cout << std::endl;
	std::cout << "Please wait: Writing to file" << std::endl;
	
	for (auto n : pixels) {
		fout << std::get<0>(n) << " " << std::get<1>(n) << " " << std::get<2>(n) << " ";
	}
	fout.close();

	std::cout << "Finished writing to file!" << std::endl;
	return 0;
}