00001
00024
00025
00026
00027
00028
00029
00030
00031 #include <sent/stddefs.h>
00032 #include <sent/htk_hmm.h>
00033 #include <sent/htk_param.h>
00034 #include <sent/hmm.h>
00035 #include <sent/gprune.h>
00036 #include "globalvars.h"
00037
00047 static int
00048 find_insert_point(LOGPROB score, int len)
00049 {
00050
00051 int left = 0;
00052 int right = len - 1;
00053 int mid;
00054
00055 while (left < right) {
00056 mid = (left + right) / 2;
00057 if (OP_calced_score[mid] > score) {
00058 left = mid + 1;
00059 } else {
00060 right = mid;
00061 }
00062 }
00063 return(left);
00064 }
00065
00086 int
00087 cache_push(int id, LOGPROB score, int len)
00088 {
00089 int insertp;
00090
00091 if (len == 0) {
00092 OP_calced_score[0] = score;
00093 OP_calced_id[0] = id;
00094 return(1);
00095 }
00096 if (OP_calced_score[len-1] >= score) {
00097 if (len < OP_gprune_num) {
00098 OP_calced_score[len] = score;
00099 OP_calced_id[len] = id;
00100 len++;
00101 }
00102 return len;
00103 }
00104 if (OP_calced_score[0] < score) {
00105 insertp = 0;
00106 } else {
00107 insertp = find_insert_point(score, len);
00108 }
00109 if (len < OP_gprune_num) {
00110 memmove(&(OP_calced_score[insertp+1]), &(OP_calced_score[insertp]), sizeof(LOGPROB)*(len - insertp));
00111 memmove(&(OP_calced_id[insertp+1]), &(OP_calced_id[insertp]), sizeof(int)*(len - insertp));
00112 } else if (insertp < len - 1) {
00113 memmove(&(OP_calced_score[insertp+1]), &(OP_calced_score[insertp]), sizeof(LOGPROB)*(len - insertp - 1));
00114 memmove(&(OP_calced_id[insertp+1]), &(OP_calced_id[insertp]), sizeof(int)*(len - insertp - 1));
00115 }
00116 OP_calced_score[insertp] = score;
00117 OP_calced_id[insertp] = id;
00118 if (len < OP_gprune_num) len++;
00119 return(len);
00120 }
00121