use of org.h2.command.dml.Set in project h2database by h2database.
the class TestPerfectHash method testMinimal.
private int testMinimal(int size) {
Random r = new Random(size);
HashSet<Long> set = new HashSet<>(size);
while (set.size() < size) {
set.add((long) r.nextInt());
}
LongHash hf = new LongHash();
byte[] desc = MinimalPerfectHash.generate(set, hf);
int max = testMinimal(desc, set, hf);
assertEquals(size - 1, max);
return desc.length * 8;
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class TestPerfectHash method testMinimalWithString.
private int testMinimalWithString(int size) {
Random r = new Random(size);
HashSet<String> set = new HashSet<>(size);
while (set.size() < size) {
set.add("x " + r.nextDouble());
}
StringHash hf = new StringHash();
byte[] desc = MinimalPerfectHash.generate(set, hf);
int max = testMinimal(desc, set, hf);
assertEquals(size - 1, max);
return desc.length * 8;
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class TestPerfectHash method testBrokenHashFunction.
private void testBrokenHashFunction() {
int size = 10000;
Random r = new Random(10000);
HashSet<String> set = new HashSet<>(size);
while (set.size() < size) {
set.add("x " + r.nextDouble());
}
for (int test = 1; test < 10; test++) {
final int badUntilLevel = test;
UniversalHash<String> badHash = new UniversalHash<String>() {
@Override
public int hashCode(String o, int index, int seed) {
if (index < badUntilLevel) {
return 0;
}
return StringHash.getFastHash(o, index, seed);
}
};
byte[] desc = MinimalPerfectHash.generate(set, badHash);
testMinimal(desc, set, badHash);
}
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class TestPerfectHash method testMinimal.
private <K> int testMinimal(byte[] desc, Set<K> set, UniversalHash<K> hf) {
int max = -1;
BitSet test = new BitSet();
MinimalPerfectHash<K> hash = new MinimalPerfectHash<>(desc, hf);
for (K x : set) {
int h = hash.get(x);
assertTrue(h >= 0);
assertTrue(h <= set.size() * 3);
max = Math.max(max, h);
assertFalse(test.get(h));
test.set(h);
}
return max;
}
use of org.h2.command.dml.Set in project h2database by h2database.
the class TestRecovery method testCompressedAndUncompressed.
private void testCompressedAndUncompressed() throws SQLException {
DeleteDbFiles.execute(getBaseDir(), "recovery", true);
DeleteDbFiles.execute(getBaseDir(), "recovery2", true);
org.h2.Driver.load();
Connection conn = getConnection("recovery");
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, data clob)");
stat.execute("insert into test values(1, space(10000))");
stat.execute("set compress_lob lzf");
stat.execute("insert into test values(2, space(10000))");
conn.close();
Recover rec = new Recover();
rec.runTool("-dir", getBaseDir(), "-db", "recovery");
Connection conn2 = getConnection("recovery2");
Statement stat2 = conn2.createStatement();
String name = "recovery.h2.sql";
stat2.execute("runscript from '" + getBaseDir() + "/" + name + "'");
stat2.execute("select * from test");
conn2.close();
conn = getConnection("recovery");
stat = conn.createStatement();
conn2 = getConnection("recovery2");
stat2 = conn2.createStatement();
assertEqualDatabases(stat, stat2);
conn.close();
conn2.close();
DeleteDbFiles.execute(getBaseDir(), "recovery", true);
DeleteDbFiles.execute(getBaseDir(), "recovery2", true);
}
Aggregations