Пример #1
0
void BuildLSH(LSH** lshptr, int L, int k) {
    int i,j;

    *lshptr = malloc(sizeof(LSH));
    LSH* lsh = *lshptr;
    lsh->L = L;
    lsh->k = k;
    lsh->tables = malloc(L * sizeof(hashMap));
    value value;
    for (i = 0; i < L; i++) {

        //initialize struct for each G function depending on the metric
        lsh->tables[i].GConfiguration = data.initStruct();

        //initialize hash
        InitHashTable(&(lsh->tables[i].tables), data.tableSize,
                      sizeof(value), data.print, data.distance, data.G,
                      NULL);

        //insert each value in hash table
        for(j=0; j<GetDataSize(); j++) {
            GetIthData(j,&value);

            InsertHashTable(lsh->tables[i].tables, &value,
                            lsh->tables[i].GConfiguration);
            //value = GetNextData();
        }
    }

}
Пример #2
0
mccp_result_t
mccp_hashmap_create(mccp_hashmap_t *retptr,
                    mccp_hashmap_type_t t,
                    mccp_hashmap_value_freeup_proc_t proc) {
  mccp_result_t ret = MCCP_RESULT_ANY_FAILURES;
  mccp_hashmap_t hm;

  if (retptr != NULL) {
    *retptr = NULL;
    hm = (mccp_hashmap_t)malloc(sizeof(*hm));
    if (hm != NULL) {
      if ((ret = mccp_rwlock_create(&(hm->m_lock))) ==
          MCCP_RESULT_OK) {
        hm->m_type = t;
        InitHashTable(&(hm->m_hashtable), (unsigned int)t);
        hm->m_del_proc = proc;
        hm->m_n_entries = 0;
        hm->m_is_operational = true;
        *retptr = hm;
        ret = MCCP_RESULT_OK;
      } else {
        free((void *)hm);
      }
    } else {
      ret = MCCP_RESULT_NO_MEMORY;
    }
  } else {
    ret = MCCP_RESULT_INVALID_ARGS;
  }

  return ret;
}
Пример #3
0
int main(int argc,char* argv[])
{
	hashdata** ht;

	InitHashTable(&ht,N);

	const char* words[15] = {
		"ske","abs","mps","test","tt","total","smtp","mbsc",
		"adfads","asdfa","dfads","13413la","tt","linux","windows"
	};

	int i;
	for (i = 0; i < 15; i++)
	{
		AddData(ht,N,words[i]);
	}
	PrintHashTable(ht,N);

	for (i = 0; i < 15; i++)
	{
		DeleteData(ht,N,words[i]);
	}
	PrintHashTable(ht,N);

	DestroyHashTable(&ht,N);

	return 0;
}
Пример #4
0
void Dictionary::SetAt(const ieResRef key, unsigned int type, unsigned int value)
{
	int i;
	unsigned int nHash;
	MyAssoc* pAssoc=GetAssocAt( key, type, nHash );

	if (pAssoc == NULL) {
		if (m_pHashTable == NULL)
			InitHashTable( m_nHashTableSize );

		// it doesn't exist, add a new Association
		pAssoc = NewAssoc();
		// put into hash table
		pAssoc->pNext = m_pHashTable[nHash];
		m_pHashTable[nHash] = pAssoc;
	}
	for(i=0;i<KEYSIZE && key[i];i++) {
		pAssoc->key[i]=tolower(key[i]);
	}
	for(;i<KEYSIZE;i++) {
		pAssoc->key[i]=0;
	}
	pAssoc->type = type;
	pAssoc->value = value;
}
int main(void)
{
	int n;
	int m;
	scanf("%d %d", &n, &m);
	struct elem ** table = InitHashTable(m);
	int i = 0;
	int k;
	int v;
	char word[7];
	for(i = 0; i < n; i++)
	{
		scanf("%s", word);
		if(word[0] == 'A' && word[1] == 'T')
		{
			scanf("%d", &k);
			v = Lookup(table, k, m);
			printf("%d\n", v);
		}
		else
		{
			scanf("%d %d", &k, &v);
			table = Insert(table, k, v, m);
		}
	}
	freeTable(table, m);
	return 0;
}
Пример #6
0
int* twoSum(int* nums, int numSize, int target)
{
	int i;
	int tableSize = numSize*2;
	int* TwoNum = (int*)malloc(sizeof(int)*2);
	if (TwoNum == NULL)
	{
		printf("malloc TwoSum error\n");
		return NULL;
	}

	HashList* list = InitHashTable(tableSize);
	for (i = 0; i < numSize; i++)
	{
		int pos;
		pos = Hash(abs(nums[i]), tableSize);
		InsertHash(nums[i], i, pos, list);
	}

	for (i = 0; i < numSize; i++)
	{
		int subdata = target-nums[i];
		int pos = Hash(abs(subdata), tableSize);
		HashNode node = FindNode(i, pos, subdata, list);
		if (node != NULL)
		{
			TwoNum[0] = i+1;
			TwoNum[1] = node->index+1;
			FreeHash(list, tableSize);
			return TwoNum;
		}
	}
	FreeHash(list, tableSize);
	return NULL;
}
Пример #7
0
int main(void)
{
	hashTable ht;
	InitHashTable(&ht, 100, print, equal, hashFun);
	int a1 =2;
	int a2 =4;

	InsertHashTable(ht, &a1);

	//print(SearchHashTable(ht, &a1));
	int *r =(int*)SearchHashTable(ht, &a1);
	assert( *r == 2 );

	r = SearchHashTable(ht, &a2);
	assert( r == NULL );

	InsertHashTable(ht, &a2);
	r = SearchHashTable(ht, &a2);
	assert( *r == 4);

	DestroyHashTable(&ht);
	printf("hashTable OK\n");
	
	
	return 0;
}
Пример #8
0
void    VSTInit( void ) {
//=================

// Initialize symbol table.

    NList = NULL;
    InitHashTable( HashTable, HASH_PRIME );
    CList = NULL;
    InitHashTable( ConstHashTable, HASH_PRIME );
    LList = NULL;
    SList = NULL;
    MList = NULL;
    BList = NULL;
    RList = NULL;
    NmList = NULL;
    IFList = NULL;
}
Пример #9
0
void    OpenSymTab( void ) {
//====================

// Initialize the symbol table.

    if( ( ProgSw & PS_DONT_GENERATE ) == 0 ) return;
    GList = NULL;
    InitHashTable( GHashTable, HASH_PRIME + 1 );
}
Пример #10
0
int main(void) {
    unsigned int n;
    char key[64], *japanese;
    HASHTABLE hashtable;
    WORDSET *wordfound;
    WORDSET words[5] = {
            {"dolphin", "イルカ"},{"beluga", "シロイルカ"},
            {"grampus", "シャチ"},{"medusa", "海月"},
            {"otter", "カワウソ"}
    };

    /* ハッシュテーブルの初期化 */
    InitHashTable(&hashtable, 503);

    /* データを追加 */
    for(n = 0; n < 5; n++) {
        AddDataToMap(&hashtable, &words[n]);
    }

    do {
        printf("どの操作を行いますか?(1:検索 2:削除 "
                                    "3:全表示 0:終了)\n>");
        scanf("%d", &n);
        switch(n) {
        case 1: /* 検索 */
            printf("検索する英単語を入力してください:");
            scanf("%s", key);
            japanese = GetDataFromMap(&hashtable, key);
            if(japanese != NULL) {
                printf("%sの和訳は%sです。\n", key, japanese);
            } else {
                printf("%sがマップのなかに"
                            "見つかりませんでした。\n", key);
            }
            break;
        case 2: /* 削除 */
            printf("削除する英単語を入力してください:");
            scanf("%s", key);
            wordfound = DeleteDataFromMap(&hashtable, key);
            if(wordfound != NULL) {
                printf("%sをマップから削除しました。\n", key);
            } else {
                printf("%sがマップのなかに"
                            "見つかりませんでした。\n", key);
            }
            break;
        case 3: /* 全表示 */
            PrintAllData(&hashtable);
            break;
        }
    } while(n != 0);

    CleanupHashTable(&hashtable);   /* クリーンアップ */

    return 0;
}
Пример #11
0
Map* InitMap() {
	Map* mp = (Map*)malloc(sizeof(Map));
	//printf("malloc Map: %d\n",sizeof(Map));
	if (!mp) return NULL;
	mp->tb = InitHashTable();
	mp->size = 0;
	if (mp->tb) return mp;
	else {
		free(mp);
		return NULL;
	}
}
Пример #12
0
int main(int argc, const char* argv[])
{
  int i;
  int* addr = (int *) malloc(sizeof(int));
  HashTable H;
  InitHashTable(&H);
  for (i = 0; i < 10; i++) {
    InsertHash(&H, i * 2);
  }
  int t = SearchHash(H, 12, addr);
  printf("%d\n", t);
}
Пример #13
0
/**
 * @brief Create hash information from a array.
 *
 * @param itemNum Number of items in array.
 * @param pArray Pointer pointed to array which will create hash information.
 * @return Pointer to created hash information.
 */
