[PD-cvs] pd/src m_pd.h, 1.4.4.11.2.33.2.66, 1.4.4.11.2.33.2.67 desire.h, 1.1.2.49.2.37, 1.1.2.49.2.38 kernel.c, 1.1.2.75, 1.1.2.76 desire.c, 1.1.2.217.2.177, 1.1.2.217.2.178 s_main.c, 1.7.4.17.2.22.2.29, 1.7.4.17.2.22.2.30

Mathieu Bouchard matju at users.sourceforge.net
Tue Jul 31 03:20:34 CEST 2007


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5363

Modified Files:
      Tag: desiredata
	m_pd.h desire.h kernel.c desire.c s_main.c 
Log Message:
t_hash becomes a class template


Index: m_pd.h
===================================================================
RCS file: /cvsroot/pure-data/pd/src/m_pd.h,v
retrieving revision 1.4.4.11.2.33.2.66
retrieving revision 1.4.4.11.2.33.2.67
diff -C2 -d -r1.4.4.11.2.33.2.66 -r1.4.4.11.2.33.2.67
*** m_pd.h	31 Jul 2007 00:42:34 -0000	1.4.4.11.2.33.2.66
--- m_pd.h	31 Jul 2007 01:20:29 -0000	1.4.4.11.2.33.2.67
***************
*** 12,15 ****
--- 12,82 ----
  #if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus)
  #include <iostream>
+ 
+ #ifdef __cplusplus
+ template <class K, class V> class t_hash /* : t_pd */ {
+ 	struct entry {
+ 		K k;
+ 		V v;
+ 		struct entry *next;
+ 	};
+ 	long capa;
+ 	long n;
+ 	entry **tab;
+ /* when iterating: */
+ 	long i;
+ 	entry *m_next;
+ public:
+ 	t_hash(long capa_) : capa(capa_), n(0), i(0) {
+ 		tab = new entry *[capa];
+ 		for (long j=0; j<capa; j++) tab[j]=0;
+ 	}
+ 	~t_hash() {delete[] tab;}
+ 	size_t size() {return n;}
+ 	V get(K k) {
+ 		long h = hash(k);
+ 		for (entry *e=tab[h]; e; e=e->next) {if (e->k==k) return e->v;}
+ 		return 0;
+ 	}
+ 	void set(K k, V v) {
+ 		long h = hash(k);
+ 		for (entry *e=tab[h]; e; e=e->next) {if (e->k==k) {e->v=v; return;}}
+ 		entry *nu = new entry; nu->k=k; nu->v=v; nu->next=tab[h];
+ 		n++;
+ 		tab[h] = nu;
+ 	}
+ 	V del(K k) {
+ 		long h = hash(k);
+ 		for (entry **ep=&tab[h]; *ep; ep=&(*ep)->next) {
+ 			if ((*ep)->k==k) {
+ 				V v=(*ep)->v;
+ 				entry *next=(*ep)->next;
+ 				delete *ep; n--;
+ 				*ep = next;
+ 				return v;
+ 			}
+ 		}
+ 		return 0;
+ 	}
+ 	int    exists(K k) {
+ 		long h = hash(k);
+ 		for (entry *e=tab[h]; e; e=e->next) {if (e->k==k) return 1;}
+ 		return 0;
+ 	}
+ 	void start() {i=0; m_next=0;}
+ 	int  next(K *kp, V *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;
+ 		}
+ 		return 0;
+ 	}
+ 	#define hash_foreach(k,v,h) for (h->start(); h->next(&k,&v); )
+ 	long hash(K k) {return (((long)k*0x54321) & 0x7FFFFFFF)%capa;}
+ };
+ #endif
+ 
  extern "C" {
  #endif
***************
*** 176,248 ****
  } t_atom;
  
