Example #1
0
void *matcher_thread(void *n) {
	int tid = (uintptr_t) n;
#ifdef THREAD_ENABLE
	while (1) {
#endif
		//pthread_mutex_lock(&big_debug_lock);
		DocumentDescriptor *doc_desc = (DocumentDescriptor *) cir_queue_remove(
				&cirq_busy_docs);
		char *doc = doc_desc->document;
		int i = 0;
		int matchCount = 0;
		while (doc[i]) {
			while (doc[i] == ' ')
				i++;
			int e = i;
			while (doc[e] != ' ' && doc[e] != '\0')
				e++;
			TrieDocInsert(dtrie[tid], &doc[i], e - i, doc_desc->docId);
			i = e;
		}

		matchTrie(doc_desc->docId, tid, &matchCount, &(dtrie[tid]->root),
				&(eltire->root), &qresult[tid], &qresult_pool[tid]);

		cir_queue_insert(&cirq_free_docs, doc_desc->document);

		doc_desc->matches = (QueryID *) malloc(sizeof(QueryID) * matchCount);
		doc_desc->numResults = matchCount;

		i = 0;
		int p = 0;

		DNode_t* cur = qresult[tid].head.next;
		while (cur != &(qresult[tid].tail)) {
//			QueryDescriptor * cqd = (QueryDescriptor *) cur->data;
//			if (cqd->docId[tid] == doc_desc->docId
//					&& cqd->matchedWords[tid] == (1 << (cqd->numWords)) - 1)
			doc_desc->matches[p++] = (QueryID) (uintptr_t) cur->data;
//			if (p == matchCount)
//				break;
			cur = delete_node_with_pool(cur, &qresult_pool[tid]);
		}

		qsort(doc_desc->matches, matchCount, sizeof(QueryID), cmpfunc);

		//XXX could be moved above when we're using array instead of linkedlist

		pthread_mutex_lock(&docList_lock);
		doc_desc->next = docList.next;
		docList.next = doc_desc;
		pthread_cond_signal(&docList_avail);
		pthread_mutex_unlock(&docList_lock);
		//pthread_mutex_unlock(&big_debug_lock);
#ifdef THREAD_ENABLE
	}
#endif
	return 0;
}
Example #2
0
static Func *
matchTrie(Trie *triep)
{
    Func *func;
    if (triep == TRIE_NULL)
        func = NULL_FUNC;
    else if (triep->n.t_altr != TRIE_NULL)
        func = NULL_FUNC;	/* Ambiguous root, no match.  */
    else if (triep->n.t_next == TRIE_NULL)
        func = triep->l.t_func;	/* At leaf node, return datum.  */
    else				/* Keep going to leaf.  */
        func = matchTrie(triep->n.t_next);
    return func;
}
Example #3
0
Func *
getTrie(char *name, Trie *triep)
{
    Trie *curp = NULL;
    assert(triep != TRIE_NULL);

    /* Traverse next links to end of region name. */
    for (; triep != TRIE_NULL; triep = triep->n.t_next) {
        curp = triep;
        if (*name == NUL) {
            /* End of user-typed name. */
            if (triep->n.t_altr != TRIE_NULL)
                /* Ambiguous at this point. */
                return NULL_FUNC;
            else {
                /* Complete next character. */
                *name++ = triep->n.t_char;
                *name = NUL;
            }
        } else if (*name == '*')
            return matchTrie(triep);
        else	/* Not at end of user-typed name yet, traverse
			   alternate list to find current letter.
			*/ {
            for (;
                    triep != TRIE_NULL
                    &&	*name != triep->n.t_char;
                    triep = triep->n.t_altr
                )
                ;
            if (triep == TRIE_NULL) {
                /* Non-existent name, truncate bad part. */
                *name = NUL;
                return NULL_FUNC;
            } else
                name++;
        }
    }
    /* Clobber key-stroke, and return it. */
    --name;
    *name = NUL;
    assert(curp != TRIE_NULL);
    return curp->l.t_func;
}