elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  tabla hash
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: tabla hash  (Leído 1,629 veces)
gloomyfairy

Desconectado Desconectado

Mensajes: 1


Ver Perfil
tabla hash
« en: 3 Abril 2014, 06:03 am »

Hola, kisiera k m ayuden con el comando para compilar desde la terminal de linux este código:

Código
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5.  
  6. #define MAX_BUCKETS 512          /* the index size and the maximum number of buckets */
  7. #define SIZE 10                  /* the number of records per bucket                 */
  8.  
  9. struct rec_tag
  10. {
  11.  char key_field[21];
  12.  /* other data fields as necessary */
  13. };
  14.  
  15. typedef struct buck_tag
  16. {
  17.  long number_of_records;
  18.  int bucket_bits;
  19.  struct rec_tag record[SIZE];
  20. } BUCKET;
  21.  
  22. struct head_tag
  23. {
  24.  int bits_used_in_index;
  25.  long buckets_used;
  26. };
  27.  
  28. int main()
  29. {
  30.  int  depth, bits;
  31.  int  i , limit;
  32.  int  sub;
  33.  int  record_found;
  34.  long rrn;
  35.  long address;
  36.  int begin_new, end_new;
  37.  long bucket_address;
  38.  long bucket_table[MAX_BUCKETS];   /* this will hold actual byte offsets rather than rrn */
  39.  long index_size;
  40.  long positions_used;
  41.  
  42.  BUCKET bucket;
  43.  BUCKET new_bucket;
  44.  struct rec_tag record;
  45.  struct head_tag header_record;
  46.  
  47.  FILE *buckets;
  48.  FILE *index;
  49.  
  50.  index = fopen("c:\\index.dat", "rb+");  /* access will only be sequential */
  51.  buckets = fopen("c:\\buckets.dat", "rb+");  /* access will be relative     */
  52.  
  53.  fread(&header_record, sizeof(header_record), 1, index);
  54.  index_size = pow(2, header_record.bits_used_in_index);
  55.  fread(bucket_table, sizeof(long), index_size, index);
  56.  
  57.  /*  at this point would be a call to a function that would fill the
  58.       structure called record with valid data                               */
  59.  
  60.  sub = makesub(record.key_field, header_record.bits_used_in_index);
  61.  
  62.  fseek(buckets, bucket_table[sub], SEEK_SET);
  63.  fread(&bucket, sizeof(bucket), 1, buckets);
  64.  
  65.  for(i=0, record_found=1; i < bucket.number_of_records && record_found != 0; i++)
  66.    record_found = strcmp(record.key_field, bucket.record[i].key_field);
  67.  
  68.  if(record_found == 0)
  69.  {
  70.    puts("Record already exists.");
  71.    puts("Enter another record.");
  72.  }
  73.  else
  74.  {
  75.    if(bucket.number_of_records < SIZE)
  76.    {
  77.      bucket.number_of_records += 1;
  78.      memcpy(&bucket.record[bucket.number_of_records - 1], &record, sizeof(record));
  79.      fseek(buckets, bucket_table[sub], SEEK_SET);
  80.      fwrite(&bucket, sizeof(bucket), 1, buckets);
  81.    }
  82.    else /* the bucket is full and must be split  */
  83.    {
  84.      if(bucket.bucket_bits == header_record.bits_used_in_index)
  85.          header_record.bits_used_in_index =
  86.                                doublidx(header_record.bits_used_in_index, bucket_table);
  87.      moverecs(&bucket, &new_bucket);
  88.      header_record.buckets_used += 1;
  89.      fseek(buckets, bucket_table[sub], SEEK_SET);
  90.      fwrite(&bucket, sizeof(bucket), 1, buckets);
  91.      fseek(buckets, 0, SEEK_END);
  92.      bucket_address = ftell(buckets);
  93.      fwrite(&new_bucket, sizeof(bucket), 1, buckets);
  94.  
  95.     /* now comes the tricky bit.  the address of the new bucket must be
  96.         inserted into the appropriate place(s) in the index.  first, get the
  97.         subscript for the table entry from any key in the new bucket.       */
  98.  
  99.      sub = makesub(new_bucket.record[0].key_field, header_record.bits_used_in_index);
  100.  
  101.  rrn = bucket_table[sub];
  102.  limit = pow(2,header_record.bits_used_in_index);
  103.  
  104.      for(i=0; i < limit; i++)
  105.      {
  106.        if(bucket_table[i]==rrn) break;
  107.  }
  108.  begin_new = i;
  109.  for(;bucket_table[i]==rrn && i < limit; i++) end_new = i;
  110.      begin_new = begin_new + (end_new - begin_new + 1) / 2;
  111.  
  112.      for(i=begin_new; i <= end_new; i++) bucket_table[i] = bucket_address;
  113.  
  114.      fseek(index, 0L, SEEK_SET);
  115.      fwrite(&header_record, sizeof(header_record), 1, index);
  116.      index_size = sizeof(long) * pow(2, header_record.bits_used_in_index);
  117.      fwrite(bucket_table, index_size, 1, index);
  118.  
  119.     /* now that the index and bucket maintenance is done, the rest is simple
  120.         retrieve the bucket and add the new record.                           */
  121.  
  122.      sub = makesub(record.key_field, header_record.bits_used_in_index);
  123.  
  124.      fseek(buckets, bucket_table[sub], SEEK_SET);
  125.      fread(&bucket, sizeof(bucket), 1, buckets);
  126.  
  127.      bucket.number_of_records += 1;
  128.      memcpy(&bucket.record[bucket.number_of_records - 1], &record, sizeof(record));
  129.      fseek(buckets, bucket_table[sub], SEEK_SET);
  130.      fwrite(&bucket, sizeof(bucket), 1, buckets);
  131.    }  /*  end else */
  132.  }  /*  end else */
  133.  
  134.  fclose(index);
  135.  fclose(buckets);
  136.  
  137.  return 0;
  138. }
  139.  

