Beispiel #1
0
int
addModuleSourceFile(SourceFile sf, Module m)
{ ListCell *cp, c2;
  int rc = TRUE;

  LOCKSRCFILE(sf);
  for(cp=&sf->modules; *cp; cp = &(*cp)->next)
  { ListCell cell = *cp;

    if ( cell->value == m )
      goto out;
  }

  if ( !(c2 = allocHeap(sizeof(struct list_cell))) )
  { rc = FALSE;			/* no memory */
    goto out;
  }
  c2->value = m;
  c2->next = NULL;
  *cp = c2;

out:
  UNLOCKSRCFILE(sf);
  return rc;
}
Beispiel #2
0
void *
allocHeapOrHalt(size_t n)
{ void *mem = allocHeap(n);

  if ( !mem )
    outOfCore();

  return mem;
}
Beispiel #3
0
static Code
allocCodes(size_t n)
{ GET_LD
  Code codes = allocHeap(sizeof(code)*(n+1));

  *codes++ = (code)n;

  return codes;
}
Beispiel #4
0
static void
allocHTableEntries(Table ht)
{ GET_LD
  int n;
  Symbol *p;

  ht->entries = allocHeap(ht->buckets * sizeof(Symbol));

  for(n=0, p = &ht->entries[0]; n < ht->buckets; n++, p++)
    *p = NULL;
}
Beispiel #5
0
char *
store_string(const char *s)
{ if ( s )
  { GET_LD

    char *copy = (char *)allocHeap(strlen(s)+1);

    strcpy(copy, s);
    return copy;
  } else
  { return NULL;
  }
}
Beispiel #6
0
Table
newHTable(int buckets)
{ GET_LD
  Table ht;

  ht		  = allocHeap(sizeof(struct table));
  ht->buckets	  = (buckets & ~TABLE_MASK);
  ht->size	  = 0;
  ht->enumerators = NULL;
  ht->free_symbol = NULL;
  ht->copy_symbol = NULL;
#ifdef O_PLMT
  if ( (buckets & TABLE_UNLOCKED) )
    ht->mutex = NULL;
  else
  { ht->mutex     = allocHeap(sizeof(simpleMutex));
    simpleMutexInit(ht->mutex);
  }
#endif

  allocHTableEntries(ht);
  return ht;
}
arbre* computeBIPtree(call_t *c, graphe* g, listeNodes* askedToRedirect, listeNodes* needsToBeCovered, int debug)
{
	struct nodedata *nodedata = get_node_private_data(c);
	arbre* bipTree = 0;
	int i, minNode, devientEmetteur, numMinNode, numVoisin;
	double coutIncremental;
	double* cle = malloc(g->nbSommets*sizeof(double));
	double* poids = malloc(g->nbSommets*sizeof(double));
	int* pere = malloc(g->nbSommets*sizeof(int));
	Heap* F = allocHeap(g->nbSommets, cle); // tas gardant les couts des noeuds pas encore dans l'arbre
	voisin *trans;
	
	if(debug)
		printf("Fixation des valeurs initiales...\n");
	for(i = 0 ; i < g->nbSommets ; i++)
	{
		cle[i] = DBL_MAX;
		poids[i] = 0;
		pere[i] = -1;
		h_insertNode(F, i);
	}
	h_changeLabel(F, g->s.num, 0);
	if(askedToRedirect == 0 || needsToBeCovered == 0)
	{
		poids[g->s.num] = getEdgeCost(g, c->node, getNearestNeighbour(c, g));
	}
	else
	{
		if(debug)
			printf("Fixation des valeurs de range deduites du paquet...\n");
		listeNodes *tmp = askedToRedirect, *tmp2 = needsToBeCovered;
		while(tmp != 0)
		{
			if(getEdgeCost(g, tmp->values.node, tmp2->values.node) != DBL_MAX)
			{
                                //printf("poids[%d] = %.1lf\n", tmp->values.node, getEdgeCost(g, tmp->values.node, tmp2->values.node));
				poids[getNumFromLabel(g,tmp->values.node)] = getEdgeCost(g, tmp->values.node, tmp2->values.node);
			}
			tmp = tmp->suiv;
			tmp2 = tmp2->suiv;
		}
	}
	if(debug)
		printf("Debut de l'algorithme...\n");
	while(!h_isEmpty(F))
	{
		if(debug)
			printf("Recuperation du min du tas...\n");
		numMinNode = h_remNode(F);
		minNode = getLabelFromNum(g,numMinNode);
		if(debug)
		{
			printf("minNode label : %d\n", minNode);
			printf("\tnum : %d\n", numMinNode);
			printf("Ajout du noeud dans l'arbre...\n");
		}
		if(pere[numMinNode] == -1)
		{
			arbre_add_pere(&(bipTree), minNode);
		}
		else
		{
			arbre_add_fils(bipTree, pere[numMinNode], minNode);
			int numPere = getNumFromLabel(g, pere[numMinNode]);
			if(poids[numPere] < getEdgeCost(g, pere[numMinNode], minNode))
			{
				if(debug)
					printf("\tChangement du poids de %d\n", pere[numMinNode]);
				poids[numPere] = getEdgeCost(g,pere[numMinNode], minNode);
			}
		}
		// pour chacun des noeuds pas dans l'arbre ie : dans le tas
		for(i = 0 ; i < g->nbSommets ; i++)
		{
			if(h_contains(F, i))
				h_changeLabel(F, i, DBL_MAX);
		}
		
		// pour chacun des noeuds dans l'arbre ie : pas dans le tas
		for(i = 0 ; i < g->nbSommets ; i++)
		{
			if(!h_contains(F, i))
			{
				// pour chacun des voisins dans le tas ie : pas dans l'arbre
				if(debug)
					printf("Recuperation du voisinage...\n");
				trans = getNeighboursFromLabel(g,getLabelFromNum(g,i));
				while(trans != 0)
				{
					numVoisin = getNumFromLabel(g,trans->vLabel);
					if(h_contains(F, numVoisin))
					{
						if(debug)
							printf("\tVoisin pas dans l'arbre : label : %d ; num : %d\n", trans->vLabel, numVoisin);
						coutIncremental = trans->cout - poids[i];
						if(coutIncremental < cle[numVoisin])
						{
							if(debug)
							{
								printf("\tCout a ameliorer : %.1lf < %.1lf\n", coutIncremental, cle[numVoisin]);
							}
							h_changeLabel(F, numVoisin, coutIncremental);
							if(debug)
								printf("\tpere[%d] devient %d...\n", trans->vLabel, getLabelFromNum(g,i));
							pere[numVoisin] = getLabelFromNum(g,i);
						}
					}
					trans = trans->vSuiv;
				}
			}
		}
	}
	
	
	free(poids);
	free(pere);
	free(cle);
	freeHeap(F);
	
	/*printf("Graphe de voisinage complet : \n");
	 printf("Graphe de voisinage : \n");
	 afficherGraphe(nodedata->g2hop);
	 printf("arbre de BIP de %d construit : \n", c->node);
	 arbre_affiche(bipTree);*/
	
	return bipTree;
}