saved a bit more ram using UTF8 String compression for OpenGeoDB and

Geonames data files.
pull/1/head
Michael Peter Christen 13 years ago
parent 225ee42879
commit cde20911bb

@ -24,10 +24,12 @@ package net.yacy.document.geolocalization;
import java.util.Comparator;
import net.yacy.cora.document.UTF8;
public class GeoLocation extends IntegerGeoPoint implements Comparable<GeoLocation>, Comparator<GeoLocation> {
private String name;
private byte[] name;
private int population;
public GeoLocation(double lat, double lon) {
@ -38,15 +40,15 @@ public class GeoLocation extends IntegerGeoPoint implements Comparable<GeoLocati
public GeoLocation(double lat, double lon, String name) {
super(lat, lon);
this.name = name;
this.name = UTF8.getBytes(name);
}
public void setName(String name) {
this.name = name;
this.name = UTF8.getBytes(name);
}
public String getName() {
return this.name;
return UTF8.String(this.name);
}
public void setPopulation(int population) {
@ -61,7 +63,7 @@ public class GeoLocation extends IntegerGeoPoint implements Comparable<GeoLocati
public boolean equals(Object loc) {
if (!(loc instanceof GeoLocation)) return false;
if (this.name == null || ((GeoLocation) loc).name == null) return super.equals(loc);
return super.equals(loc) && this.name.toLowerCase().equals(((GeoLocation) loc).name.toLowerCase());
return super.equals(loc) && this.getName().toLowerCase().equals(((GeoLocation) loc).getName().toLowerCase());
}
/**

@ -52,9 +52,7 @@ import net.yacy.kelondro.logging.Log;
public class OpenGeoDBLocalization implements Localization
{
private final Map<Integer, String> locTypeHash2locType;
private final Map<Integer, GeoLocation> id2loc;
private final Map<Integer, Integer> id2locTypeHash;
private final TreeMap<StringBuilder, List<Integer>> name2ids;
private final TreeMap<StringBuilder, List<Integer>> kfz2ids;
private final Map<String, List<Integer>> predial2ids;
@ -64,13 +62,9 @@ public class OpenGeoDBLocalization implements Localization
public OpenGeoDBLocalization(final File file, final boolean lonlat) {
this.file = file;
this.locTypeHash2locType = new HashMap<Integer, String>();
this.id2loc = new HashMap<Integer, GeoLocation>();
this.id2locTypeHash = new HashMap<Integer, Integer>();
this.name2ids =
new TreeMap<StringBuilder, List<Integer>>(StringBuilderComparator.CASE_INSENSITIVE_ORDER);
this.kfz2ids =
new TreeMap<StringBuilder, List<Integer>>(StringBuilderComparator.CASE_INSENSITIVE_ORDER);
this.name2ids = new TreeMap<StringBuilder, List<Integer>>(StringBuilderComparator.CASE_INSENSITIVE_ORDER);
this.kfz2ids = new TreeMap<StringBuilder, List<Integer>>(StringBuilderComparator.CASE_INSENSITIVE_ORDER);
this.predial2ids = new HashMap<String, List<Integer>>();
this.zip2id = new HashMap<String, Integer>();
@ -143,11 +137,13 @@ public class OpenGeoDBLocalization implements Localization
id = Integer.parseInt(v[0]);
h = removeQuotes(v[2]);
final Integer hc = h.hashCode();
final String t = this.locTypeHash2locType.get(hc);
if ( t == null ) {
this.locTypeHash2locType.put(hc, h);
/*
final byte[] tb = this.locTypeHash2locType.get(hc);
if ( tb == null ) {
this.locTypeHash2locType.put(hc, UTF8.getBytes(h));
}
this.id2locTypeHash.put(id, hc);
*/
} else if ( v[1].equals("500300000") ) { // PLZ
this.zip2id.put(removeQuotes(v[2]), Integer.parseInt(v[0]));
} else if ( v[1].equals("500500000") ) { // KFZ-Kennzeichen

@ -322,6 +322,7 @@ public final class Switchboard extends serverSwitch
getDataPath(SwitchboardConstants.HTDOCS_PATH, SwitchboardConstants.HTDOCS_PATH_DEFAULT);
this.log.logConfig("HTDOCS Path: " + this.htDocsPath.toString());
this.workPath = getDataPath(SwitchboardConstants.WORK_PATH, SwitchboardConstants.WORK_PATH_DEFAULT);
this.workPath.mkdirs();
this.log.logConfig("Work Path: " + this.workPath.toString());
this.dictionariesPath =
getDataPath(
@ -329,8 +330,16 @@ public final class Switchboard extends serverSwitch
SwitchboardConstants.DICTIONARY_SOURCE_PATH_DEFAULT);
this.log.logConfig("Dictionaries Path:" + this.dictionariesPath.toString());
// init libraries
this.log.logConfig("initializing libraries");
new Thread() {
@Override
public void run() {
LibraryProvider.initialize(Switchboard.this.dictionariesPath);
}
}.start();
// init global host name cache
this.workPath.mkdirs();
Domains.init(new File(this.workPath, "globalhosts.list"));
// init sessionid name file
@ -341,15 +350,6 @@ public final class Switchboard extends serverSwitch
// init tables
this.tables = new WorkTables(this.workPath);
// init libraries
this.log.logConfig("initializing libraries");
new Thread() {
@Override
public void run() {
LibraryProvider.initialize(Switchboard.this.dictionariesPath);
}
}.start();
// set a high maximum cache size to current size; this is adopted later automatically
final int wordCacheMaxCount = (int) getConfigLong(SwitchboardConstants.WORDCACHE_MAX_COUNT, 20000);
setConfig(SwitchboardConstants.WORDCACHE_MAX_COUNT, Integer.toString(wordCacheMaxCount));

Loading…
Cancel
Save