示例#1
0
globals* globals_alloc() {
	globals *g = malloc(sizeof(globals));
	assert(g);

	g->sorts = cp_trie_create_trie(COLLECTION_MODE_DEEP, 0, free);
	assert(g->sorts);

	g->sorts_N = 0;

	g->ops = cp_multimap_create_by_option(COLLECTION_MODE_DEEP|COLLECTION_MODE_COPY|COLLECTION_MODE_MULTIPLE_VALUES ,
			op_s_key, op_cmp, op_dup, free);
	assert(g->ops);

	g->ops_N = 0;

	g->op_names = cp_vector_create(1); //size in multiples of sizeof(void*)
	assert(g->op_names);

	g->terms = cp_multimap_create_by_option(COLLECTION_MODE_DEEP|COLLECTION_MODE_COPY|COLLECTION_MODE_MULTIPLE_VALUES ,
			op_s_key, op_cmp, op_dup, free); /* TODO: CHANGE TO REFLECT THE TARGET SORT OF THE TERM ONLY */

	g->f = stdout;

	return g;
}
int32_t ds_trie_mgmt_init(hash_tbl_props_t* htp){

    htp->trie = cp_trie_create_trie(
		(COLLECTION_MODE_NOSYNC|COLLECTION_MODE_COPY|
		 COLLECTION_MODE_DEEP),
		trie_copy_func, trie_destruct_func);
    pthread_rwlock_init(&htp->lock, NULL);
    return 0;
}
static int trie_nkncnt_name_to_index(const char *name, int *cindex)
{
    int n;
    int rv;
    int ret;
    nkn_shmdef_t cur_shmdef;
    glob_item_t *item;

    pthread_mutex_lock(&nkncnt_lock);

    cur_shmdef = *pshmdef;
    while (cur_shmdef.revision != shmdef.revision) {
    	if (nkn_cnt_trie) {
	    cp_trie_destroy(nkn_cnt_trie);
	}
	nkn_cnt_trie = cp_trie_create_trie(
				(COLLECTION_MODE_NOSYNC|COLLECTION_MODE_COPY|
		 	 	COLLECTION_MODE_DEEP), 
				trie_copy_func, trie_destruct_func);
	if (!nkn_cnt_trie) {
	    ret = 1;
	    goto exit;
	}

	for (n = 0; n < pshmdef->tot_cnts; n++) {
	    if (!g_allcnts[n].size) {
	    	continue;
	    }
	    rv = cp_trie_add(nkn_cnt_trie,(varname+g_allcnts[n].name), 
			     &g_allcnts[n]);
	    if (rv) {
	    	ret = 2;
	    	goto exit;
	    }
	}
	if (cur_shmdef.revision == pshmdef->revision) {
	    shmdef = cur_shmdef;
	    break;
	}
    	cur_shmdef = *pshmdef;
    }

    item = (glob_item_t *)cp_trie_exact_match(nkn_cnt_trie, (char *)name);
    if (item) {
    	*cindex = (((uint64_t)item - (uint64_t)g_allcnts)/sizeof(glob_item_t));
	ret = 0;
    } else {
    	*cindex = -1;
    	ret = 0; // Not found
    }

exit:

    pthread_mutex_unlock(&nkncnt_lock);
    return ret;
}