me salen los siguientes errores kuando ingreso el código cc nombre.c -lm -o nombre.exe -lrt

c.c:(.text+0xe4): referencia a `makesub' sin definir
c.c:(.text+0x28a): referencia a `doublidx' sin definir
c.c:(.text+0x2a5): referencia a `moverecs' sin definir
c.c:(.text+0x364): referencia a `makesub' sin definir
c.c:(.text+0x513): referencia a `makesub' sin definir
collect2: error: ld returned 1 exit status



« Última modificación: 3 Abril 2014, 12:11 pm por Eternal Idol » En línea

Eternal Idol
Kernel coder
Moderador
***
Desconectado Desconectado

Mensajes: 5.937


Israel nunca torturó niños, ni lo volverá a hacer.


Ver Perfil WWW
Re: tabla hash
« Respuesta #1 en: 3 Abril 2014, 12:14 pm »

http://www.isqa.unomaha.edu/haworth/isqa3300/fs009.htm

Ahi esta el resto del codigo ...


En línea

La economía nunca ha sido libre: o la controla el Estado en beneficio del Pueblo o lo hacen los grandes consorcios en perjuicio de éste.
Juan Domingo Perón
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Duda sobre insersion a tabla html desde tabla sql
Bases de Datos
mokoMonster 2 3,946 Último mensaje 20 Febrero 2010, 01:20 am
por Shell Root
no me borra la tabla haciendo delete on cascade tabla n:m
Bases de Datos
kinos 2 4,122 Último mensaje 31 Julio 2010, 13:05 pm
por kinos
Tabla dentro de tabla.
Java
KenoChile 2 2,771 Último mensaje 10 Agosto 2012, 16:31 pm
por KenoChile
Calculo de frecuencias de palabras usando dispersio con tabla HASH cerrada
Programación C/C++
falcao999 3 3,758 Último mensaje 5 Diciembre 2012, 19:13 pm
por 0xDani
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines