Beispiel #1
0
static void sink4(const int size, int *a, const int n)
{
	//fprintf(stderr,"sink4\n");
	int *pt = a+n;
	int *c1 = a+4*n+1;
	int *c2 = a+4*n+2;
	int *c3 = a+4*n+3;
	int *c4 = a+4*n+4;
	if (4*n+1>=size)
		return;
	else if (4*n+2==size) {
		if (*c1>*pt) {
			swp(pt,c1);
			sink4(size,a,4*n+1); 
		}
	} else if (4*n+3==size) {
		if (*c1>*pt && *c1>*c2) {
			swp(pt,c1);
			sink4(size,a,4*n+1);
		} else if (*c2>*pt && *c2>*c1) {
			swp(pt,c2);
			sink4(size,a,4*n+2);
		}
	} else if (4*n+4==size) { 
		if (*c1>*pt && *c1>*c2 && *c1>*c3) {
			swp(pt,c1);
			sink4(size,a,4*n+1);
		} else if (*c2>*pt && *c2>*c1 && *c2>*c3) {
			swp(pt,c2);
			sink4(size,a,4*n+2);
		} else if (*c3>*pt && *c3>*c1 && *c3>*c2) {
			swp(pt,c3);
			sink4(size,a,4*n+3);
		}
	} else { 
		if (*c1>*pt && *c1>*c2 && *c1>*c3 && *c1>*c4) {
			swp(pt,c1);
			sink4(size,a,4*n+1);
		} else if (*c2>*pt && *c2>*c1 && *c2>*c3 && *c2>*c4) {
			swp(pt,c2);
			sink4(size,a,4*n+2);
		} else if (*c3>*pt && *c3>*c1 && *c3>*c2 && *c3>*c4) {
			swp(pt,c3);
			sink4(size,a,4*n+3);
		} else if (*c4>*pt && *c4>*c1 && *c4>*c2 && *c4>*c3) {
			swp(pt,c4);
			sink4(size,a,4*n+4);
		}
	}
}
void CCmdTestSsmCommand::CreateAndExecuteCmd(TSwpBuiltInCmdValues aCmdValue)
	{
	TInt err = RProperty::Define(KMySID, 0, RProperty::EInt);
	RDebug::Print(_L(" CCmdTestSsmCommand::CreateAndExecuteCmd RProperty::Define %d"), err);

	RSsmStateManager sess;
	err = sess.Connect();
	RDebug::Print(_L("RSsmStateManager sess connect %d"), err);

	err = sess.RegisterSwpMapping(KSwpTestKey1, KTestSwpPolicyCmd);
	TSsmSwp swp(KSwpTestKey1,0);

	swp.Set(KSwpTestKey1, aCmdValue);		
	RSsmSystemWideProperty property;
	err = property.Connect(KSwpTestKey1);
	RDebug::Print(_L("RSsmStateManager RSsmSystemWideProperty Connect %d"), err);
	sess.RequestSwpChange(swp, iStatus);
	User::WaitForRequest(iStatus);
	// Wait for 0.5 sec to allow transitions to fully complete
	User::After(5000000);		
	TEST(KErrNone == iStatus.Int());
	//Find any instances of running process started by this test and kill them
	TInt instances = 0;
	if(aCmdValue == ESwpStartProcWFS || aCmdValue == ESwpStartProcDWFS || aCmdValue == ESwpStartProcFAF )
		{
		instances = FindAndKill(KTestProcGood);
		INFO_PRINTF2(_L("Instances of KTestProcGood found was '%d'."), instances);
		}
	else
		{
		instances = FindAndKill(KGoodApp);
		INFO_PRINTF2(_L("Instances of KGoodApp found was '%d'."), instances);
		}	
	TEST(instances==1);
	}
