SphinxBase 0.6
|
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/sphinxbase_export.h> 00129 #include <sphinxbase/prim_type.h> 00130 #include <sphinxbase/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 00279 SPHINXBASE_EXPORT 00280 void *hash_table_delete_bkey(hash_table_t *h, 00282 const char *key, 00284 size_t len 00285 ); 00286 00290 SPHINXBASE_EXPORT 00291 void hash_table_empty(hash_table_t *h 00292 ); 00293 00301 SPHINXBASE_EXPORT 00302 void *hash_table_enter_bkey(hash_table_t *h, 00304 const char *key, 00305 size_t len, 00306 void *val 00307 ); 00308 00315 #define hash_table_enter_bkey_int32(h,k,l,v) \ 00316 ((int32)(long)hash_table_enter_bkey((h),(k),(l),(void *)(long)(v))) 00317 00325 SPHINXBASE_EXPORT 00326 void *hash_table_replace_bkey(hash_table_t *h, 00327 const char *key, 00328 size_t len, 00329 void *val 00330 ); 00331 00338 #define hash_table_replace_bkey_int32(h,k,l,v) \ 00339 ((int32)(long)hash_table_replace_bkey((h),(k),(l),(void *)(long)(v))) 00340 00346 SPHINXBASE_EXPORT 00347 int32 hash_table_lookup(hash_table_t *h, 00348 const char *key, 00349 void **val 00351 ); 00352 00359 SPHINXBASE_EXPORT 00360 int32 hash_table_lookup_int32(hash_table_t *h, 00361 const char *key, 00362 int32 *val 00364 ); 00365 00372 SPHINXBASE_EXPORT 00373 int32 hash_table_lookup_bkey(hash_table_t *h, 00374 const char *key, 00375 size_t len, 00376 void **val 00378 ); 00379 00386 SPHINXBASE_EXPORT 00387 int32 hash_table_lookup_bkey_int32(hash_table_t *h, 00388 const char *key, 00389 size_t len, 00390 int32 *val 00392 ); 00393 00397 SPHINXBASE_EXPORT 00398 hash_iter_t *hash_table_iter(hash_table_t *h); 00399 00408 SPHINXBASE_EXPORT 00409 hash_iter_t *hash_table_iter_next(hash_iter_t *itor); 00410 00414 SPHINXBASE_EXPORT 00415 void hash_table_iter_free(hash_iter_t *itor); 00416 00420 SPHINXBASE_EXPORT 00421 glist_t hash_table_tolist(hash_table_t *h, 00422 int32 *count 00425 ); 00426 00432 SPHINXBASE_EXPORT 00433 void hash_table_display(hash_table_t *h, 00434 int32 showkey 00437 ); 00438 00439 #ifdef __cplusplus 00440 } 00441 #endif 00442 00443 #endif