55 #include <sphinxbase/prim_type.h>
56 #include <sphinxbase/err.h>
57 #include <sphinxbase/ckd_alloc.h>
60 #include "fsg_search_internal.h"
61 #include "fsg_history.h"
68 fsg_history_init(fsg_model_t * fsg,
dict_t *dict)
74 h->entries = blkarray_list_init();
78 h->n_ciphone = bin_mdef_n_ciphone(dict->
mdef);
80 (glist_t **) ckd_calloc_2d(fsg_model_n_state(fsg),
81 bin_mdef_n_ciphone(dict->
mdef),
82 sizeof(**h->frame_entries));
85 h->frame_entries = NULL;
98 ns = fsg_model_n_state(h->fsg);
101 for (s = 0; s < ns; s++) {
102 for (lc = 0; lc < np; lc++) {
103 for (gn = h->frame_entries[s][lc]; gn; gn = gnode_next(gn)) {
104 ckd_free(gnode_ptr(gn));
106 glist_free(h->frame_entries[s][lc]);
110 ckd_free_2d(h->frame_entries);
111 blkarray_list_free(h->entries);
119 if (blkarray_list_n_valid(h->entries) != 0) {
120 E_WARN(
"Switching FSG while history not empty; history cleared\n");
121 blkarray_list_reset(h->entries);
124 if (h->frame_entries)
125 ckd_free_2d((
void **) h->frame_entries);
126 h->frame_entries = NULL;
131 h->n_ciphone = bin_mdef_n_ciphone(dict->
mdef);
133 (glist_t **) ckd_calloc_2d(fsg_model_n_state(fsg),
134 bin_mdef_n_ciphone(dict->
mdef),
143 int32 frame, int32 score, int32 pred,
148 gnode_t *gn, *prev_gn;
154 new_entry->fsglink = link;
155 new_entry->frame = frame;
156 new_entry->score = score;
157 new_entry->pred = pred;
161 blkarray_list_append(h->entries, (
void *) new_entry);
165 s = fsg_link_to_state(link);
169 for (gn = h->frame_entries[s][lc]; gn; gn = gnode_next(gn)) {
176 if (FSG_PNODE_CTXT_SUB(&rc, &(entry->rc)) == 0)
185 new_entry->fsglink = link;
186 new_entry->frame = frame;
187 new_entry->score = score;
188 new_entry->pred = pred;
193 h->frame_entries[s][lc] = glist_add_ptr(h->frame_entries[s][lc],
195 prev_gn = h->frame_entries[s][lc];
198 prev_gn = glist_insert_ptr(prev_gn, (
void *) new_entry);
207 if (FSG_PNODE_CTXT_SUB(&(entry->rc), &rc) == 0) {
209 ckd_free((
void *) entry);
210 gn = gnode_free(gn, prev_gn);
231 ns = fsg_model_n_state(h->fsg);
234 for (s = 0; s < ns; s++) {
235 for (lc = 0; lc < np; lc++) {
236 for (gn = h->frame_entries[s][lc]; gn; gn = gnode_next(gn)) {
238 blkarray_list_append(h->entries, (
void *) entry);
241 glist_free(h->frame_entries[s][lc]);
242 h->frame_entries[s][lc] = NULL;
254 entries = h->entries;
256 if (
id >= blkarray_list_n_valid(entries))
259 r =
id / blkarray_list_blksize(entries);
260 c =
id - (r * blkarray_list_blksize(entries));
269 blkarray_list_reset(h->entries);
276 return (blkarray_list_n_valid(h->entries));
284 assert(blkarray_list_n_valid(h->entries) == 0);
285 assert(h->frame_entries);
287 ns = fsg_model_n_state(h->fsg);
290 for (s = 0; s < ns; s++) {
291 for (lc = 0; lc < np; lc++) {
292 assert(h->frame_entries[s][lc] == NULL);