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