#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

/*struct tabelem {
 * char *key;
 * void *info;
 * }
 *
 * struct telist {
 * struct tabelem *el;
 * struct telist *next;
 * }
 * */

/*DEFINIRE DIM_MAX && MAX_DIM(memo)*/

struct telist hashtab[DIM_MAX];
typedef hashtab* HASHTABLE;

struct telist* init_list ()
{
	struct telist *p;
	p=calloc(1,sizeof(struct telist));
	return p;
}

struct telist* ins_list(struct tabelem *t, struct telist *p)
{
	struct telist *q;
	assert(p);
	assert(t);
	if (!p->el)
	{
		p->el=&t;
		return p;
	}
	q=calloc(1,sizeof(struct telist));
	q->el=&t;
	q->next=&p;
	return q;
}

struct tabelem *init_tabelem(char *key, void *info)
{
	struct tabelem *p;
	assert(key);
	assert(info);
	p=calloc(1,sizeof(struct tabelem));
	p->key=(*key);
	p->info=(*info);
	return p;
}

struct tabelem* cerca_lista(char* key, struct telist *p)
{
	
	assert(key);
	assert(p);
	while((p->el)->key!=key)
	{
		p=p->next;
		if(p->next==NULL) return NULL;
	}
	return (p->el);
}

int hash_key(char* key)
{
	int a, z, q, k;
	z=0;
	assert(key);
	for (k=0; key!='\0'; k++, key++)
	{
		for(q=0; q<=k; q++)
		    a=('key'*256)%DIM_MAX;
	        z+=a;
	        z=z%DIM_MAX;
	}
	return z;
}

