00001 /* lookup_index_of() */ 00002 /*===================================================================== 00003 ======= COPYRIGHT NOTICE ======= 00004 Copyright (C) 1994, Carnegie Mellon University and Ronald Rosenfeld. 00005 All rights reserved. 00006 00007 This software is made available for research purposes only. It may be 00008 redistributed freely for this purpose, in full or in part, provided 00009 that this entire copyright notice is included on any copies of this 00010 software and applications and derivations thereof. 00011 00012 This software is provided on an "as is" basis, without warranty of any 00013 kind, either expressed or implied, as to any matter including, but not 00014 limited to warranty of fitness of purpose, or merchantability, or 00015 results obtained from use of this software. 00016 ======================================================================*/ 00017 00025 /* Edited by Philip Clarkson, March 1997 to prevent compilation warnings */ 00026 00027 #include "ngram.h" 00028 00029 int lookup_index_of(lookup_table, lookup_table_size, intval) 00030 int *lookup_table, lookup_table_size, intval; 00031 { 00032 int i; 00033 if (intval>0 && intval<lookup_table_size) { 00034 if (lookup_table[intval]==intval) return(intval); 00035 else if (lookup_table[intval]==0) { 00036 lookup_table[intval] = intval; 00037 return(intval); 00038 } 00039 } 00040 for (i=lookup_table_size-1; i>=0; i--) { 00041 if (lookup_table[i]==intval) return(i); 00042 if (lookup_table[i]==0) { 00043 lookup_table[i] = intval; 00044 return(i); 00045 } 00046 } 00047 quit(-1,"Error - more than %d entries required in the count table. \nCannot store counts in two bytes. Use the -four_byte_counts flag.\n",lookup_table_size); 00048 00049 /* Clearly we will never get this far in the code, but the compiler 00050 doesn't realise this, so to stop it spewing out warnings... */ 00051 00052 return(0); 00053 00054 }