rewrite query completion
The old implementation searched for all possible values and then executed each query to see what matches. The new implementation uses several indices to find only the matching values.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package org.lucares.pdb.map;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.lucares.collections.LongList;
|
||||
import org.lucares.utils.file.FileUtils;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class PersistentMapOfListsOfLongsTest {
|
||||
|
||||
private Path dataDirectory;
|
||||
|
||||
@BeforeMethod
|
||||
public void beforeMethod() throws IOException {
|
||||
dataDirectory = Files.createTempDirectory("pdb");
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
public void afterMethod() throws IOException {
|
||||
FileUtils.delete(dataDirectory);
|
||||
}
|
||||
|
||||
public void test() throws IOException {
|
||||
|
||||
final String mapFilePrefix = "test";
|
||||
final String keyA = "a";
|
||||
final String keyB = "b";
|
||||
|
||||
final int size = 10;
|
||||
final LongList a = LongList.range(0, size);
|
||||
a.shuffle();
|
||||
final LongList b = LongList.range(0, size);
|
||||
b.shuffle();
|
||||
|
||||
try (PersistentMapOfListsOfLongs<String> map = new PersistentMapOfListsOfLongs<>(dataDirectory, mapFilePrefix,
|
||||
PersistentMap.STRING_CODER)) {
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
map.appendLong(keyA, a.get(i));
|
||||
map.appendLong(keyB, b.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
try (PersistentMapOfListsOfLongs<String> map = new PersistentMapOfListsOfLongs<>(dataDirectory, mapFilePrefix,
|
||||
PersistentMap.STRING_CODER)) {
|
||||
|
||||
final LongList actualA = new LongList();
|
||||
map.getLongs(keyA).forEachOrdered(actualA::addAll);
|
||||
Assert.assertEquals(actualA, a);
|
||||
|
||||
final LongList actualB = new LongList();
|
||||
map.getLongs(keyB).forEachOrdered(actualB::addAll);
|
||||
Assert.assertEquals(actualB, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user