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