Example #1
0
void InitInstrTable(void){
	instrHashTbl =  InitializeTable(instrNum * 2);//create hash table
	size_t tableSize = instrHashTbl->TableSize;
	opStrHashFindTbl = (int *)malloc(sizeof(size_t) * tableSize);
	memset(opStrHashFindTbl, NONE, sizeof(size_t) * tableSize);
	memset(opCodeFindTbl, NONE, sizeof(size_t) * OP_CODE_NUM);
	memset(functCodeFindTbl, NONE, sizeof(size_t) * FUNCT_CODE_NUM);
//create table

	Position pos;
	reg_type op = 0;
	reg_type funct = 0;

	size_t i = 0;
	for(i = 0; i < instrNum; i++){
		pos = Insert(instrTable[i].instruction[1], instrHashTbl);//insert op_str to table
		opStrHashFindTbl[pos] = i;
		sscanf(instrTable[i].code[0], "%d", &op);
		sscanf(instrTable[i].code[5], "%d", &funct);
		if(op != 0){
			opCodeFindTbl[op] = i;
		}
		else{
			functCodeFindTbl[funct] = i;
		}

#ifdef INSTR_BUG
		printf("pos: %d, retrieve: %s, opstr: %s\n",pos, Retrieve(pos, instrHashTbl),instrTable[i].instruction[1]);
#endif
	}
}
Example #2
0
int main()
{
	HashTable H;
	int i;

	H = InitializeTable( TableSize );
	
	for(i = 0; i < LEN; i++) {
		Insert(a[i], H);
	}

	PrintHashTable( H );
}
Example #3
0
SymbolTable build( Program program )
{
    SymbolTable table;
    Declarations *decls = program.declarations;
    Declaration current;

    InitializeTable(&table);

    while(decls !=NULL){
        current = decls->first;
        add_table(&table, current.name, current.type);
        decls = decls->rest;
    }

    return table;
}
Example #4
0
HashTable
Rehash(HashTable H)
{
	int i,OldSize;
	Cell *OldCells;

	OldCells = H->TheCells;
	OldSize=H->TableSize;

	H=InitializeTable(2*OldSize);
	for(i=0;i<OldSize;i++)
		if(OldCells[i].Info==Legitimate)
			Insert(OldCells[i].Element,H);
	free(OldCells);
	return H;
}
Example #5
0
int main()
{
	HashTable H;
	int i, num;

	freopen("dictionary.txt", "r", stdin);
	scanf("%d", &num);

	H = InitializeTable( TableSize );
	
	for(i = 0; i < num; i++) {
		scanf("%s", s);
		Insert(s, H);
	}

	PrintHashTable( H );
	
}
Example #6
0
int
main(void)
{
  HashTable H = InitializeTable(17);
  srand(time(NULL));
  for (int i = 0; i < 8; i++)
  {
    int ins = rand() % 100;
    printf("%d ---->\n", ins);
    Insert(ins, H);
  }
  printf("<----------------->\n");
  hprint(H);
  printf("<----------------->\n");
  H = Rehash(H);
  hprint(H);
  return 0;
}
Example #7
0
File: m.c Project: KHN190/cisb212
int main() {
	
	p_list p;
	HashTable H = InitializeTable(50);
	readfile(H);
	
	check(100,H);
	check(1201,H);
	check(26966,H);

	//traverse(H);

	double_del(H);
	printf("\n");
	traverse(H);

	DestroyTable(H);
	return 0;
}
Example #8
0
/* START: fig5_22.txt */
        HashTable
        Rehash( HashTable H )
        {
            int i, OldSize;
            Cell *OldCells;

/* 1*/      OldCells = H->TheCells;
/* 2*/      OldSize  = H->TableSize;

            /* Get a new, empty table */
/* 3*/      H = InitializeTable( 2 * OldSize );

            /* Scan through old table, reinserting into new */
/* 4*/      for( i = 0; i < OldSize; i++ )
/* 5*/          if( OldCells[ i ].Info == Legitimate )
/* 6*/              Insert( OldCells[ i ].Element, H );

/* 7*/      free( OldCells );

/* 8*/      return H;
        }
