void main()
{
	int n;
	scanf("%d", &n);

	char * words[n];
	hashtable_quadratic ht[n];
	for (int i = 0; i < n; i++)	{
		words[i] = malloc(BUFFER);
		scanf("%s", words[i]);
		ht[i] = (hashtable_quadratic) {calloc(INITIAL_SIZE, 1), 0, INITIAL_SIZE};

	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < strlen(words[i]); j++)
			hashinsert(words[i][j], &ht[i]);

	char * uniq[n];
	for (int i = 0; i < n; i++)	{
		uniq[i] = ht_to_array(&ht[i], uniq[i]);
		qsort(uniq[i], ht[i].size, 1, compare);
		for (int j = 0; j < ht[i].size; j++)
			printf("%c\t", *(uniq[i] + j));
		printf("\n");

	}

}
void hashinsert(char key, hashtable_quadratic * ht)
{
	int pos;
	pos = hash_quadratic(key, ht);
	
	int i;
	i = 0;
	while (*(ht->table + pos) && (i < ht->capacity))	{
		if (*(ht->table + pos) == key)
			return;
		pos = (pos + C1 * (++i) + C2 * (i ^ 2)) % ht->capacity;

	}
	if (i < ht->capacity)	{
		*(ht->table + pos) = key;
		ht->size++;

	}
	else	{
		char * arr;
		arr = ht_to_array(ht, arr);
		ht->capacity *= 2;
		char * tmp;
		tmp = NULL;
		while (!(tmp = realloc(ht->table, ht->capacity)));
		ht->table = tmp;
		
		ht->table = memset(ht->table, 0, ht->capacity);
		int oldsize;
		oldsize = ht->size;
		ht->size = 0;
		for (int i = 0; i < oldsize; i++)
			hashinsert(*(arr + i), ht);
		hashinsert(key, ht);

	}

}
Example #3
0
void hashinsert(char * key, hashtable_linear * ht)
{
	int pos;
	pos = hash_linear(key, ht);
	
	int i;
	i = 0;
	while (*(ht->table + pos) && (i < ht->capacity))	{
		if (!strcmp(*(ht->table + pos), key))
			return;
		pos = (pos + (++i)) % ht->capacity;

	}
	if (i < ht->capacity)	{
		*(ht->table + pos) = key;
		ht->size++;

	}
	else	{
		char ** arr;
		arr = ht_to_array(ht, arr);
		ht->capacity *= 2;
		char ** tmp;
		while (!(tmp = realloc(ht->table, ht->capacity * sizeof(char *))));
		ht->table = tmp;
		
		ht->table = memset(ht->table, 0, ht->capacity * sizeof(char *));
		int oldsize;
		oldsize = ht->size;
		ht->size = 0;
		for (int i = 0; i < oldsize; i++)
			hashinsert(*(arr + i), ht);
		hashinsert(key, ht);

	}

}
Example #4
0
void main()
{
	int n;
	scanf("%d", &n);

	char * word;
	hashtable_linear ht;
	ht = (hashtable_linear) {calloc(INITIAL_SIZE, sizeof(char *)), 0, INITIAL_SIZE};
	for (int i = 0; i < n; i++)	{
		word = malloc(BUFFER);
		scanf("%s", word);
		hashinsert(word, &ht);

	}

	printf("%d\n", ht.size);

}
void insert(int inode)
{
        void hashinsert(int);
        temp=first;
        ptr=temp;
        while(temp->link!=NULL)
        {
                if(temp->info==inode)
                {
                       ptr->link=temp->link;
                }
                ptr=temp;
                temp=temp->link;

        }
        printf("\n THE inode DELETED FROM THE FREE LIST AND ALLOCATED TO THE HASH QUEUE \n");
        display(inode);
        hashinsert(inode);
}
Example #6
0
boolean tablemakenewvalue (void) {
	
	/*
	create a new, empty value below the current cell.
	
	to get the node to be inserted below the current position, we use
	tableoverridesort to patch the comparenodes langglobals callback and 
	look for the next node in the table
	*/
	
	register hdlhashtable ht;
	bigstring bsname;
	tyvaluerecord val;
	short newrow;
	hdlhashnode hnode, hnext;
	register boolean fl;
	
	pushundoaction (undotypingstring);
	
	if (tableempty ())
		newrow = 0;
	else
		newrow = (**tableformatsdata).rowcursor + 1;
	
	ht = tablegetlinkedhashtable ();
	
	pushhashtable (ht);
	
	hashgetnthnode (ht, newrow, &hnext); /*ignore result -- will be nil if rowcursor is last*/
	
	tableoverridesort (hnext);
	
	setemptystring (bsname);
	
	clearbytes (&val, longsizeof (val));
	
	fl = hashinsert (bsname, val);
	
	assert (tablevalidate (ht, true));
	
	tablerestoresort ();
	
	// (**ht).flneedsort = true;
	
	pophashtable ();
	
	if (!fl)
		return (false);
	
	if (hashgetnthnode (ht, newrow, &hnode))
		pushundostep ((undocallback) tableredoclear, (Handle) hnode);
	
	if (!tableeditentercell (newrow, namecolumn)) {
		
		undolastaction (false);
		
		return (false);
		}
	
	return (true);
	} /*tablemakenewvalue*/