00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00048 #include "rr_libs/general.h"
00049 #include "ngram.h"
00050
00051 unsigned short new_index(int full_index,
00052 int *ind_table,
00053 unsigned short *ind_table_size,
00054 int position_in_list) {
00055
00056
00057 if (full_index - (((*ind_table_size)-1)*KEY) >= KEY) {
00058 ind_table[*ind_table_size] = position_in_list;
00059 (*ind_table_size)++;
00060 }
00061
00062 return (full_index % KEY);
00063
00064 }
00065
00066 int get_full_index(unsigned short short_index,
00067 int *ind_table,
00068 unsigned short ind_table_size,
00069 int position_in_list) {
00070
00071 int lower_bound;
00072 int upper_bound;
00073 int new_try;
00074
00075
00076
00077 lower_bound = 0;
00078 upper_bound = ind_table_size-1;
00079
00080
00081
00082 if (ind_table_size > 0) {
00083
00084 if (position_in_list >= ind_table[upper_bound]) {
00085 lower_bound = upper_bound;
00086 }
00087
00088 while (upper_bound-lower_bound > 1) {
00089 new_try = (upper_bound + lower_bound) / 2;
00090 if (ind_table[new_try] > position_in_list) {
00091 upper_bound = new_try;
00092 }
00093 else {
00094 lower_bound = new_try;
00095 }
00096 }
00097 }
00098
00099
00100
00101
00102 return((lower_bound*KEY)+short_index);
00103
00104 }
00105