move database to hashmap

This commit is contained in:
Eyck Jentzsch 2021-01-12 11:46:21 +01:00
parent 3cbbdbee92
commit fa4bd0ddd5
1 changed files with 10 additions and 9 deletions

View File

@ -34,8 +34,10 @@ import java.util.zip.GZIPInputStream;
import org.eclipse.collections.impl.map.mutable.UnifiedMap; import org.eclipse.collections.impl.map.mutable.UnifiedMap;
import org.mapdb.DB; import org.mapdb.DB;
import org.mapdb.DB.HashMapMaker;
import org.mapdb.DB.TreeMapSink; import org.mapdb.DB.TreeMapSink;
import org.mapdb.DBMaker; import org.mapdb.DBMaker;
import org.mapdb.HTreeMap;
import org.mapdb.Serializer; import org.mapdb.Serializer;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
@ -83,8 +85,6 @@ public class TextDbLoader implements IWaveformDbLoader {
/** The transactions. */ /** The transactions. */
Map<Long, ScvTx> transactions = null; Map<Long, ScvTx> transactions = null;
Map<Long, Long> id2index = new HashMap<>();
/** The attribute types. */ /** The attribute types. */
final Map<String, TxAttributeType> attributeTypes = UnifiedMap.newMap(); final Map<String, TxAttributeType> attributeTypes = UnifiedMap.newMap();
@ -117,7 +117,7 @@ public class TextDbLoader implements IWaveformDbLoader {
} }
public ScvTx getScvTx(long id) { public ScvTx getScvTx(long id) {
return transactions.get(id2index.get(id)); return transactions.get(id);
} }
/** /**
@ -187,9 +187,12 @@ public class TextDbLoader implements IWaveformDbLoader {
} }
TextDbParser parser = new TextDbParser(this); TextDbParser parser = new TextDbParser(this);
try { try {
parser.txSink = mapDb.treeMap("transactions", Serializer.LONG, Serializer.JAVA).createFromSink();
// parser.txSink = mapDb.treeMap("transactions", Serializer.LONG, Serializer.JAVA).createFromSink();
parser.txSink = mapDb.hashMap("transactions", Serializer.LONG, Serializer.JAVA).create();
parser.parseInput(gzipped ? new GZIPInputStream(new FileInputStream(file)) : new FileInputStream(file)); parser.parseInput(gzipped ? new GZIPInputStream(new FileInputStream(file)) : new FileInputStream(file));
transactions = parser.txSink.create(); // transactions = parser.txSink.create();
transactions = parser.txSink;
} catch (IllegalArgumentException | ArrayIndexOutOfBoundsException e) { } catch (IllegalArgumentException | ArrayIndexOutOfBoundsException e) {
} catch (Exception e) { } catch (Exception e) {
throw new InputFormatException(e.toString()); throw new InputFormatException(e.toString());
@ -281,7 +284,7 @@ public class TextDbLoader implements IWaveformDbLoader {
HashMap<Long, ScvTx> transactionById = new HashMap<>(); HashMap<Long, ScvTx> transactionById = new HashMap<>();
/** The tx sink. */ /** The tx sink. */
TreeMapSink<Long, ScvTx> txSink; HTreeMap<Long, ScvTx> txSink;
/** The reader. */ /** The reader. */
BufferedReader reader = null; BufferedReader reader = null;
@ -292,7 +295,6 @@ public class TextDbLoader implements IWaveformDbLoader {
/** The attr value lut. */ /** The attr value lut. */
Map<String, Integer> attrValueLut = new HashMap<>(); Map<String, Integer> attrValueLut = new HashMap<>();
long indexCount = 0;
/** /**
* Instantiates a new text db parser. * Instantiates a new text db parser.
* *
@ -412,8 +414,7 @@ public class TextDbLoader implements IWaveformDbLoader {
nextLine = reader.readLine(); nextLine = reader.readLine();
} }
} }
txSink.put(indexCount, scvTx); txSink.put(scvTx.getId(), scvTx);
loader.id2index.put(scvTx.getId(), indexCount++);
transactionById.remove(id); transactionById.remove(id);
} else if ("tx_relation".equals(tokens[0])) { } else if ("tx_relation".equals(tokens[0])) {
Long tr2 = Long.parseLong(tokens[2]); Long tr2 = Long.parseLong(tokens[2]);