[PD-cvs] pd/src m_hash.c,NONE,1.1.2.1 SConscript,1.1.4.45,1.1.4.46

Mathieu Bouchard matju at users.sourceforge.net
Sat Apr 22 00:54:59 CEST 2006


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

Modified Files:
      Tag: devel_0_39
	SConscript 
Added Files:
      Tag: devel_0_39
	m_hash.c 
Log Message:
hashtable (for e.g. classlist)


--- NEW FILE: m_hash.c ---
/* independent hash table for PureData */
/* Copyright (c) 2006 Mathieu Bouchard */
/* Part of PureData devel_0_39 */
/* Licensed under SIBSD */

#include "m_pd.h"
#include <malloc.h>

typedef struct _hashentry {
	hashkey k;
	hashvalue v;
	struct _hashentry *next;
} t_hashentry;

struct _hash {
	long capa;
	t_hashentry **tab;
};

t_hash *hash_new(long capa) {
	long i;
	t_hash *self = (t_hash *)malloc(sizeof(t_hash));
	self->capa = capa;
	self->tab = (t_hashentry **)malloc(capa*sizeof(void*));
	for (i=0; i<capa; i++) self->tab[i]=0;
	return self;
}

//t_hashentry *hash_find(t_hash *self, hashkey k) {}

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);
	t_hashentry *e;
	for (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);
	t_hashentry *e;
	for (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 *e;
	for (e=self->tab[h]; e; e=e->next) {if (e->k==k) {e->v=v; return;}}
	t_hashentry *nu = malloc(sizeof(t_hashentry));
	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);
	t_hashentry **ep;
	for (ep=&self->tab[h]; *ep; ep=&(*ep)->next) {
		if ((*ep)->k==k) {
			hashvalue v=(*ep)->v;
			t_hashentry *next=(*ep)->next;
			free(*ep);
			*ep = next;
			return v;
		}
	}
	return 0;
}


Index: SConscript
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/SConscript,v
retrieving revision 1.1.4.45
retrieving revision 1.1.4.46
diff -C2 -d -r1.1.4.45 -r1.1.4.46
*** SConscript	20 Apr 2006 13:32:33 -0000	1.1.4.45
--- SConscript	21 Apr 2006 22:54:56 -0000	1.1.4.46
***************
*** 77,81 ****
  if pdenv['desire']:
      sources += Split("""
!         desire.c
      """)
  else:
--- 77,81 ----
  if pdenv['desire']:
      sources += Split("""
!         desire.c m_hash.c
      """)
  else:
***************
*** 179,183 ****
  #
  
! add_cpppath = []
  
  if pdenv['PLATFORM'] != 'win32':
--- 179,183 ----
  #
  
! add_cpppath = ["/usr/include/tcl8.4"]
  
  if pdenv['PLATFORM'] != 'win32':
***************
*** 202,206 ****
              print "can't find tk"
  
!     if not ( conf.CheckHeader('tcl.h') or
           conf.CheckHeader('tcl/tcl.h')
           ):  
--- 202,206 ----
              print "can't find tk"
  
!     if not (conf.CheckHeader('tcl.h') or
           conf.CheckHeader('tcl/tcl.h')
           ):  
***************
*** 211,215 ****
          else:
              print "can't find tcl header"
!         
      if not ( conf.CheckHeader('tk.h') or
           conf.CheckHeader('tk/tk.h')
--- 211,215 ----
          else:
              print "can't find tcl header"
! 
      if not ( conf.CheckHeader('tk.h') or
           conf.CheckHeader('tk/tk.h')
***************
*** 225,229 ****
              else:
                  print "can't find tk header"
!             
  
  if not conf.CheckLib(pthreadLib, 'pthread_create'):
--- 225,229 ----
              else:
                  print "can't find tk header"
! 
  
  if not conf.CheckLib(pthreadLib, 'pthread_create'):





More information about the Pd-cvs mailing list