logo separator

[mkgmap-dev] [PATCH 08/14] Be more efficient with handling ways.

From Jeffrey C. Ollie jeff at ocjtech.us on Thu Sep 9 21:12:08 BST 2010

From: Scott Crosby <scrosby at cs.rice.edu>

---
 src/uk/me/parabola/splitter/SplitProcessor.java |   33 ++++++++++++++++------
 1 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/src/uk/me/parabola/splitter/SplitProcessor.java b/src/uk/me/parabola/splitter/SplitProcessor.java
index 716c50b..97b014e 100644
--- a/src/uk/me/parabola/splitter/SplitProcessor.java
+++ b/src/uk/me/parabola/splitter/SplitProcessor.java
@@ -14,7 +14,9 @@ package uk.me.parabola.splitter;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.BitSet;
+import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map.Entry;
@@ -39,7 +41,7 @@ class SplitProcessor implements MapProcessor {
 	private final ArrayList<Thread> workerThreads;
 
 	private int currentNodeAreaSet;
-	private BitSet currentWayAreaSet;
+	private ArrayList<Integer> currentWayAreaSet, tmpWayAreaSet;
 	private BitSet currentRelAreaSet;
 	
 	private final int maxThreads;
@@ -76,8 +78,8 @@ class SplitProcessor implements MapProcessor {
 			writerInputQueues[i] = new ArrayBlockingQueue<Element>(NO_ELEMENTS);
 			writerInputQueue.add(new InputQueueInfo(this.writers[i], writerInputQueues[i]));
 		}
-
-		currentWayAreaSet = new BitSet(writers.length);
+		tmpWayAreaSet = new ArrayList<Integer>(10);
+		currentWayAreaSet = new ArrayList<Integer>(10);
 		currentRelAreaSet = new BitSet(writers.length);
 		
 		int noOfWorkerThreads = this.maxThreads - 1;
@@ -154,11 +156,12 @@ class SplitProcessor implements MapProcessor {
 	@Override
 	public void processWay(Way w) {
 
+		int last_val = 0;
 		for (int id: w.getRefs().asArray()) {
 			// Get the list of areas that the node is in.  A node may be in
 			// more than one area because of overlap.
 			int set = coords.get(id);
-
+			
 			// add the list of areas to the currentWayAreaSet
 			if (set != 0) {
 				int mask = 0xff;
@@ -166,7 +169,9 @@ class SplitProcessor implements MapProcessor {
 					int val = (set & mask) >>> (slot * 8);
 				if (val == 0)
 					break;
-				currentWayAreaSet.set(val - 1);
+				if (val != last_val)
+					currentWayAreaSet.add(val - 1);
+				last_val = val;
 				}
 			}
 		}
@@ -254,10 +259,20 @@ class SplitProcessor implements MapProcessor {
 			System.out.println("Writing ways " + new Date());
 		}
 		if (!currentWayAreaSet.isEmpty()) {
-			if (currentWayAreaSet.cardinality() <= 4) {
+			Collections.sort(currentWayAreaSet);
+			int last = -1;
+			tmpWayAreaSet.clear();
+			for (Integer n : currentWayAreaSet) {
+				if (n.equals(last))
+					continue;
+				tmpWayAreaSet.add(n);
+				last = n;
+			}
+			
+			if (tmpWayAreaSet.size() <= 4) {
 				// this way falls into 4 or less areas (the normal case). Store these areas in the ways map
 				int set = 0;
-				for (int n = currentWayAreaSet.nextSetBit(0); n >= 0; n = currentWayAreaSet.nextSetBit(n + 1)) {
+				for (Integer n : tmpWayAreaSet) {
 					if (maxThreads > 1) {
 						addToWorkingQueue(n, currentWay);
 					} else {
@@ -271,8 +286,8 @@ class SplitProcessor implements MapProcessor {
 			} else {
 				// this way falls into 5 or more areas. Convert the currentWayAreaSet into a long[] and store
 				// these areas in the bigWays map
-				long[] set = new long[currentWayAreaSet.size() / 64];
-				for (int n = currentWayAreaSet.nextSetBit(0); n >= 0; n = currentWayAreaSet.nextSetBit(n + 1)) {
+				long[] set = new long[(writers.length+63) / 64];
+				for (Integer n : tmpWayAreaSet) {
 					if (maxThreads > 1) {
 						addToWorkingQueue(n, currentWay);
 					} else {
-- 
1.7.2.3




More information about the mkgmap-dev mailing list