Beispiel #3
0
 boost::shared_ptr<FixedFloatSwap> create(Date settle, 
                                          Date maturity, 
                                          Rate fixedRate,
                                          SwapPayType payerType = FixedPayer,
                                          Spread floating_spread = 0.0,
                                          Real notional = 1000000.0,
                                          Date eval_date=Date()
                                          )
 {
     boost::shared_ptr<IborIndex> iborIdx = _indexBase();
 
     boost::shared_ptr<FixedFloatSwap> swp(new FixedFloatSwap(settle,
                                                              maturity,
                                                              fixedRate,
                                                              iborIdx,
                                                              payerType,
                                                              floating_spread,
                                                              notional,
                                                              _fixedLegFrequency,
                                                              _fixedLegDayCounter,
                                                              _fixedLegConvention,
                                                              _floatingLegFrequency,
                                                              _floatingLegDayCounter,
                                                              _floatingLegConvention,
                                                              _calendar,
                                                              eval_date));
     return swp;
 }
	void revstr(string s)
	{
		int l = s.length();
		int f = 0;
		int r = l - 1;
		int fc=-1, rc=-1;
		while (true)
		{
			if (f >= r)
				break;
			if ((s[f] >= 'a' && s[f] <= 'z') || (s[f] >= 'A' && s[f] <= 'Z'))
			{
				fc = f;
			}
			if ((s[r] >= 'a' && s[r] <= 'z') || ( s[r] >= 'A'&& s[r] <= 'Z'))
			{
				rc = r;
			}
			if (fc >= 0 && rc >= 0)
			{
				swp(s[f], s[r]);
				fc = -1;
				rc = -1;
				f++;
				r--;
				continue;
			}
			// Ab,c,de!$
			if (fc < 0)
				f++;
			if (rc < 0)
				r--;
		}
		cout << s;
	}
void CCmdTestSsmCommand::CreateAndExecuteCancelCmd1(TSwpBuiltInCmdValues aCmdValue)
	{
	TInt err = RProperty::Define(KMySID, 0, RProperty::EInt);
	RDebug::Print(_L(" CCmdTestSsmCommand::CreateAndExecuteCancelCmd1 RProperty::Define %d"), err);

	RSsmStateManager sess;
	err = sess.Connect();
	RDebug::Print(_L("RSsmStateManager sess connect %d"), err);

	err = sess.RegisterSwpMapping(KSwpTestKey1, KTestSwpPolicyCmd);
	TSsmSwp swp(KSwpTestKey1,0);

	swp.Set(KSwpTestKey1, aCmdValue);

	RSsmSystemWideProperty property;
	err = property.Connect(KSwpTestKey1);
	RDebug::Print(_L("RSsmStateManager RSsmSystemWideProperty Connect %d"), err);

	//Transition engine will not cancel any request that is currently in execution. It will delete only quad request.
	sess.RequestSwpChange(swp, iStatus);		
	sess.RequestSwpChange(swp, iCancelReqStatus);			

	TEST(iStatus == KRequestPending);
	User::WaitForRequest(iStatus);
	
	sess.RequestSwpChangeCancel();
	User::WaitForRequest(iCancelReqStatus);
	
	TEST(KErrNone == iStatus.Int());	
	TEST(KErrCancel == iCancelReqStatus.Int());
	RDebug::Print(_L("CreateAndExecuteCancelCmd1 completes with %d err"),iCancelReqStatus.Int());
	}
 void sink(int i) {
   while (true) {
     int l = 2*i + 1, r = l + 1;
     if (l >= count) break;
     int m = r >= count || cmp(l, r) ? l : r;
     if (!cmp(m, i)) break;
     swp(m, i), i = m; } }
Beispiel #7
0
int main()
{
    int cups[3] = {1, 0, 0};
    unsigned char a, b;
    while(~scanf("%c,%c\n", &a, &b)) {
        swp(cups[a - 'A'], cups[b - 'A']);
    }
    printf("%c\n", cups[0] * 'A' + cups[1] * 'B' + cups[2] * 'C');
    return 0;
}
Beispiel #8
0
macro Formula operator && (Formula f, Formula g)
{
    if      (f == _0_ || g == _0_) return _0_;
    else if (f == _1_)             return g;
    else if (g == _1_)             return f;
    else if (f ==  g )             return f;
    else if (f == ~g )             return _0_;

    if (g < f) swp(f, g);
    return Bin_new(op_And, f, g);
}
	void rec(char* s, int n, int c)
	{
		if (c >= n - 1 && isBalanced(s,n) && !isPresent(s,n))
		{
			insertSet(s, n);
			for (int i = 0; i < n; i++)
			{
				cout << s[i];
			}
			cout << endl;
			return;
		}

		for (int i = c; i < n; i++)
		{
			swp(s[i], s[c]);
			rec(s, n, c + 1);
			swp(s[i], s[c]);
		}
	}
