Esempio n. 1
0
 void splay(int rt)
 {
  for(int x = rt;!isrt(x);)
  {
   int y = t[x].F;
   int z = t[y].F;
   if(!isrt(y) && (t[z].R == y)==(t[y].R == x))
    rotate(y);
   rotate(x);
  }
  update(rt);
 }
Esempio n. 2
0
void splay(int p)
{
	int pt;tops=0;
	for(pt=p;!isrt(pt);pt=fa[pt]) stk[++tops]=pt;
	stk[++tops]=pt;
	for(pt=tops;pt>0;pt--) pushdown(stk[pt]);
	while(!isrt(p))
	{
		if(!isrt(fa[p]))
			getd(p)==getd(fa[p])? rotate(fa[p]): rotate(p);
		rotate(p);
	}
	update(p);
}
Esempio n. 3
0
 void splay(int x)
 {
  while(!isrt(x))
  {
   int y = ch[x][F];
   if(!isrt(y)){
   int z = ch[y][F];
   int d1 = ((ch[z][0]==y)==(ch[y][0]==x));
   if(d1) rotate(y);
   }
   rotate(x);
  }
  update(x);
 }
Esempio n. 4
0
void UninstallProcess::run()
{
	if (m_szIPath == "" || m_szMCFPath == "")
	{
		gcException errPathNull(ERR_BADPATH, gcString("One of the paths for uninstall was nullptr [IP: {0} MCF: {1}].", m_szIPath, m_szMCFPath));
		onErrorEvent(errPathNull);
		return;
	}

	MCFCore::MCFI *mcfHandle = mcfFactory();
	m_pMcfHandle = mcfHandle;
	mcfHandle->getErrorEvent() += delegate(&onErrorEvent);
	mcfHandle->getProgEvent() += delegate(this, &UninstallProcess::onProgress);

	InstallScriptRunTime isrt(m_szInstallScript.c_str(), m_szIPath.c_str());

	try
	{
		mcfHandle->setFile(m_szMCFPath.c_str());
		mcfHandle->parseMCF();

		isrt.run("PreUninstall");
		mcfHandle->removeFiles(m_szIPath.c_str());
		isrt.run("PostUninstall");
	}
	catch (gcException &except)
	{
		onErrorEvent(except);
	}

	m_pMcfHandle=nullptr;
	mcfDelFactory(mcfHandle);

	onCompleteEvent();
}
Esempio n. 5
0
void rotate(int p)
{
	int d=getd(p),Fa=fa[p];
	isrt(Fa)? (void)(fa[p]=fa[Fa]): sets(getd(Fa),p,fa[Fa]);
	sets(d,son[p][d^1],Fa);
	sets(d^1,Fa,p);
	update(Fa);
}
Esempio n. 6
0
 void rotate(int x)
 {
  int y = ch[x][F],z = ch[y][F],d1 = (ch[y][0]==x),d2 = (ch[z][1] == y) ,d3 = isrt(y);
  ch[y][!d1] = ch[x][d1],ch[ch[y][!d1]][F]= y;
  ch[x][d1] = y;ch[y][F]=x;
  if(!d3) ch[z][d2]= x;
  ch[x][F]=z;
  update(y);update(x);
 }
Esempio n. 7
0
 void rotate(int x)
 {
  int y = t[x].F;
  int z = t[y].F;
  int d1 = (t[y].L==x);
  int d2 = (t[z].R==y);
  int d3 = isrt(y);
  t[y].C[!d1] = t[x].C[d1];t[t[y].C[!d1]].F = y;
  t[x].C[d1] = y;t[y].F = x;
  if(!d3) t[z].C[d2] = x;
  t[x].F = z;
  update(y);update(x);
 }
