Quick Short Answer
Pick a regular Tree Structure first, later look for a similar optimized version
Long Boring Extended Answer
Use a regular Tree Structure first.
I read that it seems you try to store the entire path in each node element,
and that's one of the reasons your structure may requiere unnecesarily optimization.
Note: The following examples are pseudocode. These are not specific Programming Language, finished examples.
Instead of having something like these:
public struct NodeStruct
{
public string FullPath;
public *NodeStruct Container;
public List<*NodeStruct> Items;
}
int main()
{
int ErrorCode = 0;
*NodeStruct MyFileSystem =
new nodeStruct;
MyFileSystem->FullPath = "FileSystem";
MyFileSystem->Container = null;
*NodeStruct CDrive =
new nodeStruct;
CDrive->FullPath = "C:\";
CDrive->Container = MyFileSystem;
*NodeStruct DDrive =
new nodeStruct;
DDrive->FullPath = "D:\";
DDrive->Container = MyFileSystem;
*NodeStruct SomeFolder = null;
*NodeStruct SomeFile = null;
SomeFolder =
new nodeStruct;
SomeFolder->FullPath = "C:\Program Files";
SomeFolder->Container = CFolder;
SomeFolder =
new nodeStruct;
SomeFolder->FullPath = "C:\My Documents";
SomeFolder->Container = CFolder;
SomeFile =
new nodeStruct;
MyFileSystem->FullPath = "C:\My Documents\Homework1.doc";
MyFileSystem->Container = SomeFolder;
free MyFileSystem;
return ErrorCode;
} // int main(...)
You may want to have something like these:
public struct NodeStruct
{
string Identifier;
public *NodeStruct Container;
public List<*NodeStruct> Items;
}
string GetFullPath(*NodeStruct AFileSystemItem)
{
string ErrorCode = "";
// code to "traverse" a tree item or tree node
// and get the full path
return ErrorCode;
} // string GetFullPath(...)
int main()
{
int ErrorCode = 0;
*NodeStruct MyFileSystem =
new nodeStruct;
MyFileSystem->FullPath = "FileSystem";
MyFileSystem->Container = null;
*NodeStruct CDrive =
new nodeStruct;
CDrive->FullPath = "C:";
CDrive->Container = MyFileSystem;
*NodeStruct DDrive =
new nodeStruct;
DDrive->FullPath = "D:";
DDrive->Container = MyFileSystem;
*NodeStruct SomeFolder = null;
*NodeStruct SomeFile = null;
SomeFolder =
new nodeStruct;
SomeFolder->FullPath = "Program Files";
SomeFolder->Container = CFolder;
SomeFolder =
new nodeStruct;
SomeFolder->FullPath = "My Documents";
SomeFolder->Container = CFolder;
SomeFile =
new nodeStruct;
MyFileSystem->FullPath = "Homework1.doc";
MyFileSystem->Container = SomeFolder;
string AFullPath = GetFullPath(SomeFile);
// "AFullPath" should have the "C:\My Documents\Homework1.doc" value
free MyFileSystem;
return ErrorCode;
} // int main(...)
You didn't specify a particular Programming Language in your question. Neither if you are using an Imperative, Procedural, Functional or Object Oriented P.L., that may help suggest you a library.
Cheers.