-
Notifications
You must be signed in to change notification settings - Fork 4
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
Generic trait for SecondaryMaps #51
Conversation
@zrho You may have comments on this. |
- Renames the old SecondaryMap struct as "UnmanagedMap" - Implements SecondaryMap for BitVec - Uses the trait in Dominators to avoid wasting memory when doing partial traversals.
f06febf
to
a2fbad8
Compare
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.
I believe there's a bug in BitVec implementation but otherwise looks mostly ok
@@ -127,13 +140,13 @@ impl<'graph> TopoSort<'graph> { | |||
// Mark all the candidate ports as visited, so we don't visit them again. | |||
for node in candidate_nodes.iter() { | |||
for port in graph.ports(*node, direction.reverse()) { | |||
remaining_ports.set(port.index(), false); | |||
visited_ports.set(port, true); |
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.
is there an assumption here that the default value of Map
is always false
or is that guranteed?
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.
Yes, that is part of the definition of SecondaryMap
:
/// A map from keys to values that does not manage it's indices.
///
/// Querying a key that has not been set returns a default value.
(and default_value
returns false
for BitVec)
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.
right but that doesn't stop me using a struct for Map
that returns true
for default_value
right? Might need a debug assert at least?
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.
Added the check to toposort. If the default value is true
it initializes everything (and states so in the docs).
Looks good to me.
|
Yes, perhaps
👍 |
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.
👍
This is a big breaking change that will give us more flexibility when managing secondary data on a portgraph.
It adds a
SecondaryMap
trait that encapsulates the common interfaces we use when managing node and port data.We can then implement that trait on different structures like the old
SecondaryMap
(now renamedUnmanagedMap
), bit vec for boolean storage, and any {Hash,BTree}{Set,Map}. This closes #46.With this, we can add a
Map
generic parameter toDominatorTree
andTopoSort
that lets us use more efficient structures when we do not traverse the full graph. This closes #31.Also:
There's a TODO to implement SecondaryMap for sparse containers (hash and BTree), but those can be done in another non-breaking PR.
Note that
unmanaged.rs
is mostly the old contents ofsecondary.rs
, but git didn't pick up the renaming.