blkarray_list.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  *
00019  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 
00020  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
00021  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00022  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
00023  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00025  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00026  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00027  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00029  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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$
00041  * Revision 1.1  2006/04/05  20:27:30  dhdfu
00042  * A Great Reorganzation of header files and executables
00043  * 
00044  * Revision 1.2  2006/02/23 05:10:18  arthchan2003
00045  * Merged from branch SPHINX3_5_2_RCI_IRII_BRANCH: Adaptation of Sphinx 2's FSG search into Sphinx 3
00046  *
00047  * Revision 1.1.2.1  2005/06/27 05:26:29  arthchan2003
00048  * Sphinx 2 fsg mainpulation routines.  Compiled with faked functions.  Currently fended off from users.
00049  *
00050  * Revision 1.1  2004/07/16 00:57:12  egouvea
00051  * Added Ravi's implementation of FSG support.
00052  *
00053  * Revision 1.2  2004/05/27 14:22:57  rkm
00054  * FSG cross-word triphones completed (but for single-phone words)
00055  *
00056  * Revision 1.1.1.1  2004/03/01 14:30:31  rkm
00057  *
00058  *
00059  * Revision 1.1  2004/02/26 01:14:48  rkm
00060  * *** empty log message ***
00061  *
00062  * 
00063  * 18-Feb-2004  M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon
00064  *              Started.
00065  */
00066 
00067 
00068 #ifndef __S2_BLKARRAY_LIST_H__
00069 #define __S2_BLKARRAY_LIST_H__
00070 
00071 
00072 #include <s3types.h>
00073 
00074 
00075 #ifdef __cplusplus
00076 extern "C" {
00077 #endif
00078 #if 0
00079 /* Fool Emacs. */
00080 }
00081 #endif
00082 
00083 /*
00084  * For maintaining a (conceptual) "list" of pointers to arbitrary data.
00085  * The application is responsible for knowing the true data type.
00086  * Use an array instead of a true list for efficiency (both memory and
00087  * speed).  But use a blocked (2-D) array to allow dynamic resizing at a
00088  * coarse grain.  An entire block is allocated or freed, as appropriate.
00089  */
00090 typedef struct blkarray_list_s {
00091     void ***ptr;                /* ptr[][] is the user-supplied ptr */
00092     int32 maxblks;      /* size of ptr (#rows) */
00093     int32 blksize;      /* size of ptr[] (#cols, ie, size of each row) */
00094     int32 n_valid;      /* # entries actually stored in the list */
00095     int32 cur_row;      /* The current row being that has empty entry */
00096     int32 cur_row_free; /* First entry valid within the current row */
00097 } blkarray_list_t;
00098 
00099 /* Access macros */
00100 #define blkarray_list_ptr(l,r,c)        ((l)->ptr[r][c])
00101 #define blkarray_list_maxblks(l)        ((l)->maxblks)
00102 #define blkarray_list_blksize(l)        ((l)->blksize)
00103 #define blkarray_list_n_valid(l)        ((l)->n_valid)
00104 #define blkarray_list_cur_row(l)        ((l)->cur_row)
00105 #define blkarray_list_cur_row_free(l)   ((l)->cur_row_free)
00106 
00107 
00108 /*
00109  * Initialize and return a new blkarray_list containing an empty list
00110  * (i.e., 0 length).  Sized for the given values of maxblks and blksize.
00111  * NOTE: (maxblks * blksize) should not overflow int32, but this is not
00112  * checked.
00113  * Return the allocated entry if successful, NULL if any error.
00114  */
00115 blkarray_list_t *_blkarray_list_init (int32 maxblks, int32 blksize);
00116 
00117 
00118 /*
00119  * Like _blkarray_list_init() above, but for some default values of
00120  * maxblks and blksize.
00121  */
00122 blkarray_list_t *blkarray_list_init ( void );
00123 
00124 
00125 /*
00126  * Append the given new entry (data) to the end of the list.
00127  * Return the index of the entry if successful, -1 if any error.
00128  * The returned indices are guaranteed to be successive integers (i.e.,
00129  * 0, 1, 2...) for successive append operations, until the list is reset,
00130  * when they resume from 0.
00131  */
00132 int32 blkarray_list_append (blkarray_list_t *, void *data);
00133 
00134 
00135 /*
00136  * Free all the entries in the list (using ckd_free) and reset the
00137  * list length to 0.
00138  */
00139 void blkarray_list_reset (blkarray_list_t *);
00140 
00144 void blkarray_list_free(blkarray_list_t *bl);
00145 
00146 #ifdef __cplusplus
00147 }
00148 #endif
00149 
00150 
00151 #endif

Generated on 7 Mar 2010 by  doxygen 1.6.1