Skip to content

Commit 955fea1

Browse files
author
steve
committed
Save memory on the initial spit stage, by not saving the node id's
-Chris Miller git-svn-id: http://svn.mkgmap.org.uk/splitter/trunk@39 838fabe5-b1a8-4b81-9896-7a84386980e9
1 parent 9b98f98 commit 955fea1

File tree

7 files changed

+204
-112
lines changed

7 files changed

+204
-112
lines changed

.idea/fileColors.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

+73-73
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/profiles_settings.xml

+8-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uk/me/parabola/splitter/AreaSplitter.java

+22-27
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package uk.me.parabola.splitter;
1818

19-
import java.util.Iterator;
2019
import java.util.LinkedList;
2120
import java.util.ListIterator;
2221

@@ -32,10 +31,10 @@ public class AreaSplitter {
3231
/**
3332
* Split a single area which would normally be the complete area of the map.
3433
* We just split areas that are too big into two. We make a rough determination
35-
* of the largest dimention and split that way.
34+
* of the largest dimension and split that way.
3635
*
3736
* @param area The original area.
38-
* @param max The maximimum number of nodes that any area can contain.
37+
* @param max The maximum number of nodes that any area can contain.
3938
* @return An array of areas. Each will have less than the specified number of nodes.
4039
*/
4140
public AreaList split(SubArea area, int max) {
@@ -50,12 +49,12 @@ public AreaList split(SubArea area, int max) {
5049
ListIterator<SubArea> it = l.listIterator();
5150
while (it.hasNext()) {
5251
SubArea workarea = it.next();
53-
SplitIntMap map = workarea.getCoords();
54-
if (map == null) {
52+
SplitIntList list = workarea.getCoords();
53+
if (list == null) {
5554
continue;
5655
}
5756

58-
int size = map.size();
57+
int size = list.size();
5958
System.out.println("comparing size " + workarea.getSize());
6059
if (size < max) {
6160
workarea.clear();
@@ -95,14 +94,14 @@ private SubArea[] splitHoriz(SubArea base) {
9594
System.out.println("left = " + left);
9695
System.out.println("right = " + right);
9796

98-
SplitIntMap baseCoords = base.getCoords();
97+
SplitIntList baseCoords = base.getCoords();
9998

100-
Iterator<IntIntMap.Entry> it = baseCoords.fastIterator();
99+
SplitIntList.Iterator it = baseCoords.getIterator();
101100
int count = 0;
102101
long total = 0;
103102
while (it.hasNext()) {
104-
IntIntMap.Entry entry = it.next();
105-
int lon = extractLongitude(entry.getValue());
103+
int val = it.next();
104+
int lon = extractLongitude(val);
106105
assert lon >= left && lon <= right : lon;
107106
count++;
108107
total += lon - left + 1;
@@ -120,15 +119,13 @@ private SubArea[] splitHoriz(SubArea base) {
120119
SubArea a1 = new SubArea(b1);
121120
SubArea a2 = new SubArea(b2);
122121

123-
it = baseCoords.fastDeletingIterator();
122+
it = baseCoords.getDeletingIterator();
124123
while (it.hasNext()) {
125-
IntIntMap.Entry entry = it.next();
126-
int key = entry.getKey();
127-
int co = entry.getValue();
124+
int co = it.next();
128125
if (extractLongitude(co) < mid) {
129-
a1.put(key, co);
126+
a1.add(co);
130127
} else {
131-
a2.put(key, co);
128+
a2.add(co);
132129
}
133130
}
134131

@@ -142,15 +139,15 @@ private SubArea[] splitVert(SubArea base) {
142139
int top = bounds.getMaxLat();
143140
int bot = bounds.getMinLat();
144141

145-
SplitIntMap caseCoords = base.getCoords();
142+
SplitIntList caseCoords = base.getCoords();
146143

147-
Iterator<IntIntMap.Entry> it = caseCoords.fastIterator();
144+
SplitIntList.Iterator it = caseCoords.getIterator();
148145
int count = 0;
149146
long total = 0;
150147
while (it.hasNext()) {
151-
IntIntMap.Entry entry = it.next();
152-
int lat = extractLatitude(entry.getValue());
153-
assert lat >= bot && extractLongitude(entry.getValue()) <= top : lat;
148+
int val = it.next();
149+
int lat = extractLatitude(val);
150+
assert lat >= bot && extractLongitude(val) <= top : lat;
154151
count++;
155152
total += lat - bot;
156153
}
@@ -167,15 +164,13 @@ private SubArea[] splitVert(SubArea base) {
167164

168165
caseCoords = base.getCoords();
169166

170-
it = caseCoords.fastDeletingIterator();
167+
it = caseCoords.getDeletingIterator();
171168
while (it.hasNext()) {
172-
IntIntMap.Entry entry = it.next();
173-
int key = entry.getKey();
174-
int co = entry.getValue();
169+
int co = it.next();
175170
if (extractLatitude(co) <= mid) {
176-
a1.put(key, co);
171+
a1.add(co);
177172
} else {
178-
a2.put(key, co);
173+
a2.add(co);
179174
}
180175
}
181176

src/uk/me/parabola/splitter/DivisionParser.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DivisionParser extends DefaultHandler {
3535

3636
private static final int MODE_NODE = 1;
3737

38-
private SplitIntMap coords = new SplitIntMap();
38+
private SplitIntList coords = new SplitIntList();
3939
private final MapDetails details = new MapDetails();
4040

4141
// Mixed nodes and ways in the file.
@@ -68,7 +68,6 @@ public void startElement(String uri, String localName,
6868
if (qName.equals("node")) {
6969
mode = MODE_NODE;
7070

71-
String id = attributes.getValue("id");
7271
String slat = attributes.getValue("lat");
7372
String slon = attributes.getValue("lon");
7473

@@ -83,7 +82,7 @@ public void startElement(String uri, String localName,
8382
int glon = co.getLongitude();
8483
int coord = ((glat << 8) & 0xffff0000) + ((glon >> 8) & 0xffff);
8584

86-
coords.put(Integer.parseInt(id), coord);
85+
coords.add(coord);
8786

8887
details.addToBounds(co);
8988

0 commit comments

Comments
 (0)