Skip to content

Commit

Permalink
Merge pull request #1183 from GIScience/bugfix#1181-address_data_alig…
Browse files Browse the repository at this point in the history
…nment_issue_in_hgv_storage

Access values in hgv storage as bytes rather than shorts
  • Loading branch information
takb authored Jun 15, 2022
2 parents d8b1d5d + fb9852d commit b909c0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ RELEASING:
- added missing matchTraffic override ([#1133](https://github.com/GIScience/openrouteservice/issues/1133))
- typo in docker documentation
- foot routing via `waterway=lock_gate` ([#1177](https://github.com/GIScience/openrouteservice/issues/1177))
- address data alignment issue in hgv extended storage which occasionally caused `ArrayIndexOutOfBoundsException` ([#1181](https://github.com/GIScience/openrouteservice/issues/1181))

## [6.7.0] - 2022-01-04
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.graphhopper.storage.Directory;
import com.graphhopper.storage.Graph;
import com.graphhopper.storage.GraphExtension;
import com.graphhopper.util.BitUtil;
import org.heigit.ors.routing.graphhopper.extensions.VehicleDimensionRestrictions;

public class HeavyVehicleAttributesGraphStorage implements GraphExtension {
Expand All @@ -34,6 +35,8 @@ public class HeavyVehicleAttributesGraphStorage implements GraphExtension {

private static final double FACTOR = 100.0;

private final byte[] buffer = new byte[2];

public HeavyVehicleAttributesGraphStorage(boolean includeRestrictions) {
efVehicleType = nextBlockEntryIndex(1);
efDestinationType = nextBlockEntryIndex(1);
Expand Down Expand Up @@ -115,7 +118,8 @@ public void setEdgeValue(int edgeId, int vehicleType, int heavyVehicleDestinatio

for (int i = 0; i < VehicleDimensionRestrictions.COUNT; i++) {
short shortValue = (short) (restrictionValues[i] * FACTOR);
orsEdges.setShort(edgePointer + efRestrictions + i * EF_RESTRICTION_BYTES, shortValue);
BitUtil.LITTLE.fromShort(buffer, shortValue);
orsEdges.setBytes(edgePointer + efRestrictions + i * EF_RESTRICTION_BYTES, buffer, 2);
}
}

Expand All @@ -125,7 +129,7 @@ public double getEdgeRestrictionValue(int edgeId, int valueIndex) {
if (efRestrictions == -1)
throw new IllegalStateException(MSG_EF_RESTRICTION_IS_NOT_SUPPORTED);

return orsEdges.getShort(edgeBase + efRestrictions + valueIndex * EF_RESTRICTION_BYTES) / FACTOR;
return getShort(edgeBase + efRestrictions + valueIndex * EF_RESTRICTION_BYTES) / FACTOR;
}

public boolean getEdgeRestrictionValues(int edgeId, double[] retValues) {
Expand All @@ -135,11 +139,16 @@ public boolean getEdgeRestrictionValues(int edgeId, double[] retValues) {
throw new IllegalStateException(MSG_EF_RESTRICTION_IS_NOT_SUPPORTED);

for (int i = 0; i < VehicleDimensionRestrictions.COUNT; i++)
retValues[i] = orsEdges.getShort(edgeBase + efRestrictions + i * EF_RESTRICTION_BYTES) / FACTOR;
retValues[i] = getShort(edgeBase + efRestrictions + i * EF_RESTRICTION_BYTES) / FACTOR;

return true;
}

private short getShort(long bytePos) {
orsEdges.getBytes(bytePos, buffer, 2);
return BitUtil.LITTLE.toShort(buffer);
}

public int getEdgeVehicleType(int edgeId, byte[] buffer) {
long edgeBase = (long) edgeId * edgeEntryBytes;
orsEdges.getBytes(edgeBase + efVehicleType, buffer, 2);
Expand All @@ -162,7 +171,7 @@ public boolean hasEdgeRestriction(int edgeId) {

if (efRestrictions > 0)
for (int i = 0; i < VehicleDimensionRestrictions.COUNT; i++)
if (orsEdges.getShort(edgeBase + efRestrictions + i * EF_RESTRICTION_BYTES) != 0)
if (getShort(edgeBase + efRestrictions + i * EF_RESTRICTION_BYTES) != 0)
return true;

return false;
Expand Down

0 comments on commit b909c0a

Please sign in to comment.