PocketSphinx
0.6
|
00001 /* ==================================================================== 00002 * Copyright (c) 1999-2004 Carnegie Mellon University. All rights 00003 * reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 00009 * 1. Redistributions of source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 00012 * 2. Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in 00014 * the documentation and/or other materials provided with the 00015 * distribution. 00016 * 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 00019 * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 00020 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00021 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY 00022 * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00023 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00024 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00025 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00026 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00028 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 * ==================================================================== 00031 * 00032 */ 00033 00034 /* 00035 * blkarray_list.h -- array-based list structure, for memory and access 00036 * efficiency. 00037 * 00038 * HISTORY 00039 * 00040 * $Log: blkarray_list.h,v $ 00041 * Revision 1.1.1.1 2006/05/23 18:45:02 dhuggins 00042 * re-importation 00043 * 00044 * Revision 1.2 2004/12/10 16:48:58 rkm 00045 * Added continuous density acoustic model handling 00046 * 00047 * Revision 1.1 2004/07/16 00:57:12 egouvea 00048 * Added Ravi's implementation of FSG support. 00049 * 00050 * Revision 1.2 2004/05/27 14:22:57 rkm 00051 * FSG cross-word triphones completed (but for single-phone words) 00052 * 00053 * Revision 1.1.1.1 2004/03/01 14:30:31 rkm 00054 * 00055 * 00056 * Revision 1.1 2004/02/26 01:14:48 rkm 00057 * *** empty log message *** 00058 * 00059 * 00060 * 18-Feb-2004 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon 00061 * Started. 00062 */ 00063 00064 00065 #ifndef __S2_BLKARRAY_LIST_H__ 00066 #define __S2_BLKARRAY_LIST_H__ 00067 00068 00069 #include <sphinxbase/prim_type.h> 00070 00071 00072 /* 00073 * For maintaining a (conceptual) "list" of pointers to arbitrary data. 00074 * The application is responsible for knowing the true data type. 00075 * Use an array instead of a true list for efficiency (both memory and 00076 * speed). But use a blocked (2-D) array to allow dynamic resizing at a 00077 * coarse grain. An entire block is allocated or freed, as appropriate. 00078 */ 00079 typedef struct blkarray_list_s { 00080 void ***ptr; /* ptr[][] is the user-supplied ptr */ 00081 int32 maxblks; /* size of ptr (#rows) */ 00082 int32 blksize; /* size of ptr[] (#cols, ie, size of each row) */ 00083 int32 n_valid; /* # entries actually stored in the list */ 00084 int32 cur_row; /* The current row being that has empty entry */ 00085 int32 cur_row_free; /* First entry valid within the current row */ 00086 } blkarray_list_t; 00087 00088 /* Access macros */ 00089 #define blkarray_list_ptr(l,r,c) ((l)->ptr[r][c]) 00090 #define blkarray_list_maxblks(l) ((l)->maxblks) 00091 #define blkarray_list_blksize(l) ((l)->blksize) 00092 #define blkarray_list_n_valid(l) ((l)->n_valid) 00093 #define blkarray_list_cur_row(l) ((l)->cur_row) 00094 #define blkarray_list_cur_row_free(l) ((l)->cur_row_free) 00095 00096 00097 /* 00098 * Initialize and return a new blkarray_list containing an empty list 00099 * (i.e., 0 length). Sized for the given values of maxblks and blksize. 00100 * NOTE: (maxblks * blksize) should not overflow int32, but this is not 00101 * checked. 00102 * Return the allocated entry if successful, NULL if any error. 00103 */ 00104 blkarray_list_t *_blkarray_list_init (int32 maxblks, int32 blksize); 00105 00106 00107 /* 00108 * Like _blkarray_list_init() above, but for some default values of 00109 * maxblks and blksize. 00110 */ 00111 blkarray_list_t *blkarray_list_init ( void ); 00112 00116 void blkarray_list_free(blkarray_list_t *bl); 00117 00118 00119 /* 00120 * Append the given new entry (data) to the end of the list. 00121 * Return the index of the entry if successful, -1 if any error. 00122 * The returned indices are guaranteed to be successive integers (i.e., 00123 * 0, 1, 2...) for successive append operations, until the list is reset, 00124 * when they resume from 0. 00125 */ 00126 int32 blkarray_list_append (blkarray_list_t *, void *data); 00127 00128 00129 /* 00130 * Free all the entries in the list (using ckd_free) and reset the 00131 * list length to 0. 00132 */ 00133 void blkarray_list_reset (blkarray_list_t *); 00134 00135 00136 #endif