HashInf *HashFromArray(int itemNum, char **pArray)
{
	PrepareCryptTable();
	HashInf *pHashInf = (HashInf *)malloc(sizeof(HashInf));
	pHashInf->pHashTable = InitHashTable(itemNum * ZOOM_TIMES_PREVENT_CONFLICT);
	pHashInf->nTableSize = itemNum * ZOOM_TIMES_PREVENT_CONFLICT;

	// Add each string to hash table.
	for (int i=0; i<itemNum; ++i)
	{
		InsertHash(pArray[i], pHashInf->pHashTable, pHashInf->nTableSize);
	}
	return pHashInf;
}
Пример #14
0
int PNNRange(LSH* lsh, value query, int P,value* array) {

    int i=0;
    int hashSize=0;
    hashTable neighbors;
    double* distArr=NULL;

    for (i = 0; i < lsh->L; i++) {

        //gets bucket where the value is
        List bucketList = GetListHashTable(lsh->tables[i].tables,
                                           &query, lsh->tables[i].GConfiguration);
        hashSize+=SizeList(bucketList);
    }
    InitHashTable(&neighbors,hashSize,sizeof(value),NULL,
                  data.distance,hashFunc,NULL);

    for (i = 0; i < lsh->L; i++) {


        //gets bucket where the value is
        List bucketList = GetListHashTable(lsh->tables[i].tables,
                                           &query, lsh->tables[i].GConfiguration);
        value* lValue = GetFirst(bucketList);
        //get all neighbours in range an place them in a list
        while (lValue != NULL) {
            InsertHashTable(neighbors, lValue,NULL);
            lValue = GetNext(bucketList);
        }
    }
    value** hashArr=malloc( GetHashSize(neighbors) * sizeof(value*));
    // WARNING //
    HashToArr(neighbors,(void**)hashArr);
    distArr=malloc(GetHashSize(neighbors)*sizeof(double));


    for(i=0; i<GetHashSize(neighbors); i++) {
        distArr[i]=data.distance(hashArr[i],&query);
    }

    QuickSortValue(distArr, hashArr,  GetHashSize(neighbors));

    for(i=0; (i<P && i<GetHashSize(neighbors)-1 ); i++) {
        array[i]=*hashArr[i+1];
    }
    DestroyHashTable(&neighbors);
    free(hashArr);
    free(distArr);
    return i;
}
Пример #15
0
CModel *CreateCModel(int maxCtxSize, int nSymbols, int nCtxSymbols,
  int deltaNum, int deltaDen, int maxCount)

	{
	CModel *cModel;

	if(!(cModel = (CModel *)calloc(1, sizeof(CModel))))
		{
		fprintf(stderr, "Error: in memory allocation\n");
		exit(1);
		}

	if(maxCtxSize > 30)
		{
		fprintf(stderr, "Error: context size greater than 30 is not allowed\n");
		exit(1);
		}
	
	cModel->nPModels = (unsigned long long)pow(nCtxSymbols, maxCtxSize);
	cModel->maxCtxSize = maxCtxSize;
	cModel->ctxSize = maxCtxSize;
	cModel->nSymbols = nSymbols;
	cModel->nCtxSymbols = nCtxSymbols;
	cModel->deltaNum = deltaNum;
	cModel->deltaDen = deltaDen;
	cModel->maxCount = maxCount;
	cModel->arrayMemory = cModel->nPModels * nSymbols *
	  sizeof(CCounter) / 1024 / 1024 ;

	if(cModel->arrayMemory > MAX_ARRAY_MEMORY)
		{
		InitHashTable(cModel->table);
		}

	else
		{
		if(!(cModel->counters = (CCounter *)calloc(cModel->nPModels *
		  nSymbols, sizeof(CCounter))))
			{
			fprintf(stderr, "Error: in memory allocation\n");
			exit(1);
			}

		}

	return cModel;
	}
