-
Notifications
You must be signed in to change notification settings - Fork 55
attempt to cache the index and avoid some indexOf() call #1860
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
Changes from 4 commits
14b628a
dc1501e
63b7866
2c6a5ef
2369479
828cee8
5f3f6ac
eefd082
5dfb777
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 |
|---|---|---|
|
|
@@ -19,8 +19,8 @@ | |
| * If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include "openPMD/Iteration.hpp" // needed for index caching in operator[] | ||
|
Contributor
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. Pre-declaring should be fine, but note my comment below, this entire logic is better placed in
Contributor
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. oh, didn't know, let me see
Contributor
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. I think I don't know linkHierarchy() enough to decide. It looks like a big change to me. Maybe merge this pull request and you make a new pull request and work on it?
Contributor
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. I put the logic into |
||
| #include "openPMD/backend/Container.hpp" | ||
|
|
||
| /* | ||
| * Instantiations in src/backend/Container.cpp | ||
| * This file exists so that our tests can include the Container class with | ||
|
|
@@ -149,6 +149,12 @@ auto Container<T, T_key, T_container>::operator[](key_type const &key) | |
| { | ||
| ret.writable().ownKeyWithinParent = std::to_string(key); | ||
| } | ||
| // remember our key inside the iteration object itself so that | ||
| // Series::indexOf becomes constant/ log-time instead of linear. | ||
| if constexpr (std::is_same_v<T, Iteration>) | ||
| { | ||
| ret.get().m_iterationIndex = key; | ||
| } | ||
| traits::GenerationPolicy<T> gen; | ||
| gen(ret); | ||
| return ret; | ||
|
|
@@ -181,6 +187,10 @@ auto Container<T, T_key, T_container>::operator[](key_type &&key) | |
| { | ||
| ret.writable().ownKeyWithinParent = std::to_string(std::move(key)); | ||
| } | ||
| if constexpr (std::is_same_v<T, Iteration>) | ||
| { | ||
| ret.get().m_iterationIndex = key; | ||
| } | ||
| traits::GenerationPolicy<T> gen; | ||
| gen(ret); | ||
| return ret; | ||
|
|
@@ -201,13 +211,23 @@ template <typename T, typename T_key, typename T_container> | |
| auto Container<T, T_key, T_container>::insert(value_type const &value) | ||
| -> std::pair<iterator, bool> | ||
| { | ||
| return container().insert(value); | ||
| auto res = container().insert(value); | ||
| if constexpr (std::is_same_v<T, Iteration>) | ||
| { | ||
| res.first->second.get().m_iterationIndex = res.first->first; | ||
| } | ||
| return res; | ||
| } | ||
| template <typename T, typename T_key, typename T_container> | ||
| auto Container<T, T_key, T_container>::insert(value_type &&value) | ||
| -> std::pair<iterator, bool> | ||
| { | ||
| return container().insert(value); | ||
| auto res = container().insert(value); | ||
| if constexpr (std::is_same_v<T, Iteration>) | ||
| { | ||
| res.first->second.get().m_iterationIndex = res.first->first; | ||
| } | ||
| return res; | ||
|
franzpoeschel marked this conversation as resolved.
Outdated
|
||
| } | ||
| template <typename T, typename T_key, typename T_container> | ||
| auto Container<T, T_key, T_container>::insert( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.