简体   繁体   English

获得文件夹结构层次结构的最佳数据结构?

[英]Best data structure to get folder structure hierarchy?

I am creating an application to organise my files and folders. 我正在创建一个应用程序来组织我的文件和文件夹。 The files and folder structure would be shown in the application. 文件和文件夹结构将显示在应用程序中。 Say for an example the client would send me the folder structure with files as follows 举例来说,客户将给我发送包含文件的文件夹结构,如下所示

  a
  |
  |—b— d — a.txt
    |— e — b.txt

1.a/b/d/a.txt 1.A / B / d / A.TXT

2.a/b/e/b.txt 2.A / B / E / b.txt

For the first time i would create folders a,b,d for the second time it would be enough to create folder e alone. 第一次,我将第二次创建文件夹a,b,d,仅创建文件夹e就足够了。

When the input is a/f/g/h/i/j/abc.txt I should know that the maximum folder created in this is a - and I should know that the rest folders are new - and I must be able to create the rest. 当输入为a/f/g/h/i/j/abc.txt我应该知道,在此创建的最大文件夹是a -我应该知道,其余的文件夹是新的-我必须能够创造其余的部分。

Now how I am doing is parse each file level and check for its existence in the table and then iterating. 现在,我的工作方式是解析每个文件级别,并检查表中是否存在该文件,然后进行迭代。 I would like avoid querying the table each time in each level. 我想避免每次查询每个级别的表。 So, I would like to organise this in a tree hierarchy. 因此,我想以树状层次结构进行组织。 What would be the best data structure to maintain this folder structure? 维护此文件夹结构的最佳数据结构是什么? And how to parse the tree after tree construction? 以及在构建树后如何解析树? Say in a binary tree it would have the property that the data at its right would be greater than the root value and the data at the left would be less than the root value. 在二叉树中说,它将具有以下属性:其右侧的数据将大于根值,而左侧的数据将小于根值。 But here i don't have any logic behind this folder tree structure. 但是在这里,我在此文件夹树结构后面没有任何逻辑。 In this case which tree implementation would suite? 在这种情况下,哪种树实现适合?

You could have a custom tree where the nodes can have an arbitrary number of children. 您可能有一个自定义树,其中的节点可以有任意数量的子代。 Something like 就像是

class Node {
    public String name;
    public List<Node> children;
}

In this implementation the leaves will have an empty/null list of children. 在此实现中,叶子将具有空/空子代列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM