Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28718
Modified Files: Tag: devel_0_39 m_pd.h m_hash.c Log Message: more hashtable stuff
Index: m_pd.h =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_pd.h,v retrieving revision 1.4.4.11.2.19 retrieving revision 1.4.4.11.2.20 diff -C2 -d -r1.4.4.11.2.19 -r1.4.4.11.2.20 *** m_pd.h 21 Apr 2006 22:57:56 -0000 1.4.4.11.2.19 --- m_pd.h 21 Apr 2006 23:06:13 -0000 1.4.4.11.2.20 *************** *** 165,169 **** --- 165,172 ---- typedef void *hashkey; typedef void *hashvalue; + typedef void (*hash_iter)(void *data, hashkey k, hashvalue v); t_hash * hash_new(long capa); + long hash_size(t_hash *self); + void hash_each(t_hash *self, hash_iter f, void *data); hashvalue hash_get(t_hash *self, hashkey k); void hash_set(t_hash *self, hashkey k, hashvalue v);
Index: m_hash.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/m_hash.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** m_hash.c 21 Apr 2006 22:54:57 -0000 1.1.2.1 --- m_hash.c 21 Apr 2006 23:06:13 -0000 1.1.2.2 *************** *** 15,18 **** --- 15,19 ---- struct _hash { long capa; + long size; t_hashentry **tab; }; *************** *** 22,25 **** --- 23,27 ---- t_hash *self = (t_hash *)malloc(sizeof(t_hash)); self->capa = capa; + self->size = 0; self->tab = (t_hashentry **)malloc(capa*sizeof(void*)); for (i=0; i<capa; i++) self->tab[i]=0; *************** *** 27,31 **** }
! //t_hashentry *hash_find(t_hash *self, hashkey k) {}
static long hash_hash(t_hash *self, hashkey k) { --- 29,41 ---- }
! long hash_size(t_hash *self) {return self->size;} ! void hash_each(t_hash *self, hash_iter f, void *data) { ! long i; ! for (i=0; i<self->capa; i++) { ! t_hashentry *e; ! for (e=self->tab[i]; e; e=e->next) f(data,e->k,e->v); ! } ! } !
static long hash_hash(t_hash *self, hashkey k) { *************** *** 52,55 **** --- 62,66 ---- for (e=self->tab[h]; e; e=e->next) {if (e->k==k) {e->v=v; return;}} t_hashentry *nu = malloc(sizeof(t_hashentry)); + self->size++; nu->k=k; nu->v=v; *************** *** 65,69 **** hashvalue v=(*ep)->v; t_hashentry *next=(*ep)->next; ! free(*ep); *ep = next; return v; --- 76,80 ---- hashvalue v=(*ep)->v; t_hashentry *next=(*ep)->next; ! free(*ep); self->size--; *ep = next; return v;