Пример #16
0
int main(void)
{
    size_t temp_buf = 50;   // 临时单词变量长度
    size_t buf_times = 1;   // 哈希表表长倍数
    size_t max_count = 0, max_position = 0; // 用于最后顺序查找最大值
    char *temp = (char *)malloc(temp_buf);
    HashTable *table = (HashTable *)malloc(sizeof(HashTable) * MAX_BUF * buf_times);
    HashTable *curr;
    int strLength, i;   // 单词长度
    
    InitHashTable(table, 0, MAX_BUF * buf_times);
    
    for (i = 0; i < 50; i++)
        putchar('a');
    while ( (strLength = InputWord(temp, temp_buf)) != 0)
    {
        if (*temp == '\0')  // 如果单词为空,丢弃这个单词并继续
        {
            continue;
        }
        i = Locate(temp, &table, strLength, &buf_times);
        curr = table + i;
        if (curr->word == NULL)
        {
            curr->word = (char *)malloc(strLength);    // 根据单词长度开辟空间
            strcpy(curr->word, temp);    // 拷贝到目标位置
            //           printf("%s %s", temp, (table+i)->word);
        }
        curr->count++;
    }
    
    for (i = 0; i < MAX_BUF * buf_times; i++)
    {
        curr = table + i;
        if (curr->count > max_count)
        {
            max_position = i;
            max_count = curr->count;
        }
    }
    
    printf("Max Word: %s, Count: %ld\n", (table + max_position)->word, max_count);
    
    return 0;
}
Пример #17
0
/**
 * @brief Create hash information from list.
 *
 * @param itemNum Number of items in array.
 * @param list Pointer pointed to list which will create hash information.
 * @param GetNextStr Method of how to get string from list.
 * @return Pointer to created hash information.
 */
