[mkgmap-dev] [PATCH 10/14] Switch to using an ArrayList instead of hash table for Tags.
From Jeffrey C. Ollie jeff at ocjtech.us on Thu Sep 9 21:12:10 BST 2010
From: Scott Crosby <scrosby at cs.rice.edu> --- src/uk/me/parabola/splitter/Element.java | 57 +++++++++++++--------------- src/uk/me/parabola/splitter/OSMWriter.java | 4 +- 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/uk/me/parabola/splitter/Element.java b/src/uk/me/parabola/splitter/Element.java index 94a3265..d3f4a57 100644 --- a/src/uk/me/parabola/splitter/Element.java +++ b/src/uk/me/parabola/splitter/Element.java @@ -12,18 +12,15 @@ */ package uk.me.parabola.splitter; -import java.util.HashMap; +import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; -import java.util.Map; -import java.util.NoSuchElementException; /** * @author Steve Ratcliffe */ public class Element { - private static final Iterator<Map.Entry<String, String>> EMPTY_ITERATOR = new EmptyIterator(); - - private Map<String, String> tags; + private ArrayList<Tag> tags; private int id; protected void setId(int id) { @@ -36,43 +33,41 @@ public class Element { public void reset() { this.id = 0; - tags = null; + tags.clear(); } + class Tag { + public Tag(String key,String value) { + this.key = key; + this.value = value; + } + public String getKey() { + return key; + } + public String getValue() { + return value; + } + final public String key,value; + } + public void addTag(String key, String value) { if (key.equals("created_by")) return; // Most elements are nodes. Most nodes have no tags. Create the tag table lazily - if (tags == null) { - tags = new HashMap<String, String>(4); - } - tags.put(key, value); + if (tags == null) + tags = new ArrayList<Tag>(4); + + tags.add(new Tag(key, value)); } public boolean hasTags() { return tags != null; } - public Iterator<Map.Entry<String, String>> tagsIterator() { - if (tags == null) { - return EMPTY_ITERATOR; - } - return tags.entrySet().iterator(); - } - - private static class EmptyIterator implements Iterator<Map.Entry<String, String>> - { - public boolean hasNext() - { - return false; - } + public Iterator<Tag> tagsIterator() { + if (tags == null) + return Collections.EMPTY_LIST.iterator(); - public Map.Entry<String, String> next() { - throw new NoSuchElementException(); - } - - public void remove() { - throw new UnsupportedOperationException(); - } + return tags.iterator(); } } diff --git a/src/uk/me/parabola/splitter/OSMWriter.java b/src/uk/me/parabola/splitter/OSMWriter.java index 701a639..8cd0740 100644 --- a/src/uk/me/parabola/splitter/OSMWriter.java +++ b/src/uk/me/parabola/splitter/OSMWriter.java @@ -145,9 +145,9 @@ public class OSMWriter { } private void writeTags(Element element) throws IOException { - Iterator<Map.Entry<String, String>> it = element.tagsIterator(); + Iterator<Element.Tag> it = element.tagsIterator(); while (it.hasNext()) { - Map.Entry<String, String> entry = it.next(); + Element.Tag entry = it.next(); writeString("<tag k='"); writeAttribute(entry.getKey()); writeString("' v='"); -- 1.7.2.3
- Previous message: [mkgmap-dev] [PATCH 09/14] Switch to using a binary search instead of a map for finding matching regions.
- Next message: [mkgmap-dev] [PATCH 11/14] Improved function for writing doubles. Fixes ULP errors with the binary format.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the mkgmap-dev mailing list