Use idhash as index - #523
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run --lockfile_mode=error //:license-checkStatus: Click to expand output |
0022556 to
e340109
Compare
e340109 to
b5bf313
Compare
c13c457 to
21cc9f8
Compare
| std::vector<GraphIndex> dependents; | ||
| std::vector<Key> depends_on; | ||
| std::vector<Key> dependents; | ||
| bool visited{false}; |
There was a problem hiding this comment.
Not sure if holding temporary info as members is a good idea, it does get rid of allocations if we had to make another data structure to hold the info thought 🤔
Would be good to also add @briefs to each and make it very clear that this is temp info.
There was a problem hiding this comment.
Also make sure to say that methods are not expected to reset it after use and you shall reset the values at the beginning of the method
| /// before insertion (i.e. the first node is 0, second is 1, etc.). | ||
| template <typename... Args> | ||
| GraphIndex emplace(Args&&... args) | ||
| Key try_emplace(const Key& key, Args&&... args) |
There was a problem hiding this comment.
You should add docstrings what happens if the emplace fails, what is returned.
Maybe would be better to return a Result also.
There was a problem hiding this comment.
Added a warning and a debug assert 45a58bc
| @@ -90,42 +90,45 @@ class DependencyGraph | |||
| /// reserved at construction). | |||
| std::size_t capacity() const | |||
|
|
||
| T& operator[](GraphIndex index) | ||
| T& operator[](Key key) | ||
| { |
There was a problem hiding this comment.
at() can throw here if the key isn't in the map, I think might be good to use find instead. It has the same complexity as at so there is no drawback I think.
This is for all of the other methods that use at also
| void traverse(const Key start, PerNodeFn per_node) | ||
| { | ||
| visited.assign(visited.size(), false); | ||
| for (auto& [key, value] : nodes) |
There was a problem hiding this comment.
Think std::for_each would look more readable here actually.
|
|
||
| /// @brief Returns the IComponent reference from an interface pointer. Useful for a template class that may take a | ||
| /// variant or a generic interface | ||
| inline IComponent& componentOf(IComponent* node) |
There was a problem hiding this comment.
is this really needed? seems a bit unnecessary
There was a problem hiding this comment.
This is for transition_UT, it defines its own componentOf method to override the std::variant one. I could leave this change out but I thought it made the UT easier to understand. Can be removed after #427 as well.
| // dependencies can only be wired up once every node exists, so collect | ||
| // them while creating the nodes | ||
| std::vector<std::pair<GraphIndex, std::vector<std::string>>> pending_dependencies; | ||
| std::vector<std::pair<IdentifierHash, std::vector<std::string>>> pending_dependencies; |
There was a problem hiding this comment.
I don't think you actually need to store this at all. Should be able to make dependencies to nodes that are not yet in the graph. I think we verify that there is no empty dependence in the script so should be safe (do double check though)
There was a problem hiding this comment.
We still can't setup dependencies before both sides are ready unfortunately, so this is still needed
| // LM_LOG_DEBUG() << "Queued node " << task.component.get().getIndex() << " for " | ||
| // LM_LOG_DEBUG() << "Queued node " << task.component.get().getIdentifier() << " for " | ||
| // << (task.type == ComponentTaskType::kDeactivate ? "deactivation" : "activation") | ||
| // << " execution, jobs in progress:" << jobs_in_progress_; |
There was a problem hiding this comment.
Maybe just get rid of the log?
| private: | ||
| /// @brief True iff @p node is a valid index into the underlying graph, i.e. in [0, size()). | ||
| bool isValidNode(GraphIndex node) const | ||
| bool isValidNode(Key node) const |
There was a problem hiding this comment.
I've added an assertion that Key is trivially copyable so I don't think we should use a const value: c3c554d
| /// successors. Detection of dependency readiness should be reworked to remove this. | ||
| std::bitset<static_cast<std::size_t>(internal::ProcessLimits::kMaxProcesses)> enqueued_set{}; | ||
| /// @brief Information we need to maintain about graph nodes for the current transition | ||
| std::unordered_map<Key, NodeInfo> node_information; |
There was a problem hiding this comment.
mmm why go with a hash map, bitset is nice because it won't allocate
There was a problem hiding this comment.
I don't think we can avoid using a map here, but it will only allocate during initialisation
| // Sets up or resets our stored info for this transition | ||
| for (auto [key, value] : graph_) | ||
| { | ||
| state_.node_information[key] = NodeInfo{}; |
There was a problem hiding this comment.
Might be better to just set the values rather than delet and construct a new element
21cc9f8 to
c3c554d
Compare
Resolves #463
As part of this, I have:
std::pair<const Key, T>instead ofT.componentOffortransition_UTTODO
GraphIndexwhere it occursindexwhereidentifierwould be a better fitTransitionchanges. Changes are a bit hacky, maybe it should store its own map of structs rather than a map to two bitsets?componentOfoverride in transition UT. I'm not sure how it was working before, but I had to move it. Maybe it works with a smaller change now, but we should maybe just add an override for IComponent in thecomponentOfheader