HashInf *HashFromList(int itemNum, char *(GetNextStr)(void **), void *list)
{
	char *str = NULL;
	int hashTableIndex;

	PrepareCryptTable();
	HashInf *pHashInf = (HashInf *)malloc(sizeof(HashInf));
	pHashInf->pHashTable = InitHashTable(itemNum * ZOOM_TIMES_PREVENT_CONFLICT);
	pHashInf->nTableSize = itemNum * ZOOM_TIMES_PREVENT_CONFLICT;

	// Get every string in list and add them to hash table.
	while(NULL != (str = (*GetNextStr)(&list)))
	{
		InsertHash(str, pHashInf->pHashTable, pHashInf->nTableSize);
	}

	return pHashInf;
}
Пример #18
0
int main() {

	AllInit();

	S_BOARD pos[1];
    S_SEARCHINFO info[1];
    info->quit = FALSE;
    pos->HashTable->pTable = NULL;
    InitHashTable(pos->HashTable, 64);
	setbuf(stdin, NULL);
    setbuf(stdout, NULL);
	
	printf("Welcome to Vice! Type 'vice' for console mode...\n");

	char line[256];
	while (TRUE) {
		memset(&line[0], 0, sizeof(line));

		fflush(stdout);
		if (!fgets(line, 256, stdin))
			continue;
		if (line[0] == '\n')
			continue;
		if (!strncmp(line, "uci",3)) {
			Uci_Loop(pos, info);
			if(info->quit == TRUE) break;
			continue;
		} else if (!strncmp(line, "xboard",6))	{
			XBoard_Loop(pos, info);
			if(info->quit == TRUE) break;
			continue;
		} else if (!strncmp(line, "vice",4))	{
			Console_Loop(pos, info);
			if(info->quit == TRUE) break;
			continue;
		} else if(!strncmp(line, "quit",4))	{
			break;
		}
	}

	free(pos->HashTable->pTable);
	
	return 0;
}
Пример #19
0
bool readHashTable(HashTable &hT,const char *file) {
//	std::ofstream oF("sss.txt");	oF.close();

	std::ifstream iF(file);
	if (!iF) return false;
	int size;
	iF >> size;
	table_size = size;
	InitHashTable(hT);

	ElemType data; //student
	
	while (iF >> data.id) {
		iF >> data.score;
		InsertHashTable(hT, data);
	}

	return true;
}
Пример #20
0
/*
    确定实际存放位置,如果不够则开辟空间
 
    @params *temp 存放单词的临时变量
    @params **table 哈希表的地址
    @params length 单词长度
    @params *buf_times 目前哈希表表倍数的地址
 
    @return i 实际存放位置
 */
