++


eval()


Query eval() ( ). -, eval() Query , :

class Query {

public:

virtual void eval() = 0;

// ...

};

eval() . , . , , NameQuery . NameQuery eval() .

Query. ? NameQuery , . , , . eval() :

class NameQuery : public Query {

public:

virtual void eval() {}

// ...

};



NotQuery , . _loc NotQuery (, ). :

void NotQuery::eval()

{

//

_op->eval();

// _all_locs - , ,

// NotQuery:

// static const vector<locations>* _all_locs

vector< location >::const_iterator

iter = _all_locs->begin(),

iter_end = _all_locs->end();

// ,

set<short> *ps = _vec2set( _op->locations() );

// , ,

// _loc

for ( ; iter != iter_end; ++iter )

{

if ( ! ps->count( (*iter).first )) {


_loc.push_back( *iter );

}

}

}

NotQuery. 0, 3 5 . (, 0; , .) , 1,2 4. ( , .)

==> ! daddy

daddy ( 3 ) lines match

display_location_vector:

first: 0 second: 8

first: 3 second: 3

first: 5 second: 5

! daddy ( 3 ) lines match

display_location_vector:

first: 1 second: 0

first: 1 second: 1

first: 1 second: 2

...

first: 1 second: 10

first: 2 second: 0

first: 2 second: 1

...

first: 2 second: 12

first: 4 second: 0

first: 4 second: 1

...

first: 4 second: 12

Requested query: ! daddy

( 2 ) when the wind blows through her hair, it looks almost alive,

( 3 ) like a fiery bird in flight. A beautiful fiery bird, he tells her,

( 5 ) she tells him, at the same time wanting him to tell her more.

OrQuery . merge(). merge() (, ), - . :

class less_than_pair {

public:

bool operator()( location loc1, location loc2 )

{

return (( loc1.first < loc2.first ) ||

( loc1.first == loc2.first ) &&

( loc1.second < loc2.second ));

}

};

void OrQuery::eval()

{

//



_lop->eval();

_rop->eval();

//

vector< location, allocator >::const_iterator

riter = _rop->locations()->begin(),

liter = _lop->locations()->begin(),

riter_end = _rop->locations()->end(),

liter_end = _lop->locations()->end();

merge( liter, liter_end, riter, riter_end,

inserter( _loc, _loc.begin() ),

less_than_pair() );

}

OrQuery, . ( , 1,   0.)

==> fiery || untamed

fiery ( 1 ) lines match

display_location vector:

first: 2 second: 2

first: 2 second: 8

untamed ( 1 ) lines match

display_location vector:

first: 3 second: 2

fiery || untamed ( 2 ) lines match

display_location vector:

first: 2 second: 2

first: 2 second: 8

first: 3 second: 2

Requested query: fiery || untamed

( 3 ) like a fiery bird in flight. A beautiful fiery bird, he tells her,

( 4 ) magical but untamed. "Daddy, shush, there is no such thing,"

AndQuery . _loc. , , .

void AndQuery::eval()

{

//

_lop->eval();

_rop->eval();

//

vector< location, allocator >::const_iterator

riter = _rop->locations()->begin(),

liter = _lop->locations()->begin(),

riter_end = _rop->locations()->end(),

liter_end = _lop->locations()->end();



// ,

while ( liter != liter_end &&

riter != riter_end )

{

// ,

while ( (*liter).first > (*riter).first )

{

++riter;

if ( riter == riter_end ) return;

}

// ,

while ( (*liter).first < (*riter).first )

{

//

//

// _max_col

if ( ((*liter).first == (*riter).first-1 ) &&

((*riter).second == 0 ) &&

((*liter).second == (*_max_col)[ (*liter).first ] ))

{

_loc.push_back( *liter );

_loc.push_back( *riter );

++riter;

if ( riter == riter_end ) return;

}

++liter;

if ( liter == liter_end ) return;

}

//

while ( (*liter).first == (*riter).first )

{

if ( (*liter).second+1 == ((*riter).second) )

{ //

_loc.push_back( *liter ); ++liter;

_loc.push_back( *riter ); ++riter;

}

else

if ( (*liter).second <= (*riter).second )

++liter;

else ++riter;

if ( liter == liter_end || riter == riter_end )

return;

}

}

}

AndQuery, :

==> fiery && bird

fiery ( 1 ) lines match

display_location vector:

first: 2 second: 2

first: 2 second: 8



bird ( 1 ) lines match

display_location vector:

first: 2 second: 3

first: 2 second: 9

fiery && bird ( 1 ) lines match

display_location vector:

first: 2 second: 2

first: 2 second: 3

first: 2 second: 8

first: 2 second: 9

Requested query: fiery && bird

( 3 ) like a fiery bird in flight. A beautiful fiery bird, he tells her,

, , . , :

==> fiery && ( bird || untamed )

fiery ( 1 ) lines match

display_location vector:

first: 2 second: 3

first: 2 second: 8

bird ( 1 ) lines match

display_location vector:

first: 2 second: 3

first: 2 second: 9

untamed ( 1 ) lines match

display_location vector:

first: 3 second: 2

( bird || untamed ) ( 2 ) lines match

display_location vector:

first: 2 second: 3

first: 2 second: 9

first: 3 second: 2

fiery && ( bird || untamed ) ( 1 ) lines match

display_location vector:

first: 2 second: 2

first: 2 second: 3

first: 2 second: 8

first: 2 second: 9

Requested query: fiery && ( bird || untamed )

( 3 ) like a fiery bird in flight. A beautiful fiery bird, he tells her,









Forekc.ru
, , , , , , , , , ,