blkarray_list.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 1999-2004 Carnegie Mellon University. All rights
4  * reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  *
19  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
20  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
23  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * ====================================================================
32  *
33  */
34 /*
35  * blkarray_list.h -- array-based list structure, for memory and access
36  * efficiency.
37  *
38  * HISTORY
39  *
40  * $Log$
41  * Revision 1.1 2006/04/05 20:27:30 dhdfu
42  * A Great Reorganzation of header files and executables
43  *
44  * Revision 1.2 2006/02/23 05:10:18 arthchan2003
45  * Merged from branch SPHINX3_5_2_RCI_IRII_BRANCH: Adaptation of Sphinx 2's FSG search into Sphinx 3
46  *
47  * Revision 1.1.2.1 2005/06/27 05:26:29 arthchan2003
48  * Sphinx 2 fsg mainpulation routines. Compiled with faked functions. Currently fended off from users.
49  *
50  * Revision 1.1 2004/07/16 00:57:12 egouvea
51  * Added Ravi's implementation of FSG support.
52  *
53  * Revision 1.2 2004/05/27 14:22:57 rkm
54  * FSG cross-word triphones completed (but for single-phone words)
55  *
56  * Revision 1.1.1.1 2004/03/01 14:30:31 rkm
57  *
58  *
59  * Revision 1.1 2004/02/26 01:14:48 rkm
60  * *** empty log message ***
61  *
62  *
63  * 18-Feb-2004 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon
64  * Started.
65  */
66 
67 
68 #ifndef __S2_BLKARRAY_LIST_H__
69 #define __S2_BLKARRAY_LIST_H__
70 
71 
72 #include <s3types.h>
73 
74 
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 #if 0
79 /* Fool Emacs. */
80 }
81 #endif
82 
83 /*
84  * For maintaining a (conceptual) "list" of pointers to arbitrary data.
85  * The application is responsible for knowing the true data type.
86  * Use an array instead of a true list for efficiency (both memory and
87  * speed). But use a blocked (2-D) array to allow dynamic resizing at a
88  * coarse grain. An entire block is allocated or freed, as appropriate.
89  */
90 typedef struct blkarray_list_s {
91  void ***ptr; /* ptr[][] is the user-supplied ptr */
92  int32 maxblks; /* size of ptr (#rows) */
93  int32 blksize; /* size of ptr[] (#cols, ie, size of each row) */
94  int32 n_valid; /* # entries actually stored in the list */
95  int32 cur_row; /* The current row being that has empty entry */
96  int32 cur_row_free; /* First entry valid within the current row */
98 
99 /* Access macros */
100 #define blkarray_list_ptr(l,r,c) ((l)->ptr[r][c])
101 #define blkarray_list_maxblks(l) ((l)->maxblks)
102 #define blkarray_list_blksize(l) ((l)->blksize)
103 #define blkarray_list_n_valid(l) ((l)->n_valid)
104 #define blkarray_list_cur_row(l) ((l)->cur_row)
105 #define blkarray_list_cur_row_free(l) ((l)->cur_row_free)
106 
107 
108 /*
109  * Initialize and return a new blkarray_list containing an empty list
110  * (i.e., 0 length). Sized for the given values of maxblks and blksize.
111  * NOTE: (maxblks * blksize) should not overflow int32, but this is not
112  * checked.
113  * Return the allocated entry if successful, NULL if any error.
114  */
115 blkarray_list_t *_blkarray_list_init (int32 maxblks, int32 blksize);
116 
117 
118 /*
119  * Like _blkarray_list_init() above, but for some default values of
120  * maxblks and blksize.
121  */
123 
124 
125 /*
126  * Append the given new entry (data) to the end of the list.
127  * Return the index of the entry if successful, -1 if any error.
128  * The returned indices are guaranteed to be successive integers (i.e.,
129  * 0, 1, 2...) for successive append operations, until the list is reset,
130  * when they resume from 0.
131  */
132 int32 blkarray_list_append (blkarray_list_t *, void *data);
133 
134 
135 /*
136  * Free all the entries in the list (using ckd_free) and reset the
137  * list length to 0.
138  */
140 
145 
146 #ifdef __cplusplus
147 }
148 #endif
149 
150 
151 #endif