5 static void AndQuery_reclaim(Query *this) {
6 AndQuery *q = (AndQuery*) this;
8 for ( i = 0; i < q->size; i++ ) {
9 Query_reclaim( q->conjuncts[i] );
15 static int AndQuery_next(
16 Query *this,BindingTable *bt,enum NextState state)
18 AndQuery *q = (AndQuery*) this;
20 enum NextState s = subsequent;
28 while ( i < q->size ) {
29 if ( Query_next( q->conjuncts[i], bt, s ) ) {
32 Query_next( q->conjuncts[i], bt, restore );
34 // The first conjunct now exhausted
43 for ( ; i >= 0; i-- ) {
44 Query_next( q->conjuncts[i], bt, restore );
53 static void AndQuery_variables(Query *this,HashVector *hv) {
54 AndQuery *q = (AndQuery*) this;
56 for ( i = 0; i < q->size; i++ ) {
57 Query_variables( q->conjuncts[i], hv );
61 static struct QueryCallbacks AndQuery_def = {
62 .reclaim = AndQuery_reclaim,
63 .next = AndQuery_next,
64 .variables = AndQuery_variables
67 Query *Query_and(int n,...) {
69 AndQuery *q = (AndQuery *)
70 malloc( sizeof( AndQuery ) );
75 .conjuncts = (Query**) malloc( n * sizeof( Query* ) )
79 for ( i = 0; i < n; i++ ) {
80 q->conjuncts[i] = va_arg( args, Query* );