Repository navigation
Conversation
Add a new method to TurnCostExtension which enables users to define their preferred merge strategy (overwrite vs. bitwise OR vs. …). These changes require JDK 8.
| */ | ||
| package com.graphhopper.storage; | ||
|
|
||
| import java.util.function.BiFunction; |
There was a problem hiding this comment.
Note: on Android the java.util.function package is available from API level 24 or higher.
|
Thanks for the patch! Currently it is not planned to switch to JDK8 for core (otherwise harder for Android and iOS) - can you avoid this? Furthermore we need a signed CLA from new contributors, just send us an email. |
| } | ||
| BiFunction<Long, Long, Long> overwriteFunc = (oldFlags, newFlags) -> { | ||
| return newFlags; | ||
| }; |
There was a problem hiding this comment.
It would be better to avoid creating this function on every method call.
|
Also did you compare speed for import with and without this patch (e.g. for Germany)? I expect no changes, but if there are many turn costs associated (e.g. if we add costs for every junction) we might run into troubles and then a different approach is needed like a sorted storage where we could stop the loop earlier. |
| * See EdgeBasedRoutingAlgorithmTest for examples. | ||
| */ | ||
| public void setAndMergeTurnInfo(int fromEdge, int viaNode, int toEdge, long turnFlags, | ||
| BiFunction<Long, Long, Long> mergeFunction) { |
There was a problem hiding this comment.
Maybe instead of passing a function here we could convert this to an Enum that specifies the used mode like MergeMode.OVERWRITE and MergeMode.OR, that way we can add new modes in the future and still continue using JDK 7?
Users can circumvent the check if turn flags of a specific turn have already been saved.
|
I pushed two commits today which should address your comments. Results from a performance test importing Germany with following settings: The master needs 7 minutes and 6 seconds, my branch needs the same time (or a few seconds more but it seems to be within the range of variation of the measurements). |
|
Thanks a lot for addressing the comments - looks better now and almost mergable. One question, identical to the comment from @boldtrn: why can't we just use a boolean instead of the function as parameter? I.e. do the merge if |
|
@karussell wrote:
I wanted to keep it flexible. A bitwise OR is the right solution if you write the flags of one encoder after another. But it is not the right operation on the old and new flags if you just want to overwrite the flags of one encoder or do other – maybe strange – things. |
|
We should introduce an additional layer of abstraction only if it is really necessary. Here I do not see why a boolean is not sufficient - can you explain? |
|
Would you mind to do this tiny change so that we can include it in 0.10 release? (hope to get some initial version out in the next days) |
|
Thanks for the change! Why should keep the option If this parameter is false (per default) it would not fix #1107 and if it is always true we can remove it from the method. |
|
@karussell wrote:
It was a rough test and variation was within the measurement accuracy after two or three iterations.
#1107 is caused by a lack of documentation. If a user of the library does not have a look on the actual implementation, he might think that Do with the pull request what you want. Git gives you the ability to pick out of this branch what you are interested in. I offered you a patch with unit tests and documentation and I am tired to continue this discussion. |
We should look for existing entries. This is no documentation issue IMO, there should be no feature "add without looking for existing entries" - at least I do not see why.
why?
Oh, wow. I really appreciate your work and time but this is a bit disturbing to me. Open source lives from these discussions and a maintainer has to be carefully when he merges or adds new stuff. Also you'll learn what is important and can easier contribute the next time :) |
Add a new method to TurnCostExtension which enables users to define their preferred merge strategy (overwrite vs. bitwise OR vs. …). These changes require JDK 8. replace java.util.function by a JDK7 compatible solution optimisation for simple writing of turn flags Users can circumvent the check if turn flags of a specific turn have already been saved. drop FlagMergeStrategy interface and replace it by simple ifs see #1276 (comment) less parameters, slightly more tests but avoid bit-based tests, include clearing turn infos
|
I am ok with that. |
Add a new method to TurnCostExtension which enables users to define their preferred merge strategy (overwrite vs. bitwise OR vs. …). These changes require JDK 8. replace java.util.function by a JDK7 compatible solution optimisation for simple writing of turn flags Users can circumvent the check if turn flags of a specific turn have already been saved. drop FlagMergeStrategy interface and replace it by simple ifs see #1276 (comment) less parameters, slightly more tests but avoid bit-based tests, include clearing turn infos
|
Thanks again for your contribution - merged now! |
Add a new method to TurnCostExtension which enables users to define their preferred merge strategy (overwrite vs. bitwise OR vs. …). These changes require JDK 8.
#1107