Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9582
Modified Files: Tag: desiredata desire.c kernel.c s_main.c m_pd.h Log Message: t_hash interface is now a C++ class
Index: m_pd.h =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_pd.h,v retrieving revision 1.4.4.11.2.33.2.63 retrieving revision 1.4.4.11.2.33.2.64 diff -C2 -d -r1.4.4.11.2.33.2.63 -r1.4.4.11.2.33.2.64 *** m_pd.h 30 Jul 2007 19:12:45 -0000 1.4.4.11.2.33.2.63 --- m_pd.h 30 Jul 2007 19:56:29 -0000 1.4.4.11.2.33.2.64 *************** *** 182,209 **** hashkey k; hashvalue v; ! t_hashentry *next; };
! struct t_hash : t_pd { long capa; ! long size; t_hashentry **tab; /* when iterating: */ long i; ! t_hashentry *next; }; ! ! typedef void (*hash_iter)(void *data, hashkey k, hashvalue v); ! t_hash *hash_new(long capa); ! void hash_free(t_hash *self); ! long hash_size(t_hash *self); ! void hash_start(t_hash *self); ! int hash_next(t_hash *self, hashkey *kp, hashvalue *vp); ! #define hash_foreach(k,v,h) for (hash_start(h); hash_next(h,&k,&v); ) ! ! hashvalue hash_get(t_hash *self, hashkey k); ! void hash_set(t_hash *self, hashkey k, hashvalue v); ! hashvalue hash_delete(t_hash *self, hashkey k); ! int hash_exists(t_hash *self, hashkey k); /* check if a key exists */
/* t_appendix is made of the things that logically ought to be in t_gobj but have been put in a --- 182,210 ---- hashkey k; hashvalue v; ! struct t_hashentry *next; };
! #ifdef __cplusplus ! class t_hash /* : t_pd */ { long capa; ! long n; t_hashentry **tab; /* when iterating: */ long i; ! t_hashentry *m_next; ! public: ! t_hash(long capa); ! ~t_hash(); ! size_t size() {return n;} ! hashvalue get(hashkey k); ! void set(hashkey k, hashvalue v); ! hashvalue del(hashkey k); ! int exists(hashkey k); /* check if a key exists */ ! void start(); ! int next(hashkey *kp, hashvalue *vp); ! #define hash_foreach(k,v,h) for (h->start(); h->next(&k,&v); ) ! long t_hash::hash(hashkey k); }; ! #endif
/* t_appendix is made of the things that logically ought to be in t_gobj but have been put in a *************** *** 217,221 **** --- 218,226 ---- struct _gobj **obs; /* I spy with my little I */ /* miscellaneous */ + #ifdef __cplusplus t_hash *visual; + #else + void *visual; + #endif } t_appendix; t_appendix *appendix_new (struct _gobj *master);
Index: kernel.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/kernel.c,v retrieving revision 1.1.2.72 retrieving revision 1.1.2.73 diff -C2 -d -r1.1.2.72 -r1.1.2.73 *** kernel.c 30 Jul 2007 19:12:45 -0000 1.1.2.72 --- kernel.c 30 Jul 2007 19:56:29 -0000 1.1.2.73 *************** *** 108,136 **** t_class *hash_class;
! t_hash *hash_new(long capa) { ! t_hash *self = (t_hash *)malloc(sizeof(t_hash)); ! /* t_hash *self = (t_hash *)pd_new(hash_class);*/ ! self->capa = capa; ! self->size = 0; ! self->i = 0; ! self->tab = (t_hashentry **)malloc(capa*sizeof(void*)); ! for (long i=0; i<capa; i++) self->tab[i]=0; ! return self; }
! void hash_free(t_hash *self) { ! free(self->tab); ! free(self); }
! long hash_size(t_hash *self) {return self->size;} ! void hash_start(t_hash *self) {self->i=0; self->next=0;} ! int hash_next(t_hash *self, hashkey *kp, hashvalue *vp) { ! while (!self->next && self->i<self->capa) self->next = self->tab[self->i++]; ! // printf("hash_next found in bin %ld\n",self->i-1); ! if (self->next) { ! *kp = self->next->k; ! *vp = self->next->v; ! self->next = self->next->next; return 1; } --- 108,130 ---- t_class *hash_class;
! t_hash::t_hash(long capa_) { ! capa = capa_; ! n=0; ! i=0; ! tab = (t_hashentry **)malloc(capa*sizeof(void*)); ! for (long j=0; j<capa; j++) tab[j]=0; }
! t_hash::~t_hash() { ! free(tab); }
! void t_hash::start() {i=0; m_next=0;} ! int t_hash::next(hashkey *kp, hashvalue *vp) { ! while (!m_next && i<capa) m_next = tab[i++]; ! if (m_next) { ! *kp = m_next->k; ! *vp = m_next->v; ! m_next = m_next->next; return 1; } *************** *** 138,177 **** }
! static long hash_hash(t_hash *self, hashkey k) { long h = ((long)k*0x54321) & 0x7FFFFFFF; ! return h%self->capa; }
! int hash_exists(t_hash *self, hashkey k) { ! long h = hash_hash(self,k); ! for (t_hashentry *e=self->tab[h]; e; e=e->next) {if (e->k==k) return 1;} return 0; } ! hashvalue hash_get(t_hash *self, hashkey k) { ! long h = hash_hash(self,k); ! for (t_hashentry *e=self->tab[h]; e; e=e->next) {if (e->k==k) return e->v;} return 0; }
! void hash_set(t_hash *self, hashkey k, hashvalue v) { ! long h = hash_hash(self,k); t_hashentry *nu; ! // fprintf(stderr,"hash_set %p %s %p\n",self,((t_symbol*)k)->name,v); ! for (t_hashentry *e=self->tab[h]; e; e=e->next) {if (e->k==k) {e->v=v; return;}} nu = (t_hashentry *)malloc(sizeof(t_hashentry)); ! self->size++; nu->k=k; nu->v=v; ! nu->next=self->tab[h]; ! self->tab[h] = nu; }
! hashvalue hash_delete(t_hash *self, hashkey k) { ! long h = hash_hash(self,k); ! for (t_hashentry **ep=&self->tab[h]; *ep; ep=&(*ep)->next) { if ((*ep)->k==k) { hashvalue v=(*ep)->v; t_hashentry *next=(*ep)->next; ! free(*ep); self->size--; *ep = next; return v; --- 132,170 ---- }
! long t_hash::hash(hashkey k) { long h = ((long)k*0x54321) & 0x7FFFFFFF; ! return h%capa; }
! int t_hash::exists(hashkey k) { ! long h = hash(k); ! for (t_hashentry *e=tab[h]; e; e=e->next) {if (e->k==k) return 1;} return 0; } ! hashvalue t_hash::get(hashkey k) { ! long h = hash(k); ! for (t_hashentry *e=tab[h]; e; e=e->next) {if (e->k==k) return e->v;} return 0; }
! void t_hash::set(hashkey k, hashvalue v) { ! long h = hash(k); t_hashentry *nu; ! for (t_hashentry *e=tab[h]; e; e=e->next) {if (e->k==k) {e->v=v; return;}} nu = (t_hashentry *)malloc(sizeof(t_hashentry)); ! n++; nu->k=k; nu->v=v; ! nu->next=tab[h]; ! tab[h] = nu; }
! hashvalue t_hash::del(hashkey k) { ! long h = hash(k); ! for (t_hashentry **ep=&tab[h]; *ep; ep=&(*ep)->next) { if ((*ep)->k==k) { hashvalue v=(*ep)->v; t_hashentry *next=(*ep)->next; ! free(*ep); n--; *ep = next; return v; *************** *** 183,187 **** /*extern "C"*/ void hash_setup () { hash_class = class_new(gensym("#V"), (t_newmethod)0 /*hash_new*/, ! (t_method)hash_free, sizeof(t_object), CLASS_PD, A_GIMME, 0); }
--- 176,180 ---- /*extern "C"*/ void hash_setup () { hash_class = class_new(gensym("#V"), (t_newmethod)0 /*hash_new*/, ! 0 /*(t_method)hash_free*/, sizeof(t_object), CLASS_PD, A_GIMME, 0); }
*************** *** 283,287 **** x->_class = c; //fprintf(stderr,"object_table = %p\n",object_table); ! hash_set(object_table,x,(void*)1); if (c->gobj) ((t_gobj *)x)->g_adix = appendix_new((t_gobj *)x); if (c->patchable) { --- 276,280 ---- x->_class = c; //fprintf(stderr,"object_table = %p\n",object_table); ! object_table->set(x,(void*)1); if (c->gobj) ((t_gobj *)x)->g_adix = appendix_new((t_gobj *)x); if (c->patchable) { *************** *** 296,300 **** if (c->gobj) appendix_free((t_gobj *)x); if (c->size) free(x); ! hash_delete(object_table,x); }
--- 289,293 ---- if (c->gobj) appendix_free((t_gobj *)x); if (c->size) free(x); ! object_table->del(x); }
*************** *** 309,315 **** } /* schedule for deletion if need to keep the allocation around */ ! if (c->gobj && ((long)hash_get(object_table,x)|2)) { gobj_changed((t_gobj *)x,""); ! hash_set(object_table,x,(void *)((long)hash_get(object_table,x)&~1)); } else pd_free_zombie(x); } --- 302,308 ---- } /* schedule for deletion if need to keep the allocation around */ ! if (c->gobj && ((long)object_table->get(x)|2)) { gobj_changed((t_gobj *)x,""); ! object_table->set(x,(void *)((long)object_table->get(x)&~1)); } else pd_free_zombie(x); } *************** *** 1053,1057 **** class_addmethod2(pd_objectmaker._class, (t_method)newmethod, ss, sig); #endif ! hash_set(class_table, c->name, c); return c; } --- 1046,1050 ---- class_addmethod2(pd_objectmaker._class, (t_method)newmethod, ss, sig); #endif ! class_table->set(c->name, c); return c; } *************** *** 1067,1071 **** class_addmethod2(pd_objectmaker._class, (t_method)newmethod, pd_library_name ? qualified_name(s)->name : ss, sig); #endif ! hash_set(class_table,s,0); }
--- 1060,1064 ---- class_addmethod2(pd_objectmaker._class, (t_method)newmethod, pd_library_name ? qualified_name(s)->name : ss, sig); #endif ! class_table->set(s,0); }
*************** *** 1531,1535 **** /* only looks for already loaded classes though. */
! t_class *class_find (t_symbol *s) {return (t_class *)hash_get(class_table,s);}
void glob_update_class_info (t_pd *bogus, t_symbol *s, t_symbol *cb_recv, t_symbol *cb_sel) { --- 1524,1528 ---- /* only looks for already loaded classes though. */
! t_class *class_find (t_symbol *s) {return (t_class *)class_table->get(s);}
void glob_update_class_info (t_pd *bogus, t_symbol *s, t_symbol *cb_recv, t_symbol *cb_sel) { *************** *** 1990,1994 **** if (!sscanf(s->name,".x%lx",(long*)&target)) target=0; if (target) { ! if (!hash_exists(object_table,target) || !hash_get(object_table,target)) { error("%s target is not a currently valid pointer",s->name); return; --- 1983,1987 ---- if (!sscanf(s->name,".x%lx",(long*)&target)) target=0; if (target) { ! if (!object_table->exists(target) || !object_table->get(target)) { error("%s target is not a currently valid pointer",s->name); return; *************** *** 2422,2426 **** void garray_init(); void pd_init() { ! object_table = hash_new(127); //fprintf(stderr,"object_table = %p\n",object_table); bindlist_class = class_new(gensym("bindlist"), 0, 0, sizeof(t_bindlist), CLASS_PD, 0); --- 2415,2419 ---- void garray_init(); void pd_init() { ! object_table = new t_hash(127); //fprintf(stderr,"object_table = %p\n",object_table); bindlist_class = class_new(gensym("bindlist"), 0, 0, sizeof(t_bindlist), CLASS_PD, 0);
Index: s_main.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/s_main.c,v retrieving revision 1.7.4.17.2.22.2.27 retrieving revision 1.7.4.17.2.22.2.28 diff -C2 -d -r1.7.4.17.2.22.2.27 -r1.7.4.17.2.22.2.28 *** s_main.c 20 Jul 2007 05:40:50 -0000 1.7.4.17.2.22.2.27 --- s_main.c 30 Jul 2007 19:56:29 -0000 1.7.4.17.2.22.2.28 *************** *** 119,123 **** extern "C" int sys_main(int argc, char **argv) { int noprefs = 0, i; ! class_table = hash_new(127); /* jsarlo { */ sys_externalschedlib = 0; --- 119,123 ---- extern "C" int sys_main(int argc, char **argv) { int noprefs = 0, i; ! class_table = new t_hash(127); /* jsarlo { */ sys_externalschedlib = 0;
Index: desire.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/desire.c,v retrieving revision 1.1.2.217.2.176 retrieving revision 1.1.2.217.2.177 diff -C2 -d -r1.1.2.217.2.176 -r1.1.2.217.2.177 *** desire.c 30 Jul 2007 16:33:40 -0000 1.1.2.217.2.176 --- desire.c 30 Jul 2007 19:56:26 -0000 1.1.2.217.2.177 *************** *** 84,88 **** self->nobs = 0; self->obs = 0; ! self->visual = hash_new(1); return self; } --- 84,88 ---- self->nobs = 0; self->obs = 0; ! self->visual = new t_hash(1); return self; } *************** *** 91,95 **** t_hash *h = master->dix->visual; //fprintf(stderr,"appendix_save %p size=%ld\n",master,hash_size(h)); ! if (hash_size(h)) { hashkey k; hashvalue v; --- 91,95 ---- t_hash *h = master->dix->visual; //fprintf(stderr,"appendix_save %p size=%ld\n",master,hash_size(h)); ! if (h->size()) { hashkey k; hashvalue v; *************** *** 100,104 **** binbuf_addv(b,"s",k); binbuf_add(b,al->c,al->v); ! if (i+1==hash_size(h)) binbuf_addv(b, ";"); else binbuf_addv(b,"t",","); i++; --- 100,104 ---- binbuf_addv(b,"s",k); binbuf_add(b,al->c,al->v); ! if (size_t(i+1)==h->size()) binbuf_addv(b, ";"); else binbuf_addv(b,"t",","); i++; *************** *** 113,117 **** if (self->visual) { hash_foreach(k,v,self->visual) {free(v);} ! hash_free(self->visual); } free(self); --- 113,117 ---- if (self->visual) { hash_foreach(k,v,self->visual) {free(v);} ! delete self->visual; } free(self); *************** *** 284,290 **** pd_free(o); } else { ! if (hash_exists(self->dirty,o)) { pd_upload(o); ! hash_delete(self->dirty,o); } } --- 284,290 ---- pd_free(o); } else { ! if (self->dirty->exists(o)) { pd_upload(o); ! self->dirty->del(o); } } *************** *** 295,301 **** void manager_notice (t_gobj *self_, t_gobj *origin, int argc, t_atom *argv) { t_manager *self = (t_manager *)self_; ! if (!hash_exists(self->dirty,origin)) { queue_put(self->q,origin); ! hash_set(self->dirty,origin,0); } } --- 295,301 ---- void manager_notice (t_gobj *self_, t_gobj *origin, int argc, t_atom *argv) { t_manager *self = (t_manager *)self_; ! if (!self->dirty->exists(origin)) { queue_put(self->q,origin); ! self->dirty->set(origin,0); } } *************** *** 307,311 **** self->b = binbuf_new(); clock_delay(self->clock,0); ! self->dirty = hash_new(127); return self; } --- 307,311 ---- self->b = binbuf_new(); clock_delay(self->clock,0); ! self->dirty = new t_hash(127); return self; } *************** *** 5662,5666 **** t_text *o; if (sscanf(s->name,"x%lx",(long*)&o)<1) {error("expected object-id"); return 0;} ! if (!hash_exists(object_table,o) || !(long)hash_get(object_table,o)&1) { error("%s target is not a currently valid pointer",s->name); return 0; --- 5662,5666 ---- t_text *o; if (sscanf(s->name,"x%lx",(long*)&o)<1) {error("expected object-id"); return 0;} ! if (!object_table->exists(o) || !(long)object_table->get(o)&1) { error("%s target is not a currently valid pointer",s->name); return 0; *************** *** 5981,5985 ****
void pd_upload(t_gobj *self) { ! long alive = (long)hash_get(object_table,self) & 1; if (!alive) { sys_mgui(self,"delete",""); --- 5981,5985 ----
void pd_upload(t_gobj *self) { ! long alive = (long)object_table->get(self) & 1; if (!alive) { sys_mgui(self,"delete",""); *************** *** 6040,6045 **** } } ! if (hash_exists(object_table,self)) { ! hash_set(object_table,self,(void *)((long)hash_get(object_table,self)|2)); /* has been uploaded */ } else post("object_table is broken"); } --- 6040,6045 ---- } } ! if (object_table->exists(self)) { ! object_table->set(self,(void *)((long)object_table->get(self)|2)); /* has been uploaded */ } else post("object_table is broken"); } *************** *** 6942,6950 **** if (!newest) {error("#V: there is no newest object\n"); return;} t_hash *h = ((t_gobj *)newest)->dix->visual; ! if (hash_exists(h,s)) { //printf("'%s' exists, deleting\n",s->name); ! free(hash_get(h,s)); } ! hash_set(h,s,al); //fprintf(stderr,"visualloader... %p %d\n",newest,hash_size(h)); j++; --- 6942,6950 ---- if (!newest) {error("#V: there is no newest object\n"); return;} t_hash *h = ((t_gobj *)newest)->dix->visual; ! if (h->exists(s)) { //printf("'%s' exists, deleting\n",s->name); ! free(h->get(s)); } ! h->set(s,al); //fprintf(stderr,"visualloader... %p %d\n",newest,hash_size(h)); j++; *************** *** 7281,7285 **** } post("} (%ld non-omitted objects, plus %ld [inlet], plus %ld [__list], plus %ld zombies)", ! hash_size(object_table)-inlets-lists-zombies,inlets,lists,zombies); }
--- 7281,7285 ---- } post("} (%ld non-omitted objects, plus %ld [inlet], plus %ld [__list], plus %ld zombies)", ! object_table->size()-inlets-lists-zombies,inlets,lists,zombies); }