From 66596a01e3bcb69a05e69fcf06a35049404a1158 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Tue, 17 Jan 2012 10:48:38 +0100 Subject: [PATCH] improved null-value cache in estimated wind track by duplicating into a HashSet for fast contains checks --- .../TrackBasedEstimationWindTrackImpl.java | 19 +++++++++++++++++-- ...Server (Proxy, Remote Debug SAP VM).launch | 6 +++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackBasedEstimationWindTrackImpl.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackBasedEstimationWindTrackImpl.java index ab2c38dd21d..d01fa4cf459 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackBasedEstimationWindTrackImpl.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/TrackBasedEstimationWindTrackImpl.java @@ -1,6 +1,7 @@ package com.sap.sailing.domain.tracking.impl; import java.util.Arrays; +import java.util.HashSet; import java.util.Iterator; import java.util.NavigableSet; @@ -53,6 +54,11 @@ public class TrackBasedEstimationWindTrackImpl extends WindTrackImpl implements private final TrackedRace trackedRace; private final NavigableSet timePointsWithCachedNullResult; + + /** + * A copy of the {@link #timePointsWithCachedNullResult} contents offering fast contains checks. + */ + private final HashSet timePointsWithCachedNullResultFastContains; public TrackBasedEstimationWindTrackImpl(TrackedRace trackedRace, long millisecondsOverWhichToAverage) { super(millisecondsOverWhichToAverage); @@ -60,6 +66,7 @@ public class TrackBasedEstimationWindTrackImpl extends WindTrackImpl implements trackedRace.addListener(this); this.virtualInternalRawFixes = new EstimatedWindFixesAsNavigableSet(this, trackedRace); this.timePointsWithCachedNullResult = new ArrayListNavigableSet(AbstractTimePoint.TIMEPOINT_COMPARATOR); + this.timePointsWithCachedNullResultFastContains = new HashSet(); } private NavigableSet getCachedFixes() { @@ -73,6 +80,7 @@ public class TrackBasedEstimationWindTrackImpl extends WindTrackImpl implements protected synchronized void cache(TimePoint timePoint, Wind fix) { if (fix == null) { getTimePointsWithCachedNullResult().add(timePoint); + timePointsWithCachedNullResultFastContains.add(timePoint); } else { getCachedFixes().add(fix); } @@ -80,6 +88,7 @@ public class TrackBasedEstimationWindTrackImpl extends WindTrackImpl implements protected synchronized void cacheNull(TimePoint timePoint) { timePointsWithCachedNullResult.add(timePoint); + timePointsWithCachedNullResultFastContains.add(timePoint); } private synchronized void invalidateCache(Wind startOfInvalidation, TimePoint endOfInvalidation) { @@ -100,6 +109,7 @@ public class TrackBasedEstimationWindTrackImpl extends WindTrackImpl implements TimePoint next = nullIter.next(); if (endOfInvalidation == null || next.compareTo(endOfInvalidation) < 0) { nullIter.remove(); + timePointsWithCachedNullResultFastContains.remove(next); } else { break; } @@ -108,7 +118,8 @@ public class TrackBasedEstimationWindTrackImpl extends WindTrackImpl implements private synchronized void clearCache() { getCachedFixes().clear(); - getTimePointsWithCachedNullResult().clear(); + timePointsWithCachedNullResult.clear(); + timePointsWithCachedNullResultFastContains.clear(); } /** @@ -119,7 +130,7 @@ public class TrackBasedEstimationWindTrackImpl extends WindTrackImpl implements */ protected synchronized Wind getEstimatedWindDirection(Position p, TimePoint timePoint) { Wind result; - if (getTimePointsWithCachedNullResult().contains(timePoint)) { + if (nullResultCacheContains(timePoint)) { result = null; } else { NavigableSet cache = getCachedFixes(); @@ -134,6 +145,10 @@ public class TrackBasedEstimationWindTrackImpl extends WindTrackImpl implements return result; } + private boolean nullResultCacheContains(TimePoint timePoint) { + return timePointsWithCachedNullResultFastContains.contains(timePoint); + } + @Override protected NavigableSet getInternalRawFixes() { return virtualInternalRawFixes; diff --git a/java/com.sap.sailing.server/SailingServer (Proxy, Remote Debug SAP VM).launch b/java/com.sap.sailing.server/SailingServer (Proxy, Remote Debug SAP VM).launch index 32398245d6e..b58891dfb6b 100755 --- a/java/com.sap.sailing.server/SailingServer (Proxy, Remote Debug SAP VM).launch +++ b/java/com.sap.sailing.server/SailingServer (Proxy, Remote Debug SAP VM).launch @@ -19,12 +19,12 @@ - + - + - +