/* * is there value 'val' in array or not ? */ static bool checkcondition_str(void *checkval, QueryOperand *val) { CHKVAL *chkval = (CHKVAL *) checkval; WordEntry *StopLow = chkval->arrb; WordEntry *StopHigh = chkval->arre; WordEntry *StopMiddle = StopHigh; int difference = -1; bool res = false; /* Loop invariant: StopLow <= val < StopHigh */ while (StopLow < StopHigh) { StopMiddle = StopLow + (StopHigh - StopLow) / 2; difference = tsCompareString(chkval->operand + val->distance, val->length, chkval->values + StopMiddle->pos, StopMiddle->len, false); if (difference == 0) { res = (val->weight && StopMiddle->haspos) ? checkclass_str(chkval, StopMiddle, val) : true; break; } else if (difference > 0) StopLow = StopMiddle + 1; else StopHigh = StopMiddle; } if (!res && val->prefix) { /* * there was a failed exact search, so we should scan further to find * a prefix match. */ if (StopLow >= StopHigh) StopMiddle = StopHigh; while (res == false && StopMiddle < chkval->arre && tsCompareString(chkval->operand + val->distance, val->length, chkval->values + StopMiddle->pos, StopMiddle->len, true) == 0) { res = (val->weight && StopMiddle->haspos) ? checkclass_str(chkval, StopMiddle, val) : true; StopMiddle++; } } return res; }
/* * is there value 'val' in array or not ? */ static bool checkcondition_str(void *checkval, ITEM * val) { WordEntry *StopLow = ((CHKVAL *) checkval)->arrb; WordEntry *StopHigh = ((CHKVAL *) checkval)->arre; WordEntry *StopMiddle; int difference; /* Loop invariant: StopLow <= val < StopHigh */ while (StopLow < StopHigh) { StopMiddle = StopLow + (StopHigh - StopLow) / 2; difference = ValCompare((CHKVAL *) checkval, StopMiddle, val); if (difference == 0) return (val->weight && StopMiddle->haspos) ? checkclass_str((CHKVAL *) checkval, StopMiddle, val) : true; else if (difference < 0) StopLow = StopMiddle + 1; else StopHigh = StopMiddle; } return (false); }