Beispiel #1
0
Boolean BtreeFlush::FindObjInFlush(IObjToFlush *obj2)
{
	BtreeFlush *sousbt;
	IObjToFlush *obj;
	sLONG i;
	Boolean res = false;

	if (!occupe())
	{
		sousbt=tabsous[0];
		if (sousbt!=nil)
		{
			res = res || sousbt->FindObjInFlush(obj2);
		}

		for (i=0;i<nkeys;i++)
		{
			obj=tabmem[i];
			sousbt=tabsous[i+1];
			if (obj==obj2)
			{
				assert(false);
				res = true;
			}
			if (sousbt!=nil)
			{
				res = res || sousbt->FindObjInFlush(obj2);
			}
		}
		libere();
	}

	return res;
}
Beispiel #2
0
void BtreeFlush::CheckDuplicatesInFlush()
{
	BtreeFlush *sousbt;
	IObjToFlush *obj;
	sLONG i;

	if (!occupe())
	{

		for (i=0;i<nkeys;i++)
		{
			obj=tabmem[i];
			if (obj!=nil)
			{
				assert (obj->getaddr() >= 0);
			}
		}

		for (i=0;i<=nkeys;i++)
		{
			sousbt = tabsous[i];
			if (sousbt!=nil)
				sousbt->CheckDuplicatesInFlush();
		}

		libere();
	}
}
Beispiel #3
0
sLONG BtreeFlush::CompteObjOccurence(IObjToFlush *obj2)
{
	BtreeFlush *sousbt;
	IObjToFlush *obj;
	sLONG i;
	sLONG res = 0;

	if (!occupe())
	{
		sousbt=tabsous[0];
		if (sousbt!=nil)
		{
			res = res + sousbt->CompteObjOccurence(obj2);
		}

		for (i=0;i<nkeys;i++)
		{
			obj=tabmem[i];
			sousbt=tabsous[i+1];
			if (obj==obj2)
			{
				res++;
			}
			if (sousbt!=nil)
			{
				res = res + sousbt->CompteObjOccurence(obj2);
			}
		}
		libere();
	}

	return res;
}
Beispiel #4
0
void execute_ligne_commande(){
  int flag;
  int nb;
  char *** result = ligne_commande(&flag,&nb);
  if(result != NULL){
    char ** argv = result[0];
    if(strcmp(argv[0],"exit")==0)
      exit(1);
    affiche(result);
    int f;
    if((f=fork())==0){
      execvp(argv[0],argv);
      perror("execvp");
      exit(1);
    }
    int status;
    if(flag == 0){
      printf("bloquant\n");
      waitpid(f,&status,0);
    } else {
      printf("non bloquant\n");
      waitpid(f,&status,WNOHANG);
    }

    libere(result);
  }
}
Beispiel #5
0
/* ---------------------------------------------------------------------- */
int main()
{
  Noeud* rezo[] = {
    creation(192, 168,  1, 1),
    creation(192, 168,  1, 2),
    creation(192, 168,  1, 3),
    creation(192, 168, 10, 1),
    creation(192, 168, 10, 2),
    creation(192, 168, 20, 1),
    creation(192, 168, 20, 2)
  };
 
  for (size_t i = 0 ; i < sizeof(rezo) / sizeof(rezo[0]); ++i) {
    if (NULL == rezo[i]) {
      fprintf(stderr, "pas assez de mémoire\n");
      exit(-1);
    }
  }    
 
  sont_voisins(rezo[0], rezo[1]);
  sont_voisins(rezo[0], rezo[2]);
 
  sont_voisins(rezo[1], rezo[2]);
  sont_voisins(rezo[1], rezo[3]);
  sont_voisins(rezo[1], rezo[5]);
 
  sont_voisins(rezo[2], rezo[3]);
  sont_voisins(rezo[2], rezo[5]);
 
  sont_voisins(rezo[3], rezo[4]);
  sont_voisins(rezo[3], rezo[5]);
 
  sont_voisins(rezo[5], rezo[6]);
 
  affiche(rezo[3]);
 
  affiche_simple(rezo[0]);
  printf(" et ");
  affiche_simple(rezo[5]);
  printf(" ont %u voisins communs.\n", voisins_communs(rezo[0], rezo[5]));
 
  affiche_simple(rezo[1]);
  printf(" et ");
  affiche_simple(rezo[2]);
  printf(" ont %u voisins communs.\n", voisins_communs(rezo[1], rezo[2]));
 
  /* garbage collecting */
  for (size_t i = 0 ; i < sizeof(rezo) / sizeof(rezo[0]); ++i) {
    libere(rezo[i]);
  }
  return 0;
}
Beispiel #6
0
int main(int argc, char** argv) { char s[512];
    double xmin=-5, xmax=5;
    ARBRE r=NULL;
    int dx=400,dy=200;
    SDL_Surface* f1;

    /* 
       Creation d'une fenetre graphique
       */
    f1=newfenetregraphique(dx,dy);
    Draw_Line(f1,0, 10, 200, 50,0xFFFFFFFF);
    /*
       Lecture d'une expression prefixe au clavier 
       */
    puts("Entrer une expression en notation prefixee"); gets(s);
    r=lire(s);

    /*
       Affichage de cette expression en notation classique
       */
    puts("Expression :"); affiche(r); puts("");


    puts("Entrer les bornes du trace (xmin et xmax): attention au domaine de definition");
    scanf("%lf %lf",&xmin,&xmax);

    /*
       Recherche du min et du max des ordonnees du graphe de la fonction 
       */
    trace1courbe(f1,r,dx,xmin,xmax);
    getchar(); getchar();

    /*
       Liberation de la memoire de l'arbre
       */
    r=libere(r);
    return 0;
}
Beispiel #7
0
Boolean BtreeFlush::FindObjInFlushByAddr( DataAddr4D addr)
{
	BtreeFlush *sousbt;
	IObjToFlush *obj;
	sLONG i;
	Boolean res = false;

	if (!occupe())
	{
		sousbt=tabsous[0];
		if (sousbt!=nil)
		{
			res = res || sousbt->FindObjInFlushByAddr(addr);
		}

		for (i=0;i<nkeys;i++)
		{
			obj=tabmem[i];
			sousbt=tabsous[i+1];
			if (obj!=nil)
			{
				if (obj->getaddr() == addr)
				{
					assert(false);
					res = true;
				}
			}
			if (sousbt!=nil)
			{
				res = res || sousbt->FindObjInFlushByAddr(addr);
			}
		}
		libere();
	}

	return res;
}
Beispiel #8
0
void execute_ligne_commande(){
	int nb,flag, status, pid;
	char *** cmd = ligne_commande(&flag, &nb);
	if(cmd == NULL)
		return;
	if(flag==-1)
		perror(cmd[0][0]);
		
	if(strcmp(cmd[0][0], "exit")==0)
		exit(1);
	if((pid=fork()) == 0)
	{
		execvp(cmd[0][0], cmd[0]);
		perror(cmd[0][0]);
		exit(-1);
	}
	else if(flag != 1)
	{
		pid = waitpid(pid, &status,0);
		if(pid == -1)
			perror("waitpid error");
	}
	libere(cmd);
}
Beispiel #9
0
/*
  Fonction qui libere la memoire alloue pour un arbre
*/
ARBRE libere(ARBRE r) { 
  if (r!=NULL) { libere(r->fg); libere(r->fd); free(r->val); r->val=NULL; r->fg=r->fd=NULL; free(r); return NULL;}
}
Beispiel #10
0
Boolean BtreeFlush::search(uBOOL *h, BTitemFlush *v, uBOOL pourdelete)
{
	BtreeFlush *sousBT;
	sLONG l,k,r,i;
	uBOOL isegal;
	IObjToFlush* obj2,*obj;
	BTitemFlush u;
	BtreeFlush **p,**pb;
	IObjToFlush  **p2,**p2b;
	DataAddr4D  *p3,*p3b;
	Boolean res = false;
	StAllocateInCache alloc;
	CompareResult comp;

	occupe(true);
	l=1;
	r=nkeys;
	isegal=false;
	obj=v->obj;

	while ( (!isegal) && (r>=l) )
	{
		k=(r+l)>>1;
		obj2=tabmem[k-1];
		if (obj2==obj)
		{
			isegal=true;
			res = true;
			if (pourdelete)
			{
				oldaddr[k-1]=obj->getaddr();
				tabmem[k-1]=nil;
				obj->Release();
				VInterlocked::Decrement(&sGlobalNbFlushObjects);
			}
		}
		else
		{
			if (obj2==nil)
			{
				comp = obj->CompAddr(oldaddr[k-1]);
			}
			else
			{
				comp = obj->CompAddr(obj2);
			}

			if (comp == CR_EQUAL)
			{
				if (pourdelete)
				{
					Boolean jusquaubout = true;
					for (sLONG ik = l; ik <= r; ik++)
					{
						if (tabmem[ik-1] == obj)
						{
							isegal = true;
							res = true;
							oldaddr[ik-1]=obj->getaddr();
							VInterlocked::Decrement(&sGlobalNbFlushObjects);
							tabmem[ik-1] = nil;
							jusquaubout = false;
							obj->Release();
							break;
						}
						else
						{
							CompareResult comp2;
							if (tabmem[ik-1] == nil)
								comp2 = obj->CompAddr(oldaddr[ik-1]);
							else
								comp2 = obj->CompAddr(tabmem[ik-1]);

							if (comp2 == CR_EQUAL)
							{
								sousBT = tabsous[ik-1];
								if (sousBT != nil )
								{
									u=*v;
									res = res || sousBT->search(h,&u,pourdelete);
									if (res)
									{
										isegal = true;
										jusquaubout = false;
									}
								}
							}
							else
							{
								jusquaubout = false;
								break;
							}
						}
					}
					if (jusquaubout)
					{
						sousBT=tabsous[r];
						if (sousBT!=nil)
						{
							u=*v;
							res = res || sousBT->search(h,&u,pourdelete);
							if (res)
								isegal = true;
						}
					}
				}
				else
				{
					if (obj2 == nil)
					{
						tabmem[k-1] = obj;
						isegal = true;
						VInterlocked::Increment(&sGlobalNbFlushObjects);
					}
				}
			}

			if (!isegal)
			{
				if (comp == CR_BIGGER)
				{
					l=k+1;
				}
				else
				{
					r=k-1;
				}
			}
		}
	}

	if (isegal)
	{
		l=l; /* ne sert a rien mais permet un break point */
	}
	else
	{
		sousBT=tabsous[r];
		if (sousBT!=nil)
		{
			u=*v;
			/*/ ?? faut il remettre u.sousBT a nil */
			res = res || sousBT->search(h,&u,pourdelete);
		}
		else
		{
			if (!pourdelete)
				VInterlocked::Increment(&sGlobalNbFlushObjects);
			*h=true;
			u=*v;
		}
		if (*h && !pourdelete)
		{
			if (nkeys<32)
			{
				*h=false;
				p=tabsous+nkeys+1;
				p2=tabmem+nkeys;
				p3=oldaddr+nkeys;
				for (i=r;i<nkeys;i++)
				{
					*p=*(p-1);
					p--;
					*p2=*(p2-1);
					--p2;
					*p3=*(p3-1);
					--p3;
				}
				tabsous[r+1]=u.sousBT;
				tabmem[r]=u.obj;
				oldaddr[r]=u.addr;
				//if (u.obj != nil) u.obj->SetTransOwner(u.owner);
				nkeys++;
			}
			else
			{
				sousBT=BtreeFlush::GetNewBtreeFlush();
				if (r<=16)
				{
					if (r==16)
					{
						*v=u;
					}
					else
					{
						v->addr=oldaddr[15];
						v->obj=tabmem[15];
						v->sousBT=tabsous[16];
						//if (v->obj != nil) v->owner = v->obj->GetTransOwner();
						p=tabsous+16;
						p2=tabmem+15;
						p3=oldaddr+15;

						for (i=r+1;i<16;i++)
						{
							*p=*(p-1);
							p--;
							*p2=*(p2-1);
							--p2;
							*p3=*(p3-1);
							--p3;
						}

						tabsous[r+1]=u.sousBT;
						tabmem[r]=u.obj;
						oldaddr[r]=u.addr;
						//if (u.obj != nil) u.obj->SetTransOwner(u.owner);
					}

					p=tabsous+17;
					p2=tabmem+16;
					p3=oldaddr+16;
					pb=sousBT->tabsous+1;
					p2b=sousBT->tabmem;
					p3b=sousBT->oldaddr;
					for (i=1;i<=16;i++)
					{
						*pb++=*p++;
						*p2b++=*p2++;
						*p3b++=*p3++;
					}
				}
				else
				{
					r=r-16;
					v->obj=tabmem[16];
					v->addr=oldaddr[16];
					v->sousBT=tabsous[17];
					//if (v->obj != nil) v->owner = v->obj->GetTransOwner();

					p=tabsous+18;
					p2=tabmem+17;
					p3=oldaddr+17;
					pb=sousBT->tabsous+1;
					p2b=sousBT->tabmem;
					p3b=sousBT->oldaddr;
					for (i=1;i<r;i++)
					{
						*pb++=*p++;
						*p2b++=*p2++;
						*p3b++=*p3++;
					}

					sousBT->tabsous[r]=u.sousBT;
					sousBT->tabmem[r-1]=u.obj;
					sousBT->oldaddr[r-1]=u.addr;
					//if (u.obj != nil) u.obj->SetTransOwner(u.owner);

					p=tabsous+16+r+1;
					p2=tabmem+16+r;
					p3=oldaddr+16+r;
					pb=sousBT->tabsous+1+r;
					p2b=sousBT->tabmem+r;
					p3b=sousBT->oldaddr+r;
					for (i=r+1;i<=16;i++)
					{
						*pb++=*p++;
						*p2b++=*p2++;
						*p3b++=*p3++;
					}
				}

				nkeys=16;
				sousBT->nkeys=16;
				sousBT->tabsous[0]=v->sousBT;
				v->sousBT=sousBT;
			}

		}
	}

	libere();
	return res;
}