int Locate(char *temp, HashTable **table, int length, size_t *buf_times)
{
    int head, i;    // head 默认存放位置
    
    for (i = head = CalculateHashValue(temp); (*table + i)->word != NULL && strcmp(temp, (*table +i)->word) != 0; )     // 如果单词存在并且与已存单词不同
    {
        i++;        // 线性探测查找位置
        if (i == MAX_BUF * *buf_times)  // 如果探测到尾部,从头开始
            i = 0;
        if (i == head)  // 如果完成一圈查找并没有找到,则表增加一倍
        {
            (*buf_times)++;
            *table = (HashTable *)realloc(*table, sizeof(HashTable) * MAX_BUF * *buf_times);
            InitHashTable(*table, MAX_BUF * (*buf_times - 1), MAX_BUF * *buf_times);
        }
    }
    
    return i;
}
Пример #21
0
void InitHashTable(S_HASHTABLE *table, const int MB) {

    int HashSize = 0x100000 * MB;
    table->numEntries = HashSize / sizeof(S_HASHENTRY);
    table->numEntries -= 2;

    if(table->pTable!=NULL) {
        free(table->pTable);
    }

    table->pTable = (S_HASHENTRY *) malloc(table->numEntries * sizeof(S_HASHENTRY));
    if(table->pTable == NULL) {
        printf("Hash Allocation Failed, trying %dMB...\n",MB/2);
        InitHashTable(table,MB/2);
    } else {
        ClearHashTable(table);
        printf("HashTable init complete with %d entries\n",table->numEntries);
    }

}
Пример #22
0
int main()
{
    int n, m, i;
    if(DBG){
        f1 = fopen("d:\\test.txt", "rt");
        f2 = fopen("d:\\text1.txt", "wt");
    }
    DBG ? fscanf(f1, "%d%d", &n, &m) : scanf("%d%d", &n, &m);
    HashTable H;
    HashTable * h = &H;
    InitHashTable(h, m);

    char str[40];
    int key, val;
    for(i=0; i<n; i++){
/*
if(i==6869){
        printf("sdf");
}
if(i==6870){    printf("%d", At(h, 900473962));exit(0);}
if(i==9013){    printf("sdf");}
*/
        DBG ? fscanf(f1, "%s", str) : scanf("%s", str);
        if (str[1] == 'S') {
            DBG ? fscanf(f1,"%d%d", &key, &val) : scanf("%d%d", &key, &val);
//            if(DBG)fprintf(f2, "%d\t%s %d %d\n", i+3, str, key, val);
            Assign(h, key, val);
        }
        if (str[1] == 'T') {
            DBG ? fscanf(f1,"%d", &key) : scanf("%d", &key);
//            if(DBG)fprintf(f2, "%d\t%s %d\n", i+3, str, key);
            DBG ? fprintf(f2,"%d\n", At(h, key)) : printf("%d\n", At(h, key));
        }
    }
    DestroyHashTable(h);
    if(DBG){
        fclose(f1);
        fclose(f2);
    }
    return 0;
}
Пример #23
0
void TrainModel() {
  long long a, b;
  double len;

  InitHashTable();
  ReadVector();

  FILE *fo;
  fo = fopen(output_file, "wb");
  fprintf(fo, "%lld %lld\n", num_vertices, vector_dim1 + vector_dim2);
  for (a = 0; a < num_vertices; a++) {
    fprintf(fo, "%s ", vertex[a].name);

    len = 0;
    for (b = 0; b < vector_dim1; b++) len += vec1[b + a * vector_dim1] * vec1[b + a * vector_dim1];
    len = sqrt(len);
    for (b = 0; b < vector_dim1; b++) vec1[b + a * vector_dim1] /= len;

    len = 0;
    for (b = 0; b < vector_dim2; b++) len += vec2[b + a * vector_dim2] * vec2[b + a * vector_dim2];
    len = sqrt(len);
    for (b = 0; b < vector_dim2; b++) vec2[b + a * vector_dim2] /= len;

    if (binary)
    {
      for (b = 0; b < vector_dim1; b++)
        fwrite(&vec1[a * vector_dim1 + b], sizeof(real), 1, fo);
      for (b = 0; b < vector_dim2; b++)
        fwrite(&vec2[a * vector_dim2 + b], sizeof(real), 1, fo);
    }
    else
    {
      for (b = 0; b < vector_dim1; b++)
        fprintf(fo, "%lf ", vec1[a * vector_dim1 + b]);
      for (b = 0; b < vector_dim2; b++)
        fprintf(fo, "%lf ", vec2[a * vector_dim2 + b]);
    }
    fprintf(fo, "\n");
  }
  fclose(fo);
}
Пример #24
0
void TrainLINE() {
  long a;
  pthread_t *pt = (pthread_t *)malloc(num_threads * sizeof(pthread_t));

  if (order != 1 && order != 2)
  {
    printf("Error: order should be eighther 1 or 2!\n");
    exit(1);
  }
  printf("--------------------------------\n");
  printf("Order: %d\n", order);
  printf("Samples: %lldM\n", total_samples / 1000000);
  printf("Negative: %d\n", num_negative);
  printf("Dimension: %d\n", dim);
  printf("Initial rho: %lf\n", init_rho);
  printf("--------------------------------\n");

  InitHashTable();
  ReadData();
  InitAliasTable();
  InitVector();
  InitNegTable();
  InitSigmoidTable();

  gsl_rng_env_setup();
  gsl_T = gsl_rng_rand48;
  gsl_r = gsl_rng_alloc(gsl_T);
  gsl_rng_set(gsl_r, 314159265);

  clock_t start = clock();
  printf("--------------------------------\n");
  for (a = 0; a < num_threads; a++) pthread_create(&pt[a], NULL, TrainLINEThread, (void *)a);
  for (a = 0; a < num_threads; a++) pthread_join(pt[a], NULL);
  printf("\n");
  clock_t finish = clock();
  double duration = (double)(finish - start) / CLOCKS_PER_SEC;
  printf("Total CPU time: %lf, real time %.2lf (s)\n", duration, duration / num_threads);

  Output();
}
Пример #25
0
void DEH_AddStringReplacement(const char *from_text, const char *to_text)
{
    deh_substitution_t *sub;
    size_t len;

    // Initialize the hash table if this is the first time
    if (hash_table_length < 0)
    {
        InitHashTable();
    }

    // Check to see if there is an existing substitution already in place.
    sub = SubstitutionForString(from_text);

    if (sub != NULL)
    {
        Z_Free(sub->to_text);

        len = strlen(to_text) + 1;
        sub->to_text = Z_Malloc(len, PU_STATIC, NULL);
        memcpy(sub->to_text, to_text, len);
    }
    else
    {
        // We need to allocate a new substitution.
        sub = Z_Malloc(sizeof(*sub), PU_STATIC, 0);

        // We need to create our own duplicates of the provided strings.
        len = strlen(from_text) + 1;
        sub->from_text = Z_Malloc(len, PU_STATIC, NULL);
        memcpy(sub->from_text, from_text, len);

        len = strlen(to_text) + 1;
        sub->to_text = Z_Malloc(len, PU_STATIC, NULL);
        memcpy(sub->to_text, to_text, len);

        DEH_AddToHashtable(sub);
    }
}
Пример #26
0
char& CMapDWORDToChar::operator[](DWORD key)
{
	ASSERT_VALID(this);

	UINT nHash;
	CAssoc* pAssoc;
	if ((pAssoc = GetAssocAt(key, nHash)) == NULL)
	{
		if (m_pHashTable == NULL)
			InitHashTable(m_nHashTableSize);

		// it doesn't exist, add a new Association
		pAssoc = NewAssoc();
		pAssoc->nHashValue = nHash;
		pAssoc->key = key;
		// 'pAssoc->value' is a constructed object, nothing more

		// put into hash table
		pAssoc->pNext = m_pHashTable[nHash];
		m_pHashTable[nHash] = pAssoc;
	}
	return pAssoc->value;  // return new reference
}
Пример #27
0
 void main()
 {
   ElemType r[N]={{17,1},{60,2},{29,3},{38,4},{1,5},{2,6},{3,7},{4,8},{60,9},{13,10}};
   HashTable h;
   int i,p;
   Status j;
   KeyType k;
   InitHashTable(&h);
   for(i=0;i<N-1;i++)
   { /* 插入前N-1个记录 */
     j=InsertHash(&h,r[i]);
     if(j==DUPLICATE)
       printf("表中已有关键字为%d的记录,无法再插入记录(%d,%d)\n",r[i].key,r[i].key,r[i].ord);
   }
   printf("按哈希地址的顺序遍历哈希表:\n");
   TraverseHash(h,print);
   printf("请输入待查找记录的关键字: ");
   scanf("%d",&k);
   j=Find(h,k,&p);
   if(j==SUCCESS)
     print(p,h.elem[p]);
   else
     printf("没找到\n");
   j=InsertHash(&h,r[i]); /* 插入第N个记录 */
   if(j==ERROR) /* 重建哈希表 */
     j=InsertHash(&h,r[i]); /* 重建哈希表后重新插入第N个记录 */
   printf("按哈希地址的顺序遍历重建后的哈希表:\n");
   TraverseHash(h,print);
   printf("请输入待查找记录的关键字: ");
   scanf("%d",&k);
   j=Find(h,k,&p);
   if(j==SUCCESS)
     print(p,h.elem[p]);
   else
     printf("没找到\n");
   DestroyHashTable(&h);
 }
