Skip to content

Refactor edge key - #2146

Closed
michaz wants to merge 2 commits into
masterfrom
edgekey
Closed

michaz wants to merge 2 commits into
masterfrom
edgekey

Conversation

@michaz

@michaz michaz commented Oct 2, 2020 •

Copy link
Copy Markdown
Member

This is how far I got. May be of use on its own (?) because I (think I) managed to get rid of one overloaded method in the CH class hierarchy which goes back and forth a lot..

What I did:

  • Put getEdgeKey() on EdgeIteratorState and implement by calling GHUtility.createEdgeKey
  • Replace most occurances of GHUtility.createEdgeKey by that call

What I would ultimately want to do:

  • Replace remaining 3 occurances
  • Remove it
  • Replace the implementation (in EdgeIteratorState) by the one commented-out there. Because that is the other notion of edge direction that we have, and I only want us to have one (the direction that was used to create the edge):
    default int getEdgeKey(boolean reverse) {
        return GHUtility.createEdgeKey(getBaseNode(), getAdjNode(), getEdge(), reverse);
        // What I really want to do is:
        // return getEdge() * 2 + (getBaseNode() != getAdjNode() && (get(EdgeIterator.REVERSE_STATE) ^ reverse) ? 0 : 1);
    }

What's the problem:

  • I'm not sure how to get rid of the occurance in CHPreparationGraph:
        @Override
        public int getOrigEdgeKeyFirst() {
            int e = graph.edgesAndFlags.get(index);
            return GHUtility.createEdgeKey(node, getAdjNode(), e >> 2, false);
        }
  • Particularly I don't know if we could just inline the call there, and then the preparation uses a different traversal id than the rest of the system. Don't know if that matters, the important tests seem to pass, and it uses a different algorithm and different graph interface anyway, so it wouldn't even be wrong, technically. But maybe it does matter.

Feel free to ignore if not useful.

@easbar easbar left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! It seems this is mostly about getting rid of createEdgeKey(base, adj, edge, reverse). Apparently we both started in different places: I was trying to get edge states by edge keys and you first tried to replace the edge key usages. So this is nice and when we combine both we are done :) So let's come back here once #2150 is merged?

Comment on lines -134 to +136
int baseNode = getOtherNode(origEdgeId, edge.getAdjNode());
return GHUtility.createEdgeKey(baseNode, edge.getAdjNode(), origEdgeId, reverse);
EdgeIteratorState origEdge = graph.getBaseGraph().getEdgeIteratorState(origEdgeId, edge.getAdjNode());
return origEdge.getEdgeKey(reverse);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using getOtherNode is better for performance here, I agree these getTraversalId methods are a bit twisted any hopefully this can be improved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then again we should not need this at all and the edge key should be known already. But then we need to store the first/last orig edge key (not id) for the edge-based CH shortcuts (but maybe this is better anyway...).

int getEdge();

default int getEdgeKey(boolean reverse) {
return GHUtility.createEdgeKey(getBaseNode(), getAdjNode(), getEdge(), reverse);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I if we try to get rid of GHUtility#createEdgeKey(base, adj, edge, reverse) we should probably get rid of TraversalMode#createTraversalId(base, adj, edge, reverse) as well.

@easbar

easbar commented Oct 7, 2020 •

Copy link
Copy Markdown
Member

For now we added graph.getEdgeIteratorStateForKey(edgeKey) and edgeState.getEdgeKey() via #2150. Getting rid of GHUtility.createEdgeKey(base, adj, edge, reverse) would be nice, but rather low priority for now, see: #2152

@easbar easbar closed this Oct 7, 2020
@easbar easbar mentioned this pull request Apr 27, 2022
@michaz
michaz deleted the edgekey branch March 21, 2023 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants