Esempio n. 1
0
File: engine.c Progetto: fizx/sit
int 
_recurse_add(Engine *engine, dict *hash, QueryNode *parent, Term *term, int remaining, bool negated_yet, Callback *callback) {
  assert(term);
	if(!term->hash_code) {
		term_update_hash(term);
	}
	
	if(term->type == CATCHALL) {
	  if (term->negated) {
      return callback->id;
	  } else if (remaining > 1) {
	    return _recurse_add(engine, hash, parent, term + 1, remaining - 1, negated_yet, callback);
    } else {
      Callback *next = engine->catchall_callbacks;
      engine->catchall_callbacks = callback;
      callback->next = next;
      if(callback->id < 0) callback->id = engine->query_id++;
  		return callback->id;    	
    }
	}

	if(term->negated && !negated_yet) {
	  QueryNode *node = dictFetchValue(hash, &SENTINEL);
	  if (node == NULL) {
  	  node = calloc(sizeof(QueryNode), 1);
  		node->parent = parent;
  		node->term = term_copy(&SENTINEL);
  		node->children = dictCreate(getTermQueryNodeDict(), 0);
      dictAdd(hash, node->term, node);
		}
    parent = node;
    hash = node->children;
    negated_yet = true;
	}
	
	QueryNode *node = dictFetchValue(hash, term);
	if (node == NULL) {
		node = calloc(sizeof(QueryNode), 1);
		node->parent = parent;
		node->term = term_copy(term);
		dictAdd(hash, node->term, node);
	}
	if (remaining == 1) {
		Callback *next = node->callback;
		node->callback = callback;
		callback->next = next;
    if(callback->id < 0) callback->id = engine->query_id++;
		return callback->id;
	} else {
		if(node->children == NULL) {
			node->children = dictCreate(getTermQueryNodeDict(), 0);
		}
		return _recurse_add(engine, node->children, node, term + 1, remaining - 1, negated_yet, callback);
	}
}
Esempio n. 2
0
/*ARGSUSED*/
void lps_addterm(
   Lps*        lp,
   Con*        con,
   const Term* term)
{
   int i;
   int k;

   assert(con != NULL);
/*   assert(term_valid(term));*/
   assert(con->term == NULL);

   con->term = term_copy(term);         

   for(i = 0; i < term_get_elements(term); i++)
   {
      const Mono* mono  = term_get_element(term, i);

      for(k = 0; k < mono_get_degree(mono); k++)
         mono_get_var(mono, k)->is_used = TRUE;
   }
}
Esempio n. 3
0
void *
_term_copy(void *privdata, const void *term) {
  (void) privdata;
  return term_copy(term);
}