don't use static StringCompressor in TagEncoderDecoder
This commit is contained in:
@@ -129,7 +129,7 @@ public class DataStore implements AutoCloseable {
|
||||
diskStorage = new PartitionDiskStore(storageBasePath, "data.bs");
|
||||
|
||||
tagToDocsId = new PartitionPersistentMap<>(storageBasePath, "keyToValueToDocIdsIndex.bs",
|
||||
new TagEncoderDecoder(), PartitionAwareWrapper.wrap(PersistentMap.LONG_CODER));
|
||||
new TagEncoderDecoder(stringCompressor), PartitionAwareWrapper.wrap(PersistentMap.LONG_CODER));
|
||||
|
||||
tagsToDocId = new PartitionPersistentMap<>(storageBasePath, "tagsToDocIdIndex.bs", new TagsEncoderDecoder(),
|
||||
PartitionAwareWrapper.wrap(PersistentMap.LONG_CODER));
|
||||
|
||||
@@ -1,26 +1,32 @@
|
||||
package org.lucares.pdb.datastore.internal;
|
||||
|
||||
import org.lucares.collections.LongList;
|
||||
import org.lucares.pdb.api.StringCompressor;
|
||||
import org.lucares.pdb.api.Tag;
|
||||
import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.pdb.map.PersistentMap.EncoderDecoder;
|
||||
import org.lucares.utils.byteencoder.VariableByteEncoder;
|
||||
|
||||
class TagEncoderDecoder implements EncoderDecoder<Tag> {
|
||||
private final StringCompressor stringCompressor;
|
||||
|
||||
public TagEncoderDecoder(final StringCompressor stringCompressor) {
|
||||
this.stringCompressor = stringCompressor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encode(final Tag tag) {
|
||||
|
||||
final LongList keyAndValueCompressed = new LongList(2);
|
||||
|
||||
final String key = Tags.STRING_COMPRESSOR.getKeyAsString(tag);
|
||||
final String key = stringCompressor.getKeyAsString(tag);
|
||||
final byte[] result;
|
||||
if (!key.isEmpty()) {
|
||||
final Integer keyAsLong = Tags.STRING_COMPRESSOR.put(key);
|
||||
final Integer keyAsLong = stringCompressor.put(key);
|
||||
keyAndValueCompressed.add(keyAsLong);
|
||||
|
||||
final String value = Tags.STRING_COMPRESSOR.getValueAsString(tag);
|
||||
final String value = stringCompressor.getValueAsString(tag);
|
||||
if (!value.isEmpty()) {
|
||||
final Integer valueAsLong = Tags.STRING_COMPRESSOR.put(value);
|
||||
final Integer valueAsLong = stringCompressor.put(value);
|
||||
keyAndValueCompressed.add(valueAsLong);
|
||||
}
|
||||
result = VariableByteEncoder.encode(keyAndValueCompressed);
|
||||
@@ -38,17 +44,17 @@ class TagEncoderDecoder implements EncoderDecoder<Tag> {
|
||||
switch (compressedStrings.size()) {
|
||||
case 0:
|
||||
|
||||
result = Tags.STRING_COMPRESSOR.createTag("", "");
|
||||
result = stringCompressor.createTag("", "");
|
||||
break;
|
||||
case 1:
|
||||
final String k = Tags.STRING_COMPRESSOR.get((int) compressedStrings.get(0));
|
||||
result = Tags.STRING_COMPRESSOR.createTag(k, "");
|
||||
final String k = stringCompressor.get((int) compressedStrings.get(0));
|
||||
result = stringCompressor.createTag(k, "");
|
||||
|
||||
break;
|
||||
case 2:
|
||||
final String key = Tags.STRING_COMPRESSOR.get((int) compressedStrings.get(0));
|
||||
final String value = Tags.STRING_COMPRESSOR.get((int) compressedStrings.get(1));
|
||||
result = Tags.STRING_COMPRESSOR.createTag(key, value);
|
||||
final String key = stringCompressor.get((int) compressedStrings.get(0));
|
||||
final String value = stringCompressor.get((int) compressedStrings.get(1));
|
||||
result = stringCompressor.createTag(key, value);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("too many values: " + compressedStrings);
|
||||
|
||||
Reference in New Issue
Block a user