Repository navigation
Conversation
|
Can I interpret the two thumbs as review :) ? @devemux86 @boldtrn? Just wanted someone to have a quick scan over it that I did not introduce very obvious problems :) (will also have another look now) |
| public void testViaEdges_WithCoordinates() { | ||
| GraphHopperStorage ghStorage = createTestStorage(); | ||
| Path p = calcPath(ghStorage, 0, 1, 2, 3); | ||
| assertEquals(Helper.createTList(9, 1, 2, 8), p.calcNodes()); |
There was a problem hiding this comment.
virtual nodes get a different id because of the hashmap edge2res in QueryGraph creates them in a different order
| if (edgeIdToOsmWayIdMap == null) | ||
| edgeIdToOsmWayIdMap = new TIntLongHashMap(getOsmWayIdSet().size(), 0.5f, -1, -1); | ||
|
|
||
| edgeIdToOsmWayIdMap = new GHIntLongHashMap(getOsmWayIdSet().size(), 0.5f); |
There was a problem hiding this comment.
Here we do not return -1 anymore if empty but we can easily check if the key is contained via the direct method
| */ | ||
| public class OSMShapeFileReader extends ShapeFileReader { | ||
| private static final int COORD_STATE_UNKNOWN = -1; | ||
| private static final int COORD_STATE_UNKNOWN = 0; |
There was a problem hiding this comment.
empty value in the hashmap is now 0 ... maybe replace this with a contains check? But as we do not use 0 this should be fine too
|
Oh sorry @karussell I just expressed my opinion for your decision. 🙂 |
|
Got a bit feedback from the hppc author in the aboved linked thread. Tried also koloboke as it was mentioned from him and it could be better in terms of speed but the perf numbers are identical at least for CH and non-CH routing. Also both communities are rather small but hppc is used more (90 deps) and from bigger projects like cassandra, ElasticSearch, solr, ... and does everything we need (at least now). @devemux86 no problem |
Me, too :). But I will have a look at your changes and will comment if anything might be an issue. |
boldtrn
left a comment
There was a problem hiding this comment.
I could not find any obvious issue, but I have not looked into every small change (I ignored the changes where just the dependencies changed). My comments are mostly questions, as I would have implemented some things differently, so mostly curiosity.
| final int[] buffer = this.buffer; | ||
| for (int start = 0, end = size() - 1; start < end; start++, end--) { | ||
| // swap the values | ||
| int tmp = buffer[start]; |
There was a problem hiding this comment.
Maybe we should define the int outside of the for? Not sure if this gets optimized, but I introduced a "bug" with String once, so I became a bit cautious with these things.
| public final GHIntArrayList shuffle(Random random) { | ||
| int[] buffer = this.buffer; | ||
| int max = size(); | ||
| int maxHalf = max / 2; |
There was a problem hiding this comment.
Why only half? For example the implementation of Collections.shuffle does it for every element except the first.
There was a problem hiding this comment.
To avoid a "re-shuffle" but this does not really matter to me
There was a problem hiding this comment.
Ok, so if you don't need a guaranteed complete shuffle this should be fine.
|
|
||
| Iterator<IntCursor> iter = set.iterator(); | ||
| final int val = iter.next().value; | ||
| set.removeAll(new IntPredicate() { |
There was a problem hiding this comment.
There was a problem hiding this comment.
Sorry, I should have read the thread first....
It's better to use removeAll(IntPredicate predicate).
There was a problem hiding this comment.
Hmmh, now that I'm re-reading this this looks strange to me as remove(int) seems to be very similar. Maybe he misunderstand something.
|
|
||
| /** | ||
| * @return a copy of inputArray from [offset, offset+length) | ||
| */ |
There was a problem hiding this comment.
Is this faster than construction a LongArrayList with the exptected lenght and this method http://carrotsearch.github.io/hppc/releases/0.7.1/api/com/carrotsearch/hppc/LongArrayList.html#add-long:A-int-int- ?
There was a problem hiding this comment.
Ah, nice. It should be identical and so we can remove this.
I am not sure. This sounds to me like a typical, hash collision scenario. Bascially with open addressing you are calculating a hash (index of an array) for a key. If you put an element into the hashtable you are putting it into the index of the array. If the index is already used, there are different strategies to resolve the issue, one is linear probing. So what you do with linear probing you just put the element at index+1 if the slot is available, if not put it at index+2, and so on. So the problem with this is that in the worst case you end up with linear put and get operations, whereas this should be constant for a hashmap. So from what I understand is that if you are downsizing an existing map, it might happen that you create a lot of these collisions and therefore you end up with a hash map that might be as bad as a random array. So if you are iterating over the map in key order for creating a new table, the chance for creating very bad tables is increased. Lets assume you have 3 key collisions for the first key in your map, so you start to put them at index: 0,1,2. In the bigger map that's not a problem as the next key might be at index 5, but with the smaller map this element might be put at index 1, but index 1 is occupied so you put it at index 3. This goes on and on, therefore the lookup of these elements becomes very bad. If you would look for the element that should be at index 1, you go there and compare the key, you find the key does not match so you need to check index 2, and so on. So if you would do this with iterating randomly over the hashmap the chances for creating a bad hashmap might be decreased. That's how I understand it, but I am not sure if he meant that :). |
|
Yes, this part I understand. But I'm not sure if we would currently stumble over such a problem as we
|
|
Ok, in this case I guess we would not stumble over the problem. |
|
If I may report that using extensively GraphHopper with hppc lately and not seen so far any issues with the change. 🙂 |
|
Nice & Thanks for the feedback - we did the same observation :) ! |
This fixes an early issue #34 and improves #562
The advantages:
Disadvantages
Not yet done: