コード例 #1
0
ファイル: avltree.c プロジェクト: alopatindev/data_structures
void remove_node(struct Node** root, int data) {
    struct Node* node = find_node(*root, data);
    ASSERT(node != NULL, *root);

    if (node->left == NULL && node->right == NULL) {
        remove_leaf(root, node);
    } else if (node->left != NULL && node->right == NULL) {
        remove_node_with_left_child(root, node);
    } else if (node->left == NULL && node->right != NULL) {
        remove_node_with_right_child(root, node);
    } else {
        remove_node_with_both_children(root, node);
    }
}
コード例 #2
0
ファイル: dsaa3.c プロジェクト: hasardel/sigmae
static void remove_node(SgBTreeNode **root, SgBTreeNode *n)
{
    SgSize lml, rml;

    lml = n->left->mlevel;
    rml = n->right->mlevel;
    if (!rml && !lml)
        remove_leaf(root, n);
    else if (rml > lml)
        remove_node_right(root, n);
    else if (rml < lml)
        remove_node_left(root, n);
    else {
        if (n->parent->left == n)
            remove_node_right(root, n);
        else
            remove_node_left(root, n);
    }
}
コード例 #3
0
ファイル: PatchFile.cpp プロジェクト: Allowed/SeventhUmbral
void CPatchFile::ExecuteETRY(Framework::CStream& inputStream)
{
	uint32 pathSize = inputStream.Read32_MSBF();
	std::vector<char> pathData(pathSize);
	inputStream.Read(pathData.data(), pathSize);
	std::string path(std::begin(pathData), std::end(pathData));

	auto fullFilePath = m_gameLocationPath / path;
	auto fullFileDirectory = fullFilePath;
	fullFileDirectory.remove_leaf();
	fullFileDirectory.make_preferred();
	fullFilePath.make_preferred();

	if(!boost::filesystem::exists(fullFileDirectory))
	{
		m_result.messages.push_back(string_format("Warning: Directory '%s' doesn't exist. Creating.", 
			fullFileDirectory.string().c_str()
		));
		boost::filesystem::create_directories(fullFileDirectory);
	}

	if(!boost::filesystem::exists(fullFilePath))
	{
		m_result.messages.push_back(string_format("Warning: File '%s' doesn't exist. Creating.", fullFilePath.string().c_str()));
	}

	uint32 itemCount = inputStream.Read32_MSBF();
	for(unsigned int i = 0; i < itemCount; i++)
	{
		//0x41 = last hash, 0x44 = first hash, 0x4D = both hashes?
		uint32 hashMode = inputStream.Read32();
		assert(hashMode == 0x41 || hashMode == 0x44 || hashMode == 0x4D);

		uint8 srcFileHash[0x14];
		uint8 dstFileHash[0x14];
		inputStream.Read(srcFileHash, sizeof(srcFileHash));
		inputStream.Read(dstFileHash, sizeof(dstFileHash));

		//4E is no compression
		//5A is zlib compression
		uint32 compressionMode = inputStream.Read32();
		assert((compressionMode == 0x4E) || (compressionMode == 0x5A));

		uint32 compressedFileSize = inputStream.Read32_MSBF();
		uint32 previousFileSize = inputStream.Read32_MSBF();
		uint32 newFileSize = inputStream.Read32_MSBF();

		if(i != (itemCount - 1))
		{
			assert(compressedFileSize == 0);
		}
		if(compressedFileSize == 0) continue;

		//Data starts here
		{
			//Retrying here because explorer.exe can sometimes open the ffxiv*.exe files to load
			//the icons making the open operation fail if we need to patch it again.
			
			auto outputStream = CreateOutputStdStreamWithRetry(fullFilePath.native());
			if(compressionMode == 0x4E)
			{
				ExtractUncompressed(outputStream, inputStream, compressedFileSize);
			}
			else if(compressionMode == 0x5A)
			{
				ExtractCompressed(outputStream, inputStream, compressedFileSize);
			}
			else
			{
				throw std::runtime_error("Unknown compression type.");
			}
		}
	}

	inputStream.Seek(0x08, Framework::STREAM_SEEK_CUR);
}
コード例 #4
0
ファイル: PsfStreamProvider.cpp プロジェクト: 250394/Play-
CPsfPathToken CPhysicalPsfStreamProvider::GetSiblingPath(const CPsfPathToken& pathToken, const std::string& siblingName)
{
	auto path = GetFilePathFromPathToken(pathToken);
	auto siblingPath = path.remove_leaf() / siblingName;
	return GetPathTokenFromFilePath(siblingPath);
}
コード例 #5
0
            void adaptive_sparse_rrt_t::step()
            {   
                //sample a state
                sampler->sample(state_space,sample_point);  

                //get the nearest state    
                tree_vertex_index_t nearest = nearest_vertex(sample_point);

                //propagate toward the sampled point
                plan_t plan;
                plan.link_control_space(control_space);
                state_t* end_state = pre_alloced_points[point_number];
                double prop_length=0;
                int attempts=0;
                trajectory.clear();
                do
                {
                    if(collision_checking)
                    {
                        plan.clear();
                        local_planner->steer(tree[nearest]->point,sample_point,plan,trajectory,false);
                        state_space->copy_point(end_state,trajectory[trajectory.size()-1]);
                        prop_length = plan.length();         
                    }
                    else
                    {
                        plan.clear();            
                        local_planner->steer(tree[nearest]->point,sample_point,plan,end_state,false);            
                        prop_length = plan.length();          
                    }
                    attempts++;
                }
                while(drain && attempts < max_attempts && ( metric->distance_function(tree[nearest]->point,end_state) < delta_drain || metric->distance_function(tree[nearest]->point,end_state) == PRX_INFINITY));
                count_of_failure += attempts-1;  

                //check if the trajectory is valid
                if(!collision_checking || (validity_checker->is_valid(trajectory) && trajectory.size()>1))
                {
                    std::vector<tree_vertex_index_t> X_near;
                    double new_cost = get_vertex(nearest)->cost + prop_length;
                    bool better_node = false;
                    //Check if a node inside the radius_nearest region
                    if(drain)
                    {
                        X_near = neighbors(end_state);
                        foreach(tree_vertex_index_t x_near, X_near)
                        {
                            if(get_vertex(x_near)->cost <= new_cost )
                            {
                                better_node = true;
                            }
                        }
                    }
                    if(!better_node)
                    {      
                        tree_vertex_index_t v = tree.add_vertex<adaptive_sparse_rrt_node_t,adaptive_sparse_rrt_edge_t>();
                        adaptive_sparse_rrt_node_t* node = get_vertex(v);
                        node->point = end_state;

            //            PRX_INFO_S("POINT: "<< state_space->print_point(end_state));
                        point_number++;
                        node->bridge = true;
                        node->cost = get_vertex(nearest)->cost + prop_length;   
                        tree_edge_index_t e = tree.add_edge<adaptive_sparse_rrt_edge_t>(nearest,v);
                        get_edge(e)->plan = plan;            
                        state_space->copy_point(states_to_check[0],end_state);
                        //check if better goal node
                        if(!real_solution && input_query->get_goal()->satisfied(end_state))
                        {
                            best_goal = v;
                            real_solution = true;
                        }
                        else if(real_solution && get_vertex(best_goal)->cost > get_vertex(v)->cost && input_query->get_goal()->satisfied(end_state) )
                        {
                            best_goal = v;
                        }

                        //check if we need to store trajectories for visualization
                        if(collision_checking && visualize_tree)
                        {
                            get_edge(e)->trajectory = trajectory;
                        }
                        else if(!collision_checking && visualize_tree)
                        {
                            if(trajectory.size()==0)
                                local_planner->propagate(get_vertex(nearest)->point,plan,trajectory);
                            get_edge(e)->trajectory = trajectory;
                        }   

                        if(drain)
                        {
                            foreach(tree_vertex_index_t x_near, X_near)
                            {
                                if(!get_vertex(x_near)->bridge )
                                {
                                    metric->remove_point(tree[x_near]);
                                    get_vertex(x_near)->bridge = true;
                                }
                                tree_vertex_index_t iter = x_near;
                                while( is_leaf(iter) && get_vertex(iter)->bridge && !is_best_goal(iter))
                                {
                                    tree_vertex_index_t next = get_vertex(iter)->get_parent();
                                    remove_leaf(iter);
                                    iter = next;
                                }             
                            }
                        }
                        get_vertex(v)->bridge = false;
                        metric->add_point(tree[v]);
                    }