-
Notifications
You must be signed in to change notification settings - Fork 19
Memory leak 75 #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Memory leak 75 #83
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| class HelpControllerI { | ||
| public: | ||
| virtual void help() = 0; | ||
| virtual ~HelpControllerI() = default; | ||
| }; | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,45 @@ | ||
| #include "SearchDirectory.h" | ||
| #include <iostream> | ||
| vector<pair<int, DreeNode *>> SearchDirectory::search(DreeNode *root, string &query, DreeHelpersI *dreeHelpers) { | ||
| vector<pair<int, DreeNode *>> searchResult; | ||
| vector<pair<int, pair<string, string>>> SearchDirectory::search(DreeNode *root, string &query, DreeHelpersI *dreeHelpers) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it decreasing the readability of the function?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want the function signature to remain as - vector<pair<int, DreeNode *>> @ujjwall-R
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it make sure the function is readable. |
||
| vector<pair<int, pair<string, string>>> searchResult; | ||
| traverse_directories(root, args->MaxDepth, 0, query, searchResult, dreeHelpers); | ||
| return searchResult; | ||
| } | ||
|
|
||
| void SearchDirectory::traverse_directories(DreeNode *node, long long depth, long long currentDepth, const string &query, | ||
| vector<pair<int, DreeNode *>> &results, DreeHelpersI *dreehelpers) { | ||
| vector<pair<int, pair<string, string>>> &results, DreeHelpersI *dreehelpers) { | ||
| if (currentDepth > depth) { | ||
| return; | ||
| } | ||
| int score1 = dreehelpers->levenshtein_distance_between_strings(node->name, query); | ||
| int score2 = dreehelpers->levenshtein_distance_between_strings(node->path, query); | ||
|
|
||
| if (score1 * 100 <= (50 * query.length()) || score2 * 100 <= (50 * query.length())) { | ||
| results.push_back({min(score1, score2), node}); | ||
| results.push_back({min(score1, score2), {node->name, node->path}}); | ||
| } | ||
|
|
||
| if (!dreehelpers->string_is_a_directory(node->path)) { | ||
| return; | ||
| } | ||
|
|
||
| DreeNode *child; | ||
|
|
||
| try { | ||
|
|
||
| for (const auto &entry : filesystem::directory_iterator(node->path)) { | ||
| string childDirectory = entry.path().string(); | ||
| DreeNode *child = new DreeNode(childDirectory); | ||
| child = new DreeNode(childDirectory); | ||
| node->children.push_back(child); | ||
| traverse_directories(child, depth, currentDepth + 1, query, results, dreehelpers); | ||
|
|
||
| delete child; | ||
| child = nullptr; | ||
| node->children.pop_back(); | ||
| } | ||
| } catch (const std::exception &e) { | ||
| } | ||
| delete child; | ||
| child = nullptr; | ||
| } | ||
| } | ||
|
|
||
| SearchDirectory::SearchDirectory(Args *args) { this->args = args; } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| class AboutDreeI { | ||
| public: | ||
| virtual void print_help_instructions() = 0; | ||
| virtual ~AboutDreeI() = default; | ||
| }; | ||
|
|
||
| #endif | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wont it increase the latency? Latency is already very high due to iterations. Lets not do this part. We will have to find some other way. Maybe concurrently. There is a separate issue for that.
Can we have some functionality like
finallyblock in cpp (like what we have in python)? Lets figure out some doing it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure will look for other possibilities and discuss