ostream& operator<<(ostream& out, BitVector& bv) { for ( int i=bv.f_bits-1; i>=0; i-- ) { out << bv.getBit(i) ; } out << "\n"; posRecord x; if ( bv.f_positionArray ) { positionArrayIteratorT l_positionNext(*bv.f_positionArray); while (++l_positionNext) { x = l_positionNext.key(); out << x.pathTermPos << "." << x.bitPos << " "; } } out << "\n"; return out; }
unsigned int EncodedPath::match(EncodedPath& text, SSPath* patternPath, SSPath* elementPath) { //////////////////////////////////////////////// // text: the encoded string for the element path // elementPath: the element path // // this: the encoded string for the pattern string // patternPath: the pattern path //////////////////////////////////////////////// //////////////////////////////////////////////// // the unlimited wildcard vector //////////////////////////////////////////////// BitVector* l_U = f_SVectors.findValue(&f_unlimitedWildCard); if ( l_U && patternLength() == 0 ) return true; //////////////////////////////////////////////// // the wildcard vector //////////////////////////////////////////////// BitVector* l_W = f_SVectors.findValue(&f_wildCard); // the S vector of each Letter, including that for '?' BitVector* l_S = 0; // the accumulated result vector BitVector l_R(patternLength(), 0); // placeholder for '*''s contribution BitVector l_I(patternLength(), 0); // hole position record of each path term in the pattern path posRecord l_pr; // expr pointer of each path term in the pattern path PQExpr* expr = 0; CC_TPtrDlistIterator<PathTerm>* elementPathNextPtr = 0; if ( elementPath ) elementPathNextPtr = new CC_TPtrDlistIterator<PathTerm>(*elementPath); // loop over text string for ( int i=0; i<text.length(); i++) { if ( elementPath ) ++(*elementPathNextPtr); //MESSAGE(cerr, "==================="); //debug(cerr, text.f_array[i]); //////////////////////////////////////////////// // get this character's vector, including '?'s //////////////////////////////////////////////// l_S = f_SVectors.findValue(&text.f_array[i]); if ( l_S ) { //debug(cerr, (void*)l_S); //debug(cerr, *l_S); //MESSAGE(cerr, "checking qualifies"); ////////////////////// // check qualifies. ////////////////////// if ( patternPath && l_S -> positionArray() ) { //////////////////// // get a copy of S //////////////////// f_copyOfS -> setTo(*l_S); //debug(cerr, *patternPath); positionArrayIteratorT l_positionNext(*(l_S -> positionArray())); while (++ l_positionNext) { l_pr = l_positionNext.key(); //cerr << " calling patternPath -> fastGetAt(): " << (void*)patternPath << "l_pr.pathTermPos= " << l_pr.pathTermPos << endl; expr = patternPath -> fastGetAt(l_pr.pathTermPos) -> pqexpr(); /* debug(cerr, int(expr)); if ( expr ) { MESSAGE(cerr, "qualify checking is needed."); debug(cerr, *(elementPathNext -> key())); } */ if ( expr && expr->evaluate(elementPathNextPtr->key()->element()) == PQFalse ) { //MESSAGE(cerr, form("set position %d to 0", l_pr.bitPos)); f_copyOfS -> setBitTo(l_pr.bitPos, 0); } } ///////////////////////////////////////// // make l_S point at its modified copy ///////////////////////////////////////// l_S = f_copyOfS; } } else l_S = l_W; //////////////////////////////////////////////// // get unlimited wildcard's vector. //////////////////////////////////////////////// if ( l_U ) { l_I.setTo(l_R); l_I &= (*l_U); //MESSAGE(cerr, "l_I"); //debug(cerr, l_I); } //////////////////////////////////////////////// // shift the partial result vector right once //////////////////////////////////////////////// l_R.shiftRightOneBit(); //MESSAGE(cerr, "after l_R >> 1"); //debug(cerr, l_R); //////////////////////////////////////////////// // AND in this character's vector //////////////////////////////////////////////// if ( l_S ) { l_R &= (*l_S); //debug(cerr, *l_S); //MESSAGE(cerr, "after AND with l_S"); //debug(cerr, l_R); } else { /////////////////////////////////////////////// // this branch is impossible to reach. /////////////////////////////////////////////// //MESSAGE(cerr, "l_R set all bits to 0"); l_R.setAllBitsTo(0); } /////////////////////////////////////////////// // OR in unlimited wild char's vector. /////////////////////////////////////////////// if ( l_U ) { l_R |= l_I; //MESSAGE(cerr, "after OR with l_I"); //debug(cerr, l_R); } //debug(cerr, l_R); //MESSAGE(cerr, "==================="); /////////////////////////////////////////////// // Use this test to get the first matched position // if ( l_R.getBit(0) == 1 ) // return true; /////////////////////////////////////////////// } delete elementPathNextPtr; /////////////////////////////////////////////// // // the last symbol must match // /////////////////////////////////////////////// if ( l_R.getBit(0) == 1 ) return true; else return false; }