• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

include/hash_table.h

Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
00002 /* ====================================================================
00003  * Copyright (c) 1999-2004 Carnegie Mellon University.  All rights
00004  * reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer. 
00012  *
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in
00015  *    the documentation and/or other materials provided with the
00016  *    distribution.
00017  *
00018  * This work was supported in part by funding from the Defense Advanced 
00019  * Research Projects Agency and the National Science Foundation of the 
00020  * United States of America, and the CMU Sphinx Speech Consortium.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 
00023  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00024  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00025  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
00026  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00029  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00030  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00031  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00032  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * ====================================================================
00035  *
00036  */
00037 /*
00038  * hash.h -- Hash table module.
00039  *
00040  * **********************************************
00041  * CMU ARPA Speech Project
00042  *
00043  * Copyright (c) 1999 Carnegie Mellon University.
00044  * ALL RIGHTS RESERVED.
00045  * **********************************************
00046  * 
00047  * HISTORY
00048  * $Log: hash.h,v $
00049  * Revision 1.7  2005/06/22 03:04:01  arthchan2003
00050  * 1, Implemented hash_delete and hash_display, 2, Fixed doxygen documentation, 3, Added  keyword.
00051  *
00052  * Revision 1.8  2005/05/24 01:10:54  archan
00053  * Fix a bug when the value only appear in the hash but there is no chain.   Also make sure that prev was initialized to NULL. All success cases were tested, but not tested with the deletion is tested.
00054  *
00055  * Revision 1.7  2005/05/24 00:12:31  archan
00056  * Also add function prototype for hash_display in hash.h
00057  *
00058  * Revision 1.4  2005/05/03 04:09:11  archan
00059  * Implemented the heart of word copy search. For every ci-phone, every word end, a tree will be allocated to preserve its pathscore.  This is different from 3.5 or below, only the best score for a particular ci-phone, regardless of the word-ends will be preserved at every frame.  The graph propagation will not collect unused word tree at this point. srch_WST_propagate_wd_lv2 is also as the most stupid in the century.  But well, after all, everything needs a start.  I will then really get the results from the search and see how it looks.
00060  *
00061  * Revision 1.3  2005/03/30 01:22:48  archan
00062  * Fixed mistakes in last updates. Add
00063  *
00064  * 
00065  * 05-May-1999  M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon
00066  *              Removed hash_key2hash().  Added hash_enter_bkey() and hash_lookup_bkey(),
00067  *              and len attribute to hash_entry_t.
00068  * 
00069  * 30-Apr-1999  M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon
00070  *              Added hash_key2hash().
00071  * 
00072  * 18-Jun-97    M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon
00073  *              Included case sensitive/insensitive option.
00074  * 
00075  * 08-31-95     M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon
00076  *              Created.
00077  */
00078 
00079 
00124 #ifndef _LIBUTIL_HASH_H_
00125 #define _LIBUTIL_HASH_H_
00126 
00127 /* Win32/WinCE DLL gunk */
00128 #include <sphinxbase_export.h>
00129 #include <prim_type.h>
00130 #include <glist.h>
00131 
00132 #ifdef __cplusplus
00133 extern "C" {
00134 #endif
00135 #if 0
00136 /* Fool Emacs. */
00137 }
00138 #endif
00139 
00149 typedef struct hash_entry_s {
00150         const char *key;                
00153         size_t len;                     
00155         void *val;                      
00156         struct hash_entry_s *next;      
00157 } hash_entry_t;
00158 
00159 typedef struct {
00160         hash_entry_t *table;    
00161         int32 size;             
00164         int32 inuse;            
00165         int32 nocase;           
00166 } hash_table_t;
00167 
00168 typedef struct hash_iter_s {
00169         hash_table_t *ht;  
00170         hash_entry_t *ent; 
00171         size_t idx;        
00172 } hash_iter_t;
00173 
00175 #define hash_entry_val(e)       ((e)->val)
00176 #define hash_entry_key(e)       ((e)->key)
00177 #define hash_entry_len(e)       ((e)->len)
00178 #define hash_table_inuse(h)     ((h)->inuse)
00179 #define hash_table_size(h)      ((h)->size)
00180 
00181 
00190 SPHINXBASE_EXPORT
00191 hash_table_t * hash_table_new(int32 size,       
00192                               int32 casearg     
00195     );
00196 
00197 #define HASH_CASE_YES           0
00198 #define HASH_CASE_NO            1
00199 
00204 SPHINXBASE_EXPORT
00205 void hash_table_free(hash_table_t *h 
00206     );
00207 
00208 
00215 SPHINXBASE_EXPORT
00216 void *hash_table_enter(hash_table_t *h, 
00217                        const char *key, 
00219                        void *val          
00220     );
00221 
00228 #define hash_table_enter_int32(h,k,v) \
00229     ((int32)(long)hash_table_enter((h),(k),(void *)(long)(v)))
00230 
00244 SPHINXBASE_EXPORT
00245 void *hash_table_replace(hash_table_t *h, 
00246                          const char *key, 
00248                          void *val        
00249     );
00250 
00257 #define hash_table_replace_int32(h,k,v) \
00258     ((int32)(long)hash_table_replace((h),(k),(void *)(long)(v)))
00259 
00265 SPHINXBASE_EXPORT
00266 void *hash_table_delete(hash_table_t *h,    
00268                         const char *key     
00270         );
00271 
00275 SPHINXBASE_EXPORT
00276 void hash_table_empty(hash_table_t *h    
00277     );
00278 
00286 SPHINXBASE_EXPORT
00287 void *hash_table_enter_bkey(hash_table_t *h,    
00289                               const char *key,  
00290                               size_t len,       
00291                               void *val         
00292         );
00293 
00300 #define hash_table_enter_bkey_int32(h,k,l,v) \
00301     ((int32)(long)hash_table_enter_bkey((h),(k),(l),(void *)(long)(v)))
00302 
00303 
00309 SPHINXBASE_EXPORT
00310 int32 hash_table_lookup(hash_table_t *h,        
00311                         const char *key,        
00312                         void **val              
00314         );
00315 
00322 SPHINXBASE_EXPORT
00323 int32 hash_table_lookup_int32(hash_table_t *h,  
00324                               const char *key,  
00325                               int32 *val        
00327         );
00328 
00335 SPHINXBASE_EXPORT
00336 int32 hash_table_lookup_bkey(hash_table_t *h,   
00337                              const char *key,   
00338                              size_t len,        
00339                              void **val         
00341         );
00342 
00349 SPHINXBASE_EXPORT
00350 int32 hash_table_lookup_bkey_int32(hash_table_t *h,
00351                                    const char *key,
00352                                    size_t len,  
00353                                    int32 *val   
00355         );
00356 
00360 SPHINXBASE_EXPORT
00361 hash_iter_t *hash_table_iter(hash_table_t *h);
00362 
00371 SPHINXBASE_EXPORT
00372 hash_iter_t *hash_table_iter_next(hash_iter_t *itor);
00373 
00377 SPHINXBASE_EXPORT
00378 void hash_table_iter_free(hash_iter_t *itor);
00379 
00383 SPHINXBASE_EXPORT
00384 glist_t hash_table_tolist(hash_table_t *h,      
00385                           int32 *count          
00388         );
00389 
00395 SPHINXBASE_EXPORT
00396 void  hash_table_display(hash_table_t *h, 
00397                          int32 showkey    
00400         );
00401 
00402 #ifdef __cplusplus
00403 }
00404 #endif
00405 
00406 #endif

Generated on Fri Jan 14 2011 for SphinxBase by  doxygen 1.7.1