Exemple #1
0
void
clear_string_pool(void)
{
	if (strpool == NULL)
		return;

	clear_hashtable(strpool);
}
Exemple #2
0
void Map::informed_bff_search(Map &copy_map){
    std::priority_queue<node*,std::vector<node*>,comparator_functor> search_list; //list of current search nodes.
    std::queue<node*> neighbohrs;                       //results from add_all_possible
    node start(man,diamond_pos);
    wave(copy_map,man,diamond_pos);
    search_list.push(&start);                            //set first target
    closed_set.clear();
    std::string start_node_index = to_string(start.diamonds,start.man);
    std::string hash_index;
    node *current_node;
    std::unordered_map<std::string,node*>::iterator hash_ptr;
    while( !search_list.empty()) {
        current_node = search_list.top();
        if(game_complete(current_node)){
            std::cout << "//" << " found the goal. Number of nodes: " << closed_set.size() + search_list.size() << "\n";
            std::cout << "//" << " move length: " << current_node->path_length << "\n";
            //print the path as a string or as C code
            //print_path(copy_map,current_node);
            print_path_as_C_code(copy_map,current_node);
            clear_hashtable(closed_set,start_node_index);
            while(!search_list.empty()){
                current_node = search_list.top();
                delete current_node;
                search_list.pop();
            }
            return;
        }
        search_list.pop();

        hash_index = to_string(current_node->diamonds,current_node->man);
        if( closed_set.emplace(hash_index,current_node).second){         //if the configuration has not been visited
            neighbohrs = add_all_possible_paths(current_node,copy_map);  //this gives the possible paths
            while( !neighbohrs.empty() ) {                               //append these nodes to the list.
                current_node = neighbohrs.front();
                neighbohrs.pop();

                hash_index = to_string(current_node->diamonds,current_node->man);
                hash_ptr = closed_set.find(hash_index); ;

                if( hash_ptr != closed_set.end() ){ //if already visited
                    delete current_node;
                } else {
                    search_list.push(current_node);
                }
            }
        } else { //if already visited
            delete current_node;
        }
    }
    std::cout << "no solution\n";
    return;
}
Exemple #3
0
static int	export_option_n(t_env *env, char **argv)
{
	t_env_list	*var;
	int			ret;

	if (argv[0] && !is_valid_variable_name(argv[0]))
		return (ft_dprintf(2, "%s: not a valid variable name\n", argv[0]));
	if ((var = ft_getenv(env->env_list, argv[0])))
	{
		(var->exportable == GLOBAL) ? env->env_len-- : 0;
		var->exportable = LOCAL;
	}
	if (!var || argv[1])
	{
		ret = append_variable_to_env(env, argv[0], argv[1] ? argv[1] : "",
				LOCAL);
		if (!ret && !ft_strcmp("PATH", argv[0]))
			clear_hashtable();
	}
	env->has_changed = TRUE;
	return (0);
}
Exemple #4
0
static int	set_to_global(t_env *env, char *av1, char *av2)
{
	t_env_list	*var;
	int			ret;

	ret = 1;
	if ((var = ft_getenv(env->env_list, av1)) && var->exportable == LOCAL)
	{
		if (av2)
			ret = append_variable_to_env(env, av1, av2, GLOBAL);
		else
		{
			var->exportable = 1;
			env->env_len++;
		}
	}
	else
		ret = append_variable_to_env(env, av1, av2 ? av2 : "", GLOBAL);
	if (!ret && !ft_strcmp("PATH", av1))
		clear_hashtable();
	(!ret) ? env->has_changed = TRUE : 0;
	return (0);
}