Author: EricStein
Date: 2007-07-08 16:15:07 -0400 (Sun, 08 Jul 2007)
New Revision: 426

Modified:
   trunk/pysoy/src/_datatypes/HashTable.pxi
   trunk/pysoy/src/_datatypes/soy._datatypes.pxd
Log:
Switched to exception on no key & added has_key


Modified: trunk/pysoy/src/_datatypes/HashTable.pxi
===================================================================
--- trunk/pysoy/src/_datatypes/HashTable.pxi    2007-07-08 19:57:24 UTC (rev 
425)
+++ trunk/pysoy/src/_datatypes/HashTable.pxi    2007-07-08 20:15:07 UTC (rev 
426)
@@ -24,6 +24,7 @@
   '''
   def __new__(self) :
     self._hashtable = glib.g_hash_table_new(glib.g_str_hash, glib.g_str_equal)
+    #self._hashtable = glib.g_hash_table_new_full(glib.g_str_hash, 
glib.g_str_equal, glib.g_free, glib.g_free)
 
   def __dealloc__(self) :
     glib.g_hash_table_destroy(self._hashtable)
@@ -46,5 +47,15 @@
     cdef float* f
     f = <float*> glib.g_hash_table_lookup(self._hashtable, key)
     if f == NULL :
-      return 0
+      raise RuntimeError('No such key')
     return f[0]
+
+  def has_key(self, key) :
+    if self._has_key(key) :
+      return True
+    else :
+      return False
+
+  cdef int _has_key(self, char* key) :
+    cdef glib.gpointer k, d
+    return glib.g_hash_table_lookup_extended(self._hashtable, key, &k, &d)

Modified: trunk/pysoy/src/_datatypes/soy._datatypes.pxd
===================================================================
--- trunk/pysoy/src/_datatypes/soy._datatypes.pxd       2007-07-08 19:57:24 UTC 
(rev 425)
+++ trunk/pysoy/src/_datatypes/soy._datatypes.pxd       2007-07-08 20:15:07 UTC 
(rev 426)
@@ -51,6 +51,7 @@
   cdef glib.GHashTable*  _hashtable
   cdef void              _insert(self, char*, float)
   cdef float             _lookup(self, char*)
+  cdef int               _has_key(self, char*)
 
 
 cdef class FaceList :

_______________________________________________
PySoy-SVN mailing list
[email protected]
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to