]> git.donarmstrong.com Git - biopieces.git/blobdiff - code_c/Maasha/src/inc/hash.h
added barray.c and cleaned hash.c
[biopieces.git] / code_c / Maasha / src / inc / hash.h
index bd96c265df25aeef30404ae84faeb65925857256..50ef219502e514116c7ab8a057ade51b9fdc4983 100644 (file)
@@ -3,9 +3,9 @@
 /* Structure of a generic hash element. */
 struct _hash_elem
 {
-    struct _hash_elem *next;
-    char              *key;
-    void              *val;
+    struct _hash_elem *next;   /* Hash elements constitue a sigly linked list. */
+    char              *key;    /* Hash key. */
+    void              *val;    /* Hash val. */
 };
 
 typedef struct _hash_elem hash_elem;
@@ -13,36 +13,39 @@ typedef struct _hash_elem hash_elem;
 /* Structure of a generic hash. */
 struct _hash
 {
-    hash_elem **table;
-    uint        mask;
-    int         table_size;
-    int         elem_count;
+    hash_elem **table;        /* Hash table. */
+    size_t      mask;         /* Mask to trim hashed keys. */
+    size_t      table_size;   /* Size of hash table. */
+    size_t      nmemb;        /* Number of elements in hash table. */
 };
 
 typedef struct _hash hash;
 
 /* Initialize a new generic hash structure. */
-void hash_new( hash **hash_pt, size_t size );
+hash *hash_new( size_t size );
 
-/* Hash function that generates a hash key, */
-uint       hash_key( char *string );
+/* Initializes a new hash_elem structure. */
+hash_elem *hash_elem_new();
+
+/* Hash function that generates a hash key. */
+uint hash_key( char *string );
 
 /* Add a new hash element consisting of a key/value pair to an existing hash. */
-void       hash_add( hash *hash_pt, char *key, void *val );
+void hash_add( hash *hash_pt, char *key, void *val );
 
 /* Lookup a key in a given hash and return the value - or NULL if not found. */
-void      *hash_get( hash *hash_pt, char *key );
+void *hash_get( hash *hash_pt, char *key );
 
 /* Lookup a key in a given hash and return the hash element - or NULL if not found. */
-hash_elem *hash_get_elem( hash *hash_pt, char *key );
-
-/* Remove key/value pair from a given hash. Returns true if a remove was successful. */
-bool       hash_del( hash *hash_pt, char *key );
+hash_elem *hash_elem_get( hash *hash_pt, char *key );
 
 /* Deallocate memory for hash and all hash elements. */
-void       hash_destroy( hash *hash_pt );
+void hash_destroy( hash *hash_pt );
+
+/* Debug function that prints hash meta data and all hash elements. */
+void hash_print( hash *hash_pt );
 
 /* Output some collision stats for a given hash. */
-void       hash_collision_stats( hash *hash_pt );
+void hash_collision_stats( hash *hash_pt );