Beispiel #10
0
static void sink3(const int size, int *a, const int n)
{
	//fprintf(stderr,"sink3\n");
	int *pt = a+n;
	int *c1 = a+3*n+1;
	int *c2 = a+3*n+2;
	int *c3 = a+3*n+3;
	if (3*n+1>=size)
		return;
	else if (3*n+2==size) {
		if (*c1>*pt) {
			swp(pt,c1);
			sink3(size,a,3*n+1); 
		}
	} else if (3*n+3==size) {
		if (*c1>*pt && *c1>*c2) {
			swp(pt,c1);
			sink3(size,a,3*n+1);
		} else if (*c2>*pt && *c2>*c1) {
			swp(pt,c2);
			sink3(size,a,3*n+2);
		}
	} else { 
		if (*c1>*pt && *c1>*c2 && *c1>*c3) {
			swp(pt,c1);
			sink3(size,a,3*n+1);
		} else if (*c2>*pt && *c2>*c1 && *c2>*c3) {
			swp(pt,c2);
			sink3(size,a,3*n+2);
		} else if (*c3>*pt && *c3>*c1 && *c3>*c2) {
			swp(pt,c3);
			sink3(size,a,3*n+3);
		}
	}
}
Beispiel #11
0
int main(int argc, const char *argv[])
{
    int a = 5;
    int b = 6;

    swp(a, b);
    printf("swp:a = %d, b = %d\n", a, b);

    swap(&a, &b);
    printf("swap:a = %d, b = %d\n", a, b);

    return 0;
}
Beispiel #12
0
static void sink2(const int size, int *a, const int n)
{
	//fprintf(stderr,"sink2\n");
	int *pt = a+n;
	int *c1 = a+2*n+1;
	int *c2 = a+2*n+2;
	if (2*n+1>=size)
		return;
	else if (2*n+2==size) {
		if (*c1>*pt) {
			swp(pt,c1);
			sink2(size,a,2*n+1); 
		}
	} else {
		if (*c1>*pt && *c1>*c2) {
			swp(pt,c1);
			sink2(size,a,2*n+1);
		} else if (*c2>*pt && *c2>*c1) {
			swp(pt,c2);
			sink2(size,a,2*n+2);
		}
	}
}
Beispiel #13
0
void quicksort (float* arr, int size)
{
  if (size <= 1) return;
  else{
    int pivot = selectPivot (arr, size);
    swp (arr[size-1], arr[pivot]);
    pivot = size-1;
    
    // put all values less than the pivot value after the pivot
    for (int i=0; i < pivot;){
      if ( (arr[i] < arr[pivot]) ){
        swp (arr[i], arr[pivot-1]);
        swp (arr[pivot-1], arr[pivot]);
        pivot--;
      }
      else{
        i++;
      }
    }
    quicksort (arr, pivot);
    quicksort (arr+pivot, size-pivot);
  }
}
void CTestExecuteCustCmd::CreateAndExecuteCustCmd(TInt aSwpVal)
	{
	INFO_PRINTF1(_L("CreateAndExecuteCustCmd"));
	
	RSsmStateManager client;
	const TInt connect = client.Connect();
	TEST(KErrNone == connect);

	// Create SwP
	INFO_PRINTF1(_L("Creating swp..."));
	TSsmSwp swp(KTestSwp, aSwpVal);
	RProperty property;
	TEST(KErrNone == property.Define(KCustomcmdServerSID, swp.Key(), RProperty::EInt));
	TEST(KErrNone == property.Set(KCustomcmdServerSID, swp.Key(), swp.Value()));
	
	//Ensure the environment is clean
	TInt value = 0;
	TEST(KErrNone == property.Get(KCustomcmdServerSID, swp.Key(), value));
	TESTE(aSwpVal == value, value);

	// Register mapping between keys and swp policy DLL (done once per ssmserver)
	client.RegisterSwpMapping(KTestSwp, KTestSwpPolicyCustomCmd);
	
	//Let client request swp changes
	INFO_PRINTF1(_L("Request swp change"));
	swp.Set(KTestSwp, -99);
	TRequestStatus status;
	client.RequestSwpChange(swp, status);				
	TEST(status == KRequestPending);
	User::WaitForRequest(status);
	TEST(status.Int() == KErrNone);	
    
	RSsmSystemWideProperty swpClient;
	//Connect to the swp.
	TInt err = swpClient.Connect(swp.Key());
	TEST(KErrNone == err);
	swpClient.Subscribe(iSwpStatus);
	User::WaitForRequest(iSwpStatus);
	TEST(KErrNone == property.Get(KCustomcmdServerSID, swp.Key(), value));
	// clean-up
	swpClient.Close();
	TEST(KErrNone == property.Delete(KCustomcmdServerSID, swp.Key()));
	TESTE(99 != value, value);
	property.Close();
	client.Close();
	INFO_PRINTF1(_L("CreateAndExecuteCustCmd completed"));
	}	
