[PD-cvs] pd/src kernel.c, 1.1.2.74, 1.1.2.75 m_pd.h, 1.4.4.11.2.33.2.65, 1.4.4.11.2.33.2.66

Mathieu Bouchard matju at users.sourceforge.net
Tue Jul 31 02:42:36 CEST 2007


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

Modified Files:
      Tag: desiredata
	kernel.c m_pd.h 
Log Message:
inlined all methods of t_hash


Index: m_pd.h
===================================================================
RCS file: /cvsroot/pure-data/pd/src/m_pd.h,v
retrieving revision 1.4.4.11.2.33.2.65
retrieving revision 1.4.4.11.2.33.2.66
diff -C2 -d -r1.4.4.11.2.33.2.65 -r1.4.4.11.2.33.2.66
*** m_pd.h	30 Jul 2007 20:11:15 -0000	1.4.4.11.2.33.2.65
--- m_pd.h	31 Jul 2007 00:42:34 -0000	1.4.4.11.2.33.2.66
***************
*** 194,208 ****
  	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
--- 194,246 ----
  	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

Index: kernel.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/kernel.c,v
retrieving revision 1.1.2.74
retrieving revision 1.1.2.75
diff -C2 -d -r1.1.2.74 -r1.1.2.75
*** kernel.c	30 Jul 2007 20:11:22 -0000	1.1.2.74
--- kernel.c	31 Jul 2007 00:42:34 -0000	1.1.2.75
***************
*** 108,168 ****
  
  t_class *hash_class;
- t_hash::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::~t_hash() {delete[] 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;
- 	}
- 	return 0;
- }
- 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 = new 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;
- 			delete *ep; n--;
- 			*ep = next;
- 			return v;
- 		}
- 	}
- 	return 0;
- }
  
  /*extern "C"*/ void hash_setup () {
--- 108,111 ----
***************
*** 267,271 ****
      t_pd *x = (t_pd *)getbytes(c->size);
      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);
--- 210,213 ----
***************
*** 2408,2412 ****
  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);
      class_addbang(bindlist_class, (t_method)bindlist_bang);
--- 2350,2353 ----





More information about the Pd-cvs mailing list