Esempio n. 8
0
/* this is a recursive routine.                  */
int isrt(treefmt *node, double key)
   {
   int rslt;
   treefmt *newnode;
   if (key < node->key)
      {
      if (node->left != NULL)
	 {
         rslt = isrt(node->left, key);
	 return(rslt);
	 } /* not leaf node left */
      else
         {
	 newnode = (treefmt *) inittree();
	 newnode->key = key;
	 node->left = (treefmt *) newnode;
	 return(0);
	 } /* else leaf node less than */
      } /* key less than */
   else if (key > node->key)
      {
      if (node->rght != NULL)
	 {
         rslt = isrt(node->rght, key);
	 return(rslt);
	 } /* not leaf node rght */
      else
         {
	 newnode = (treefmt *) inittree();
	 newnode->key = key;
	 node->rght = (treefmt *) newnode;
	 return(0);
	 } /* else leaf node greater than */
      } /* key greater than */
   return(-1);   /* duplicate key */
   } /* isrt */
Esempio n. 9
0
int main(int argc, char **argv)
   {
   int sz;                  /* number of normal numbers to produce */
   unsigned int i;          /* loop countedr                       */
   double mean;             /* mean of the normal distribution     */
   double stdev;            /* standard deviation                  */
   rufmt *ru;               /* erandu structure                    */
   actfmt *aa;              /* Box-Muller transform structure      */
   treefmt *root;           /* root node of the tree               */
   if (argc != 4) putstx(*argv);       /* must have 3 arguments    */
   mean = atof(*(argv+1));             /* sample mean              */
   if (mean < -1000.0)
      {
      fprintf(stderr,"Mean parameter %s "
         "is too small\n", *(argv+1));
      putstx(*argv);
      exit(1);
      } /* mean too small */
   if (mean > 1000.0)
      {
      fprintf(stderr,"Mean parameter %s "
         "is too large\n", *(argv+1));
      putstx(*argv);
      exit(1);
      } /* mean too large */
   stdev = atof(*(argv+2));            /* standard deviation */
   if (stdev < 0)
      {
      fprintf(stderr,"Stdev parameter %s "
         "is too small\n", *(argv+2));
      putstx(*argv);
      exit(1);
      } /* stdev too small */
   if (stdev > 1000)
      {
      fprintf(stderr,"Stdev parameter %s "
         "is too large\n", *(argv+2));
      putstx(*argv);
      exit(1);
      } /* stdev too large */
   sz = atoi(*(argv+3));                 /* population size */
   if (sz < 36)
      {
      fprintf(stderr,"Size parameter %s "
         "is too small\n", *(argv+3));
      putstx(*argv);
      exit(1);
      } /* sz too small */
   if (sz > 100000)
      {
      fprintf(stderr,"Size parameter %s "
         "is too large\n", *(argv+3));
      putstx(*argv);
      exit(1);
      } /* sz too large */
   ru = (rufmt *) eranduinit();   /* initialize erandu to date/time */
   /* allocate memory for the actual sample structure */
   aa = (actfmt *) malloc(sizeof(actfmt));
   if (aa == NULL)
      {
      fprintf(stderr,"main: out of memory "
         "allocating the aa structure\n");
      exit(1);
      } /* out of memory */
   root    = (treefmt *) inittree();
   /**********************************/
   /* create n samples               */
   /**********************************/
   i = sz >> 1;
   while (i--)
      {
      boxmul(ru,mean,stdev,aa);        /* Box-Muller Transform */
      /* the Box-Muller Transform gives two numbers n1 and n2  */
      /* tally by number to create histogram                   */
      isrt(root,aa->n1);      /* insert n1 into the tree       */
      isrt(root,aa->n2);      /* insert n2 into the tree       */
      } /* for each sample */
   /**********************************/
   /* traverse tree                  */
   /**********************************/
   if (root->rght != NULL) traverse(root->rght);
   /************************************************************/
   /* free memory                                              */
   /************************************************************/
   if (root->rght != NULL) rmtree(root->rght);
   free(root);
   free(aa);
   free(ru->state);
   free(ru);
   return(0);
   } /* main */