Beispiel #15
0
	void getPermutation_aux(int index,int k,vector<int>& permu,
		vector<int>& nums){
			int size=nums.size();
			if(k==0)
				return ;
			if(k==1){
				swp(nums,size-2,size-1);
				return ;
			}
			int leftPos=nums.size()-1-index;
			int mov=k/permu[leftPos-1];
			int left=k%permu[leftPos-1];
			int tmp=nums[index+mov];
			for(int i=index+mov;i>index;i--)
				nums[i]=nums[i-1];
			nums[index]=tmp;
			getPermutation_aux(index+1,left,permu,nums);
	}
Beispiel #16
0
void merge(int s, int e,int l)
{
	int i,m,ca,cb,a,b,pt,c;
	if(s>=e||l==1) return;
	else if(e-s==1) {if(dat[s]>dat[e]) swp(s,e); return;}
	else
	{
		if(l%2!=0) c=1; else c=0;
		merge(s,s+(l/2)-1+c,(l/2)+c); merge(s+(l/2)+c,e,l/2);
		ca=s; cb=s+(l/2)+c; a=0; b=0; pt=0;
		for(i=0;i<l;i++)
		{
			if(dat[ca]<=dat[cb]&&a<(l/2)+c||b>=l/2) {temp[pt]=dat[ca]; ca++; a++; pt++;}
			else if(dat[cb]<dat[ca]&&b<l/2||a>=(l/2)+c) {temp[pt]=dat[cb]; cb++; b++; pt++;}
		}
		for(i=0;i<l;i++) dat[s+i]=temp[i];
	}
}
Beispiel #17
0
void heapsort4(int size, int *a)
{
	fprintf(stderr,"heapsort4\n");

	if (!size) return;

	swp_count=0;

	crtheap4(size,a); 

	do {
		fprintf(stderr,"pop\n");
		swp(a,a+size-1);
		sink4(size-1,a,0);
	}
	while (--size>0);

	fprintf(stderr,"swp_count=%d\n",swp_count);

	return;
}
void CCmdTestSsmCommand::CreateAndExecuteCmd1(TSwpBuiltInCmdValues aCmdValue)	
	{
	TInt err = RProperty::Define(KMySID, 0, RProperty::EInt);
	RDebug::Print(_L("RProperty::Define completed with %d"), err);
	RSsmStateManager sess;
	err = sess.Connect();
	RDebug::Print(_L("RSsmStateManager sess connect %d"), err);

	err = sess.RegisterSwpMapping(KSwpTestKey1, KTestSwpPolicyCmd);
	TSsmSwp swp(KSwpTestKey1,0);

	swp.Set(KSwpTestKey1, aCmdValue);		
	RSsmSystemWideProperty property;
	err = property.Connect(KSwpTestKey1);
	RDebug::Print(_L("RSsmStateManager RSsmSystemWideProperty Connect %d"), err);
	sess.RequestSwpChange(swp, iStatus);
	User::WaitForRequest(iStatus);
	User::After(5000000);		
	
	TEST(KErrNone == iStatus.Int());	
	}
 void heapify() { for (int i = count - 1; i > 0; i--)
   if (cmp(i, (i - 1) / 2)) swp(i, (i - 1) / 2); }
 void swim(int i) {
   while (i > 0) {
     int p = (i - 1) / 2;
     if (!cmp(i, p)) break;
     swp(i, p), i = p; } }