Пример #28
0
Int2 Main(void)
{
  Int4 StsCount = 0, StsInvalid = 0;
  STSHashPtr PNTR StsHashTable;
  STSDbNamesPtr db_name;

  if (!GetArgs("setsts",NUMARGS,dump_args)) {
    return 1;
  }
  if (!ErrSetLog (LogFileName)) {
    ErrShow();
  } else {
    ErrSetOpts (ERR_CONTINUE, ERR_LOG_ON);
  }

  db_name = MemNew(sizeof(STSDbNames));
  db_name->sts_db_name = StsName;
  db_name->sts_map_name = MapName;
  db_name->sts_org_name = OrgName;
  
  if((StsHashTable = InitHashTable(db_name, &StsCount, &StsInvalid)) == NULL) {
    ErrLogPrintf("Error in initialization of Hash Table. Exiting...");
    return 1;
  }
 
  ErrLogPrintf("Invalid database entries found: %d\n",   StsInvalid); 
  ErrLogPrintf("Hash table created with %d sequences\n", StsCount);
  
  if((StsCount = DumpHashTable(db_name, StsHashTable)) < 0) {
    ErrLogPrintf("Error in dumping of Hash Table. Exiting...");
    return 1;
  }

  ErrLogPrintf("Map file dumped with %d sequences\n", StsCount);
  return 0;
}
Пример #29
0
void CO_Init(void)
{
	InitHashTable();
}
void InitCNAMEHashTable(_RTP_CONTEXT *the_context)
{
  InitHashTable(&the_context->RTP_CNAME_Hash);
}