int set_vn(struct fuse *f, struct fuse_vnode *v) { struct fuse_vn_head *vn_head; struct fuse_vnode *vn; DPRINTF("%s: create or update vnode %llu@%llu = %s\n", __func__, (unsigned long long)v->ino, (unsigned long long)v->parent, v->path); if (tree_set(&f->vnode_tree, v->ino, v) == NULL) return (0); if (!dict_check(&f->name_tree, v->path)) { vn_head = malloc(sizeof(*vn_head)); if (vn_head == NULL) return (0); SIMPLEQ_INIT(vn_head); } else { vn_head = dict_get(&f->name_tree, v->path); if (vn_head == NULL) return (0); } SIMPLEQ_FOREACH(vn, vn_head, node) { if (v->parent == vn->parent && v->ino == vn->ino) return (1); } SIMPLEQ_INSERT_TAIL(vn_head, v, node); dict_set(&f->name_tree, v->path, vn_head); return (1); }
void tree_set(int i, int j, int v, int x, int a, int b) { propagate(x, a, b); if (j < a || i > b) return; if (a == b) { T[x].v = v; return; } int lt = 2*x, rt = lt + 1, md = (a+b)/2; if (a >= i && b <= j) { i64 val = v; val *= (b - a + 1); T[x].v = val; T[lt].x = T[rt].x = v; T[lt].c = T[rt].c = true; T[lt].a = T[lt].b = 0; T[rt].a = T[rt].b = 0; T[lt].d = T[rt].d = 0; return; } tree_set(i, j, v, lt, a, md); tree_set(i, j, v, rt, md + 1, b); T[x].v = T[rt].v + T[lt].v; }
/* V_STRING -> V_STRING -> V_TREE -> V_TREE */ static struct value *tree_set_glue(struct info *info, struct value *path, struct value *val, struct value *tree) { // FIXME: This only works if TREE is not referenced more than once; // otherwise we'll have some pretty weird semantics, and would really // need to copy TREE first assert(path->tag == V_STRING); assert(val->tag == V_STRING); assert(tree->tag == V_TREE); struct tree *fake = NULL; struct pathx *p = NULL; struct value *result = NULL; if (tree->origin->children == NULL) { tree->origin->children = make_tree(NULL, NULL, tree->origin, NULL); fake = tree->origin->children; } if (pathx_parse(tree->origin, NULL, path->string->str, true, NULL, &p) != PATHX_NOERROR) { result = make_pathx_exn(ref(info), p); goto done; } if (tree_set(p, val->string->str) == NULL) { result = make_exn_value(ref(info), "Tree set of %s to '%s' failed", path->string->str, val->string->str); goto done; } if (fake != NULL) { list_remove(fake, tree->origin->children); free_tree(fake); } result = ref(tree); done: free_pathx(p); return result; }
Matrice creer_matrice_transistions(Automate* a, char c){ Automate * abis = creer_automate_etats_0_n(a); int n = taille_ensemble(get_etats(abis)); Matrice m = creer_matrice(n); tree t=tree_creat(); tree_set(t, c); m->mot = t; int i, j; for(i = 0; i < m->taille; i++){ for(j = 0; j< m->taille; j++){ m->tab[i][j] = INFINI; } } Table_iterateur it1; Ensemble_iterateur it2; for ( it1 = premier_iterateur_table(get_transitions(abis)); ! iterateur_ensemble_est_vide(it1); it1 = iterateur_suivant_ensemble(it1) ){ Cle * cle = (Cle*) get_cle(it1); Ensemble * fins = (Ensemble*) get_valeur(it1); int tmp = get_lettre_cle(cle); if(tmp == (int)c){ for( it2 = premier_iterateur_ensemble(fins); ! iterateur_ensemble_est_vide(it2); it2 = iterateur_suivant_ensemble(it2) ){ int f = get_element(it2); int cout = get_cout_cle(cle)==0 ? 0: 1; m->tab[get_origine_cle(cle)][f] = cout; } } } liberer_automate(abis); return m; }
void Interpreter::Helper::interpret( const ParseTree::child_pointer_type &node, tree_set &output) { ParseTreeMatcher::match_list_type matches; helper_key[0] = node; interpreter.parse_tree_matcher.find(helper_key, matches); # ifdef DEBUG std::cout << "MATCHED RULES:" << std::endl; for(ParseTreeMatcher::match_list_type::const_iterator i = matches.begin(), n = matches.end(); i != n; ++i) { i->first->print(interpreter.symbol_info, std::cout); std::cout << std::endl; } # endif typedef std::vector<tree_set> result_list_type; typedef std::vector<ParseTree::child_list_type> alternation_list_type; result_list_type sub_results; TranslationTree::child_list_type translation_leaves; alternation_list_type alternations; for(ParseTreeMatcher::match_list_type::const_iterator i = matches.begin(), n = matches.end(); i != n; ++i) { sub_results.clear(); translation_leaves.clear(); /* TODO A potential optimization is to precomute the list of leaf nodes in each translation tree. */ get_leaves(i->first->translation, translation_leaves); for(TranslationTree::child_list_type::const_iterator j = translation_leaves.begin(), m = translation_leaves.end(); j != m; ++j) { assert((*j)->donor_index != TranslationTree::NO_DONOR); assert(0 <= (*j)->donor_index && (*j)->donor_index < (int) i->second.size()); sub_results.push_back(tree_set()); interpret( ParseTree::child_pointer_type( new ParseTree( (*j)->symbol, i->second[(*j)->donor_index]->children)), sub_results.back()); } /* XXX Do note that since we are re-using references when generating alternations of the sub-results, the parse trees generated can share subtrees and therefore form a DAG. So, we can use this as a justification for using shared pointers as the pointer type for ParseTree. For TranslationTree, however, it is not important. */ alternations.clear(); algorithm::generate_alternations( sub_results.begin(), sub_results.end(), alternations); for(alternation_list_type::const_iterator j = alternations.begin(), m = alternations.end(); j != m; ++j) { ParseTree::child_list_type::const_iterator subroot_iter = j->begin(); output.push_back(attach_leaves(i->first->translation, subroot_iter)); } } /* Record any parse trees which did not have any matches. */ if(output.empty()) { unmatched.push_back(node); } }
std::vector<poseT> RefinePoses(const pcl::PointCloud<myPointXYZ>::Ptr scene, const std::vector<ModelT> &mesh_set, const std::vector<poseT> &all_poses) { int pose_num = all_poses.size(); std::vector<ModelT> est_models(pose_num); pcl::PointCloud<myPointXYZ>::Ptr down_scene(new pcl::PointCloud<myPointXYZ>()); pcl::VoxelGrid<myPointXYZ> sor; sor.setInputCloud(scene); sor.setLeafSize(0.005, 0.005, 0.005); sor.filter(*down_scene); #pragma omp parallel for schedule(dynamic, 1) for(int i = 0 ; i < pose_num ; i++ ){ for( int j = 0 ; j < mesh_set.size() ; j++ ){ if( mesh_set[j].model_label == all_poses[i].model_name ) { est_models[i].model_label = all_poses[i].model_name; est_models[i].model_cloud = pcl::PointCloud<myPointXYZ>::Ptr (new pcl::PointCloud<myPointXYZ>()); pcl::transformPointCloud(*mesh_set[j].model_cloud, *est_models[i].model_cloud, all_poses[i].shift, all_poses[i].rotation); break; } } } std::vector< pcl::search::KdTree<myPointXYZ>::Ptr > tree_set(est_models.size()); #pragma omp parallel for schedule(dynamic, 1) for( int i = 0 ; i < pose_num ; i++ ) { tree_set[i] = pcl::search::KdTree<myPointXYZ>::Ptr (new pcl::search::KdTree<myPointXYZ>()); tree_set[i]->setInputCloud(est_models[i].model_cloud); } std::vector<int> votes(pose_num, 0); std::vector< std::vector<int> > adj_graph(pose_num); for( int i = 0 ; i < pose_num ; i++ ) adj_graph[i].resize(pose_num, 0); float sqrT = 0.01*0.01; int down_num = down_scene->size(); std::vector< std::vector<int> > bin_vec(down_num); #pragma omp parallel for for(int i = 0 ; i < pose_num ; i++ ) { int count = 0; for( pcl::PointCloud<myPointXYZ>::const_iterator it = down_scene->begin() ; it < down_scene->end() ; it++, count++ ) { std::vector<int> idx (1); std::vector<float> sqrDist (1); int nres = tree_set[i]->nearestKSearch(*it, 1, idx, sqrDist); if ( nres >= 1 && sqrDist[0] <= sqrT ) { #pragma omp critical { bin_vec[count].push_back(i); } votes[i]++; } } } for( int it = 0 ; it < down_num ; it++ ) for( std::vector<int>::iterator ii = bin_vec[it].begin() ; ii < bin_vec[it].end() ; ii++ ) for( std::vector<int>::iterator jj = ii+1 ; jj < bin_vec[it].end() ; jj++ ) { adj_graph[*ii][*jj]++; adj_graph[*jj][*ii]++; } std::vector<bool> dead_flag(pose_num, 0); for( int i = 0 ; i < pose_num ; i++ ){ if( dead_flag[i] == true ) continue; for( int j = i+1 ; j < pose_num ; j++ ) { if( dead_flag[j] == true ) continue; int min_tmp = std::min(votes[i], votes[j]); if( (adj_graph[i][j]+0.0) / min_tmp >= 0.75 ) { if( votes[i] > votes[j] ) dead_flag[j] = true; else { dead_flag[i] = true; break; } } } } std::vector<poseT> refined_poses; for( int i = 0 ; i < pose_num ; i++ ) if( dead_flag[i] == false ) refined_poses.push_back(all_poses[i]); return refined_poses; }
void set(int i, int j, int v) { tree_set(i, j, v, 1, 0, n-1); }