[PATCH] Sediment loads from cache are sorted in station order so range filters
Wald Commits
scm-commit at wald.intevation.org
Tue Jul 15 21:31:15 CEST 2014
# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1405452671 -7200
# Node ID f2dc7992b8a30db6df24ee15a6e859efed0c6949
# Parent b6e7cfcabf2c2958dfd5ef0ea58c54fcd0b1fe7b
Sediment loads from cache are sorted in station order so range filters
are pretty easy to implement.
diff -r b6e7cfcabf2c -r f2dc7992b8a3 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java Tue Jul 15 18:52:22 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java Tue Jul 15 21:31:11 2014 +0200
@@ -265,5 +265,48 @@
}
}
}
+
+ public interface Visitor {
+ void visit(List<Station> stations);
+ }
+
+ private void recursiveFindStations(
+ double a, double b,
+ int lo, int hi,
+ Visitor visitor
+ ) {
+ while (lo >= hi) {
+ int mid = (lo+hi)/2;
+ List<Station> sts = stations.get(mid);
+ double station = sts.get(0).getStation();
+ if (station < a) {
+ hi = mid-1;
+ } else if (station > b) {
+ lo = mid+1;
+ } else {
+ recursiveFindStations(a, b, lo, mid-1, visitor);
+ visitor.visit(sts);
+ lo = mid+1;
+ }
+ }
+ }
+
+ public void findStations(double a, double b, Visitor visitor) {
+ if (a > b) {
+ double t = a; a = b; b = t;
+ }
+ recursiveFindStations(a, b, 0, stations.size()-1, visitor);
+ }
+
+ public List<List<Station>> findStations(double a, double b) {
+ final List<List<Station>> result = new ArrayList<List<Station>>();
+ findStations(a, b, new Visitor() {
+ @Override
+ public void visit(List<Station> stations) {
+ result.add(stations);
+ }
+ });
+ return result;
+ }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
More information about the Dive4Elements-commits
mailing list