Пример #1
0
void ST1insert(Item item)
{ Key v = key(item);
  int i = hash(v, M), j = 0;
  while (!null(i)){
    if( eq(st[i]->literal, item->literal) ){
      item->occurencies->next = st[i]->occurencies;
      st[i]->occurencies = item->occurencies;
      return;
    }
    i = (i+1) % M;
  }
  st[i] = item;
  N++;

  if(N >= M/2){ /*resize dinamico*/
    Item *aux;
    int oldsize = M;
    M = prime_m(2*M);
    aux = mallocSafe(M*sizeof(Item));
    for(i = 0; i < M; i++) aux[i] = NULLitem;
    for(i = 0; i < oldsize; i++){
      if(st[i] != NULLitem){
	Key v = key(st[i]);
	j = hash(v, M);
	while( aux[j] != NULLitem ) j = (j+1)%M;
	aux[j] = st[i];
      }
    }
    free(st);
    st = aux;
  }
}
Пример #2
0
/*Função que torna o hash dinamico.
   Dobra o tamanho da tabela e reinsere os elementos*/
static void reHash()
{
    int K, i;
    Item_lema *aux;
    K = prime_m(2*M);
    aux = mallocSafe(K*sizeof(Item_lema));
    for (i = 0; i < K; i++) aux[i] = NULLitem_lema;

    for (i = 0; i < M; i++)
        if(!null(i))
        {
            int h = hash(key_lema(st_lema[i]), K);
            while (aux[h].lema != NULLitem_lema.lema) h = (h+1) % K;
            aux[h] = st_lema[i];
        }

    free(st_lema);
    st_lema = aux;
    aux = NULL;
    M = K;
}
Пример #3
0
/*Função que torna o hash dinamico.
   Dobra o tamanho da tabela e reinsere os elementos*/
static void reHash()
{
    int K, i;
    link *aux, t;
    K = prime_m(2*M);
    aux = mallocSafe(K*sizeof(link));
    for (i = 0; i < K; i++) aux[i] = z;

    for (i = 0; i < M; i++)
        while ((t = heads[i]) != z)
        {
            int h = hash(key_lema(t->item), K);
            heads[i] = heads[i]->next;
            t->next = aux[h];
            aux[h] = t;
        }
    free(heads);
    heads = aux;
    aux = NULL;
    M = K;
}
Пример #4
0
void ST1init(int max)
{ int i;
  N = 0; M = prime_m(2*max);
  st = malloc(M*sizeof(Item));
  for (i = 0; i < M; i++) st[i] = NULLitem;
}