org.openstreetmap.atlas.utilities.compression.LongDictionary Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of atlas Show documentation
Show all versions of atlas Show documentation
"Library to load OSM data into an Atlas format"
package org.openstreetmap.atlas.utilities.compression;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* Simple dictionary encoding for {@link String}s
*
* @author matthieun
* @param
* The type to encode. Typically called word
*/
public class LongDictionary implements Serializable
{
private static final long serialVersionUID = 6060400113166584385L;
private final Map wordToIndex;
private final Map indexToWord;
private long index = 0;
public LongDictionary()
{
this.wordToIndex = new HashMap<>();
this.indexToWord = new HashMap<>();
}
public synchronized long add(final Type word)
{
if (this.wordToIndex.containsKey(word))
{
return this.wordToIndex.get(word);
}
this.wordToIndex.put(word, this.index);
this.indexToWord.put(this.index, word);
return this.index++;
}
public Type word(final long index)
{
return this.indexToWord.get(index);
}
}