! typedef void *hashkey;
! typedef void *hashvalue;
! 
! #ifdef __cplusplus
! struct t_hashentry {
! 	hashkey k;
! 	hashvalue v;
! 	struct t_hashentry *next;
! };
! 
! 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_) : capa(capa_), n(0), i(0) {
! 		tab = new t_hashentry *[capa];
! 		for (long j=0; j<capa; j++) tab[j]=0;
! 	}
! 	~t_hash() {delete[] tab;}
! 	size_t size() {return n;}
! 	hashvalue 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 set(hashkey k, hashvalue v) {
! 		long h = hash(k);
! 		for (t_hashentry *e=tab[h]; e; e=e->next) {if (e->k==k) {e->v=v; return;}}
! 		t_hashentry *nu = new t_hashentry; nu->k=k; nu->v=v; nu->next=tab[h];
! 		n++;
! 		tab[h] = nu;
! 	}
! 	hashvalue 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;
! 				delete *ep; n--;
! 				*ep = next;
! 				return v;
! 			}
! 		}
! 		return 0;
! 	}
! 	int    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;
! 	}
! 	void start() {i=0; m_next=0;}
! 	int  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;
! 		}
! 		return 0;
! 	}
! 	#define hash_foreach(k,v,h) for (h->start(); h->next(&k,&v); )
! 	long hash(hashkey k) {return (((long)k*0x54321) & 0x7FFFFFFF)%capa;}
! };
! #endif
  
  /* t_appendix is made of the things that logically ought to be in t_gobj but have been put in a
--- 243,247 ----
  } t_atom;
  
! struct t_arglist {long c; t_atom v[0];};
  
  /* t_appendix is made of the things that logically ought to be in t_gobj but have been put in a
***************
*** 257,261 ****
  /* miscellaneous */
  #ifdef __cplusplus
! 	t_hash *visual;
  #else
  	void *visual;
--- 256,260 ----
  /* miscellaneous */
  #ifdef __cplusplus
! 	t_hash<t_symbol *, t_arglist *> *visual;
  #else
  	void *visual;

Index: desire.h
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/desire.h,v
retrieving revision 1.1.2.49.2.37
retrieving revision 1.1.2.49.2.38
diff -C2 -d -r1.1.2.49.2.37 -r1.1.2.49.2.38
*** desire.h	30 Jul 2007 16:33:43 -0000	1.1.2.49.2.37
--- desire.h	31 Jul 2007 01:20:29 -0000	1.1.2.49.2.38
***************
*** 305,309 ****
  char* inlet_tip(t_inlet* i,int num);
  
! EXTERN t_hash *object_table;
  
  /* some kernel.c stuff that wasn't in any header, when shifting to C++. */
--- 305,310 ----
  char* inlet_tip(t_inlet* i,int num);
  
! extern t_hash<t_pd *,long> *object_table;
! extern t_hash<t_symbol *,t_class *> *class_table;
  
  /* some kernel.c stuff that wasn't in any header, when shifting to C++. */

Index: kernel.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/kernel.c,v
retrieving revision 1.1.2.75
retrieving revision 1.1.2.76
diff -C2 -d -r1.1.2.75 -r1.1.2.76
*** kernel.c	31 Jul 2007 00:42:34 -0000	1.1.2.75
--- kernel.c	31 Jul 2007 01:20:29 -0000	1.1.2.76
***************
*** 204,208 ****
  /* in which the value has bit 0 set if the key object is not a zombie,
     and has bit 1 set if the object has been uploaded to the client */