Example #9
0
int main()
{
    int N, M, F1, F2, i;
    ElementType Word;
    HashTable H;
    WList File;

    scanf("%d", &N);
    File = InitializeFileIndex(N);
    H = InitializeTable (MAXTable); /* 创建一个散列表 */
    for (i=0; i<N; i++) /* 读入并索引每个文件 */
        while (GetAWord(Word))
            FileIndex( File, i+1, InsertAndIndex(i+1, Word, H));
    scanf("%d", &M);
    for (i=0; i<M; i++) { /* 处理每条查询 */
        scanf("%d %d", &F1, &F2);
        printf("%.1f%c\n", ComputeSim(File, F1, F2, H), '%');
    }

    return 0;
}
Example #10
0
int main(void){
    HashTable H = InitializeTable(20);
    printf("%d\n",H->TableSize);
    printf("%d\n",H->TheList[0]->data);
    int choice;
    int item;

    instructions();
    printf("your choice:");
    scanf("%d",&choice);

    while(choice != 4){
        switch(choice){
            case 1:
                printf("\nEnter a number:\n");
                scanf("%d",&item);
                Insert(item,H);
                break;
            case 2:
                printf("\nEnter a number to delete\n");
                scanf("%d",&item);
                Delete(item,H);
                break;
            case 3:
                printTable(H);
                break;
            default:
                printf("\nInvaild choice\n\n");
                instructions();
                break;
        }
        printf("\nyour choice:");
        scanf("%d",&choice);
    }
    DestroyTable(H);
    printf("End of run\n");

    return 0;
}
Example #11
0
HashTable Rehash( HashTable H )
{
    int i, OldSize;
    Cell *OldCells;
        
    OldCells = H->TheCells;
    OldSize = H->TableSize;
    
    /*get a new, empty table*/
    H = InitializeTable(2*OldSize);
    
    /*Scan Through Old table, reinserting into new*/
    for(i = 0; i < OldSize; i++){
        if(OldCells[i].Info == Legitimate){
            Insert(OldCells[i].Element, H);
        }
    }
    
    free(OldCells);
    
    return H;
}
int main()
{
    HashTable table;

    table = InitializeTable(1000);


    Node tmp;
    Insert(table, 110);
    tmp = Find(table, 110);
    if(tmp == NULL)
    {
        puts("None!");
    }
    else
    {
        puts("Find it!!!");
    }

    DestoryTable(table);
    return 0;
}
Example #13
0
HashTable Rehash(HashTable H)
{
	int i;
	int TableSize;
	struct HashEntry* Cells;

	TableSize = H->TableSize;
	Cells = H->Cells;

	free( H );
	H = InitializeTable( TableSize * 2 );	
	
	for(i = 0; i < TableSize; i++) {
		if(Cells[i].Info == Legitimate) {
			Insert(Cells[i].Element, H);
		}
	}	

	free( Cells );

	return H;
}
Example #14
0
/* Initialize the identity-based hash tables. */
ABool AInitializeHashValueMapping(void)
{
    HashValueCounter = 1;
    return InitializeTable(&NewGenTable)
        && InitializeTable(&OldGenTable);
}
Example #15
0
int main()
{
	int row = 4;
	int col = 4;
	int max_len;
	int dirct;
	int size;
	int x, y;
	HashTable H;
	int i, num;

	/* Construct dictionary */
	freopen("dictionary.txt", "r", stdin);
	scanf("%d", &num);

	H = InitializeTable( TableSize );
	
	for(i = 0; i < num; i++) {
		scanf("%s", s);
		Insert(s, H);
	}


	/* Read data */
	max_len = row > col ? row : col;
	//for(y = 0; y < row; y++) {
	//	printf("%s\n", m[y]);
	//}	

	/* */
	for(y = 0; y < row; y++) {
		for(x = 0; x < col; x++) {
			for(dirct = 0; dirct < 8; dirct++) {
				for(size = 0; size < max_len; size++) {
					switch(dirct) {
					case 0:
						if(x+size < col)
							a[size] = m[y][x+size];
						else
							goto finish;
						break;
					case 1:
						if(x+size < col && y+size < row)
							a[size] = m[y+size][x+size];
						else
							goto finish;
						break;
					case 2:
						if(y+size < row)
							a[size] = m[y+size][x];
						else
							goto finish;
						break;	
					case 3:
						if(x-size >= 0 && y+size < row)
							a[size] = m[y+size][x-size];
						else
							goto finish;
						break;	
					case 4:
						if(x-size >= 0)
							a[size] = m[y][x-size];
						else
							goto finish;
						break;	
					case 5:
						if(x-size >= 0 && y-size >= 0)
							a[size] = m[y-size][x-size];
						else
							goto finish;
						break;	
					case 6:
						if(y-size >= 0)
							a[size] = m[y-size][x];
						else
							goto finish;
						break;	
					case 7:
						if(x+size < col && y-size >= 0)
							a[size] = m[y-size][x+size];
						else
							goto finish;
						break;	
					default:
						break;		
					}

					if(size + 1 >= max_len) {
						size++;
						goto finish;
					}
					continue;
finish:
					a[size] = '\0';
					if(CheckInTable(a, H)) {
						printf("(%d, %d) dirct = %d, size = %d: ",
							 y, x, dirct, size);
						printf("%s\n", a);
					}
					break; // break from for
				}
			}
		}
	}	
	
}