summaryrefslogtreecommitdiff
path: root/Userland/Applications/SpaceAnalyzer
diff options
context:
space:
mode:
authorArda Cinar <kuzux92@gmail.com>2022-12-13 11:16:55 +0300
committerSam Atkins <atkinssj@gmail.com>2023-01-09 17:08:17 +0000
commitba33267132e996d3ced36bc6ac6e20e4291eefe3 (patch)
tree8505bb46b43fae508ede7d4afe3307da71aefc45 /Userland/Applications/SpaceAnalyzer
parent0d67e605597d7a0a926476da7a39ed9b66199330 (diff)
downloadserenity-ba33267132e996d3ced36bc6ac6e20e4291eefe3.zip
SpaceAnalyzer: Add a method to TreeNode to get a child node by name
This will make it easier to get to a tree node given a file path
Diffstat (limited to 'Userland/Applications/SpaceAnalyzer')
-rw-r--r--Userland/Applications/SpaceAnalyzer/Tree.cpp10
-rw-r--r--Userland/Applications/SpaceAnalyzer/Tree.h1
2 files changed, 11 insertions, 0 deletions
diff --git a/Userland/Applications/SpaceAnalyzer/Tree.cpp b/Userland/Applications/SpaceAnalyzer/Tree.cpp
index bfc7909a64..eb6258a0c0 100644
--- a/Userland/Applications/SpaceAnalyzer/Tree.cpp
+++ b/Userland/Applications/SpaceAnalyzer/Tree.cpp
@@ -128,3 +128,13 @@ HashMap<int, int> TreeNode::populate_filesize_tree(Vector<MountInfo>& mounts, Fu
update_totals();
return error_accumulator;
}
+
+Optional<TreeNode const&> TreeNode::child_with_name(DeprecatedString name) const
+{
+ for (auto& child : *m_children) {
+ if (child.name() == name)
+ return child;
+ }
+
+ return {};
+}
diff --git a/Userland/Applications/SpaceAnalyzer/Tree.h b/Userland/Applications/SpaceAnalyzer/Tree.h
index ee63facaed..377bb4fb1f 100644
--- a/Userland/Applications/SpaceAnalyzer/Tree.h
+++ b/Userland/Applications/SpaceAnalyzer/Tree.h
@@ -32,6 +32,7 @@ public:
return 0;
}
TreeNode const& child_at(size_t i) const { return m_children->at(i); }
+ Optional<TreeNode const&> child_with_name(DeprecatedString name) const;
void sort_children_by_area() const;
HashMap<int, int> populate_filesize_tree(Vector<MountInfo>& mounts, Function<void(size_t)> on_progress);