! t_hash *object_table;
  
  t_pd *pd_new(t_class *c) {
--- 204,208 ----
  /* in which the value has bit 0 set if the key object is not a zombie,
     and has bit 1 set if the object has been uploaded to the client */
! t_hash<t_pd *,long> *object_table;
  
  t_pd *pd_new(t_class *c) {
***************
*** 210,214 ****
      t_pd *x = (t_pd *)getbytes(c->size);
      x->_class = c;
!     object_table->set(x,(void*)1);
      if (c->gobj) ((t_gobj *)x)->g_adix = appendix_new((t_gobj *)x);
      if (c->patchable) {
--- 210,214 ----
      t_pd *x = (t_pd *)getbytes(c->size);
      x->_class = c;
!     object_table->set(x,1);
      if (c->gobj) ((t_gobj *)x)->g_adix = appendix_new((t_gobj *)x);
      if (c->patchable) {
***************
*** 238,242 ****
      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);
  }
--- 238,242 ----
      if (c->gobj && ((long)object_table->get(x)|2)) {
  	gobj_changed((t_gobj *)x,"");
! 	object_table->set(x,object_table->get(x)&~1);
      } else pd_free_zombie(x);
  }
***************
*** 862,866 ****
  #endif
  
! t_hash *class_table=0;
  static t_symbol *class_loadsym;     /* name under which an extern is invoked */
  static void pd_defaultfloat(t_pd *x, t_float f);
--- 862,866 ----
  #endif
  
! t_hash<t_symbol *, t_class *> *class_table=0;
  static t_symbol *class_loadsym;     /* name under which an extern is invoked */
  static void pd_defaultfloat(t_pd *x, t_float f);
***************
*** 2349,2353 ****
  void garray_init();
  void pd_init() {
!     object_table = new t_hash(127);
      bindlist_class = class_new(gensym("bindlist"), 0, 0, sizeof(t_bindlist), CLASS_PD, 0);
      class_addbang(bindlist_class, (t_method)bindlist_bang);
--- 2349,2353 ----
  void garray_init();
  void pd_init() {
!     object_table = new t_hash<t_pd *,long>(127);
      bindlist_class = class_new(gensym("bindlist"), 0, 0, sizeof(t_bindlist), CLASS_PD, 0);
      class_addbang(bindlist_class, (t_method)bindlist_bang);

Index: s_main.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_main.c,v
retrieving revision 1.7.4.17.2.22.2.29
retrieving revision 1.7.4.17.2.22.2.30
diff -C2 -d -r1.7.4.17.2.22.2.29 -r1.7.4.17.2.22.2.30
*** s_main.c	30 Jul 2007 20:16:34 -0000	1.7.4.17.2.22.2.29
--- s_main.c	31 Jul 2007 01:20:32 -0000	1.7.4.17.2.22.2.30
***************
*** 114,123 ****
  static void sys_afterargparse();
  
- EXTERN t_hash *class_table;
- 
  /* this is called from main() in s_entry.c */
  extern "C" int sys_main(int argc, char **argv) {
      int noprefs = 0, i;
!     class_table = new t_hash(127);
      /* jsarlo { */
      sys_externalschedlib = 0;
--- 114,121 ----
  static void sys_afterargparse();
  
  /* this is called from main() in s_entry.c */
  extern "C" int sys_main(int argc, char **argv) {
      int noprefs = 0, i;
!     class_table = new t_hash<t_symbol*,t_class*>(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.177
retrieving revision 1.1.2.217.2.178
diff -C2 -d -r1.1.2.217.2.177 -r1.1.2.217.2.178
*** desire.c	30 Jul 2007 19:56:26 -0000	1.1.2.217.2.177
--- desire.c	31 Jul 2007 01:20:29 -0000	1.1.2.217.2.178
***************
*** 71,79 ****
  // externals compiled for PureMSP.
  
! struct t_arglist {
! 	long c;
! 	long dummy;
! 	t_atom v[0];
! };
  
  t_appendix *appendix_new (t_gobj *master) {
--- 71,75 ----
  // externals compiled for PureMSP.
  
! typedef t_hash<t_symbol *, t_arglist *> t_visual;
  
  t_appendix *appendix_new (t_gobj *master) {
***************
*** 84,97 ****
  	self->nobs = 0;
  	self->obs = 0;
! 	self->visual = new t_hash(1);
  	return self;
  }
  
  void appendix_save (t_gobj *master, t_binbuf *b) {
! 	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;
  	    int i=0;
  	    binbuf_addv(b,"t","#V");
--- 80,93 ----
  	self->nobs = 0;
  	self->obs = 0;
! 	self->visual = new t_visual(1);
  	return self;
  }
  
  void appendix_save (t_gobj *master, t_binbuf *b) {
! 	t_visual *h = master->dix->visual;
  	//fprintf(stderr,"appendix_save %p size=%ld\n",master,hash_size(h));
  	if (h->size()) {
! 	    t_symbol *k;
! 	    t_arglist *v;
  	    int i=0;
  	    binbuf_addv(b,"t","#V");
***************
*** 109,116 ****
  void appendix_free (t_gobj *master) {
  	t_appendix *self = master->dix;
! 	hashkey k;
! 	hashvalue v;
  	if (self->visual) {
! 		hash_foreach(k,v,self->visual) {free(v);}
  		delete self->visual;
  	}
--- 105,112 ----
  void appendix_free (t_gobj *master) {
  	t_appendix *self = master->dix;
! 	t_symbol *k;
! 	t_arglist *v;
  	if (self->visual) {
! 		hash_foreach(k,v,self->visual) free(v);
  		delete self->visual;
  	}
***************
*** 264,272 ****
  // update manager:
  
  struct t_manager : t_text {
  	t_queue *q;
  	t_clock *clock;
  	t_binbuf *b; /* reusable, for processing messages from the gui */
! 	t_hash *dirty;
  };
  
--- 260,275 ----
  // update manager:
  
+ struct t_dirtyentry {
+ 	t_symbol *a[4];
+ 	t_dirtyentry() {a[0]=a[1]=a[2]=a[3]=0;}
+ };
+ 
+ typedef t_hash <t_gobj *, t_dirtyentry *> t_dirtyset;
+ 
  struct t_manager : t_text {
  	t_queue *q;
  	t_clock *clock;
  	t_binbuf *b; /* reusable, for processing messages from the gui */
! 	t_dirtyset *dirty;
  };
  
***************
*** 307,311 ****
  	self->b = binbuf_new();
  	clock_delay(self->clock,0);
! 	self->dirty = new t_hash(127);
  	return self;
  }
--- 310,314 ----
  	self->b = binbuf_new();
  	clock_delay(self->clock,0);
! 	self->dirty = new t_dirtyset(127);
  	return self;
  }
***************
*** 377,381 ****
  }
  
! void glob_setfilename(void *dummy, t_symbol *filesym, t_symbol *dirsym) {
      canvas_newfilename = filesym;
      canvas_newdirectory = dirsym;
--- 380,384 ----
  }
  
! void glob_setfilename(void *self, t_symbol *filesym, t_symbol *dirsym) {
      canvas_newfilename = filesym;
      canvas_newdirectory = dirsym;
***************
*** 494,498 ****
  /* make a new canvas.  It will either be a "root" canvas or else it appears as
     a "text" object in another window (canvas_getcurrent() tells us which.) */
! static t_canvas *canvas_new(void *dummy, t_symbol *sel, int argc, t_atom *argv) {
      t_canvas *x = canvas_new2();
      t_canvas *owner = canvas_getcurrent();
--- 497,501 ----
  /* make a new canvas.  It will either be a "root" canvas or else it appears as
     a "text" object in another window (canvas_getcurrent() tells us which.) */
! static t_canvas *canvas_new(void *self, t_symbol *sel, int argc, t_atom *argv) {
      t_canvas *x = canvas_new2();
      t_canvas *owner = canvas_getcurrent();
***************
*** 961,965 ****
  }
  
! extern "C" void glob_dsp(void *dummy, t_symbol *s, int argc, t_atom *argv) {
      if (argc) {
          int newstate = atom_getintarg(0, argc, argv);
--- 964,968 ----
  }
  
! extern "C" void glob_dsp(void *self, t_symbol *s, int argc, t_atom *argv) {
      if (argc) {
          int newstate = atom_getintarg(0, argc, argv);
***************
*** 6041,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");
  }
--- 6044,6048 ----
  	}
  	if (object_table->exists(self)) {
! 		object_table->set(self,object_table->get(self)|2); /* has been uploaded */
  	} else post("object_table is broken");
  }
***************
*** 6941,6945 ****
  		//printf("#V reading '%s':\n",s->name);
  		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);
--- 6944,6948 ----
  		//printf("#V reading '%s':\n",s->name);
  		if (!newest) {error("#V: there is no newest object\n"); return;}
! 		t_visual *h = ((t_gobj *)newest)->dix->visual;
  		if (h->exists(s)) {
  			//printf("'%s' exists, deleting\n",s->name);
***************
*** 6977,6983 ****
  }
  
- EXTERN t_hash *class_table;
  extern "C" void glob_update_class_list (t_pd *self, t_symbol *cb_recv, t_symbol *cb_sel) {
!     hashkey k; hashvalue v;
      sys_gui("global class_list; set class_list {");
      hash_foreach(k,v,class_table) sys_vgui("%s ", ((t_symbol *)k)->name);
--- 6980,6985 ----
  }
  
  extern "C" void glob_update_class_list (t_pd *self, t_symbol *cb_recv, t_symbol *cb_sel) {
!     t_symbol *k; t_class *v;
      sys_gui("global class_list; set class_list {");
      hash_foreach(k,v,class_table) sys_vgui("%s ", ((t_symbol *)k)->name);
***************
*** 7258,7268 ****
  /* tb } */
  
- extern t_hash *object_table;
- 
  static void glob_object_table() {
  	t_symbol *s_inlet = gensym("inlet");
  	t_symbol *s___list = gensym("__list");
  	size_t inlets=0, lists=0, zombies=0;
! 	hashkey k; hashvalue v;
  	post("object_table = {");
  	hash_foreach(k,v,object_table) {
--- 7260,7268 ----
  /* tb } */
  
  static void glob_object_table() {
  	t_symbol *s_inlet = gensym("inlet");
  	t_symbol *s___list = gensym("__list");
  	size_t inlets=0, lists=0, zombies=0;
! 	t_pd *k; long v;
  	post("object_table = {");
  	hash_foreach(k,v,object_table) {





More information about the Pd-cvs mailing list