Skip to main content
added 18 characters in body
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342

The tree approach will only provide a benefit in one specific scenario: Obtaining all files within a specific directory subnode. If that's your most common access pattern, then this structure might be useful.

If you want to get a single file by its full path and name, then you will be far better off if you create a separate std::unordered_map<std::string, Entry*> which maps filenames (with complete path) to Entrys. An unordered_map is (practically always) internally implemented as a hash table, so finding an entry in it by key is a constant time operation. Finding one in your tree can potentially take much longer, especially if you happen to have many directories in the hierarchy which have a lot of entries which come before the one you are looking for.

Note that an unordered_map can also be used to speed up tree traversal if you put the entries for the directory nodes into it, because it will make it faster to find the directory node from which you want to find the children.

Possible drawback: Hashmaps have quite a lot of memory overhead compared to other data structures. But I suspect that this overhead will be nothing compared to the memory taken by the actual file data in your virtual filesystem.

The tree approach will only provide a benefit in one specific scenario: Obtaining all files within a specific directory subnode. If that's your most common access pattern, then this structure might be useful.

If you want to get a single file by its full path and name, then you will be far better off if you create a separate std::unordered_map<std::string, Entry*> which maps filenames (with complete path) to Entrys. An unordered_map is (practically always) internally implemented as a hash table, so finding an entry in it by key is a constant time operation. Finding one in your tree can potentially take much longer, especially if you happen to have many directories in the hierarchy which have a lot of entries which come before the one you are looking for.

Note that an unordered_map can also be used to speed up tree traversal if you put the entries for the directory nodes into it, because it will make it faster to find the directory node from which you want to find the children.

The tree approach will only provide a benefit in one specific scenario: Obtaining all files within a specific directory subnode. If that's your most common access pattern, then this structure might be useful.

If you want to get a single file by its full path and name, then you will be far better off if you create a separate std::unordered_map<std::string, Entry*> which maps filenames (with complete path) to Entrys. An unordered_map is (practically always) internally implemented as a hash table, so finding an entry in it by key is a constant time operation. Finding one in your tree can potentially take much longer, especially if you happen to have many directories in the hierarchy which have a lot of entries which come before the one you are looking for.

Note that an unordered_map can also be used to speed up tree traversal if you put the entries for the directory nodes into it, because it will make it faster to find the directory node from which you want to find the children.

Possible drawback: Hashmaps have quite a lot of memory overhead compared to other data structures. But I suspect that this overhead will be nothing compared to the memory taken by the actual file data in your virtual filesystem.

added 18 characters in body
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342

The tree approach will only provide a benefit in one specific scenario: Obtaining all files within a specific directory subnode. If that's your most common access pattern, then this structure might improve performancebe useful.

If you want to get a single file by its full path and name, then you will be far better off if you create a separate std::unordered_map<std::string, Entry>Entry*> which maps filenames (with complete path) to Entrys. ItAn unordered_map is almost(practically always) internally implemented as a hash table, so finding an entry in an unordered_mapit by key is a constant time operation. Finding one in your tree can potentially take much longer, especially if you happen to have many directories in the hierarchy which have a lot of entries which come before the one you are looking for.

Note that an unordered_map can also be used to speed up tree traversal if you put the entries for the directory nodes into it, because it will make it faster to find the directory node from which you want to find the children.

The tree approach will only provide a benefit in one specific scenario: Obtaining all files within a specific directory subnode. If that's your most common access pattern, then this structure might improve performance.

If you want to get a single file by its full path and name, then you will be far better off if you create a separate std::unordered_map<std::string, Entry> which maps filenames (with complete path) to Entrys. It is almost always implemented as a hash table, so finding an entry in an unordered_map by key is a constant time operation. Finding one in your tree can potentially take much longer, especially if you happen to have many directories in the hierarchy which have a lot of entries which come before the one you are looking for.

The tree approach will only provide a benefit in one specific scenario: Obtaining all files within a specific directory subnode. If that's your most common access pattern, then this structure might be useful.

If you want to get a single file by its full path and name, then you will be far better off if you create a separate std::unordered_map<std::string, Entry*> which maps filenames (with complete path) to Entrys. An unordered_map is (practically always) internally implemented as a hash table, so finding an entry in it by key is a constant time operation. Finding one in your tree can potentially take much longer, especially if you happen to have many directories in the hierarchy which have a lot of entries which come before the one you are looking for.

Note that an unordered_map can also be used to speed up tree traversal if you put the entries for the directory nodes into it, because it will make it faster to find the directory node from which you want to find the children.

added 31 characters in body
Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342

The tree approach will only provide a benefit in one specific scenario: Obtaining all files within a specific directory subnode. If that's your most common access pattern, then this structure might improve performance.

If you want to get a specificsingle file by its full path and name, then you will be far better off if you create a separate std::unordered_map<std::string, Entry> which maps filenames (with complete path) to Entrys. FindingIt is almost always implemented as a hash table, so finding an entry in an unordered_map by key is a constant time operation. Finding one in ayour tree iscan potentially take much longer, especially if you happen to have many directories in the hierarchy which have a logarithmic time operationlot of entries which come before the one you are looking for.

The tree approach will only provide a benefit in one specific scenario: Obtaining all files within a specific directory subnode. If that's your most common access pattern, then this structure might improve performance.

If you want a specific file, then you will be far better off if you create a separate std::unordered_map<std::string, Entry> which maps filenames (with complete path) to Entrys. Finding an entry in an unordered_map by key is a constant time operation. Finding one in a tree is a logarithmic time operation.

The tree approach will only provide a benefit in one specific scenario: Obtaining all files within a specific directory subnode. If that's your most common access pattern, then this structure might improve performance.

If you want to get a single file by its full path and name, then you will be far better off if you create a separate std::unordered_map<std::string, Entry> which maps filenames (with complete path) to Entrys. It is almost always implemented as a hash table, so finding an entry in an unordered_map by key is a constant time operation. Finding one in your tree can potentially take much longer, especially if you happen to have many directories in the hierarchy which have a lot of entries which come before the one you are looking for.

Source Link
Philipp
  • 121.5k
  • 28
  • 261
  • 342
Loading