提交 8da4f1a0 authored 作者: Thomas Mueller's avatar Thomas Mueller

Perfect hash: small speedup

上级 08b98324
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
*/ */
package org.h2.test.unit; package org.h2.test.unit;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.util.BitSet; import java.util.BitSet;
...@@ -47,6 +48,10 @@ public class TestPerfectHash extends TestBase { ...@@ -47,6 +48,10 @@ public class TestPerfectHash extends TestBase {
private static void largeFile(String s) throws IOException { private static void largeFile(String s) throws IOException {
String fileName = System.getProperty("user.home") + "/temp/" + s; String fileName = System.getProperty("user.home") + "/temp/" + s;
if (!new File(fileName).exists()) {
System.out.println("not found: " + fileName);
return;
}
RandomAccessFile f = new RandomAccessFile(fileName, "r"); RandomAccessFile f = new RandomAccessFile(fileName, "r");
byte[] data = new byte[(int) f.length()]; byte[] data = new byte[(int) f.length()];
f.readFully(data); f.readFully(data);
......
...@@ -525,7 +525,7 @@ public class MinimalPerfectHash<K> { ...@@ -525,7 +525,7 @@ public class MinimalPerfectHash<K> {
x = ((x >>> 16) ^ x) * 0x45d9f3b; x = ((x >>> 16) ^ x) * 0x45d9f3b;
x = ((x >>> 16) ^ x) * 0x45d9f3b; x = ((x >>> 16) ^ x) * 0x45d9f3b;
x = (x >>> 16) ^ x; x = (x >>> 16) ^ x;
return Math.abs(x % size); return (x & (-1 >>> 1)) % size;
} }
private static <K> int hash(int x, int level, int offset, int size) { private static <K> int hash(int x, int level, int offset, int size) {
...@@ -533,7 +533,7 @@ public class MinimalPerfectHash<K> { ...@@ -533,7 +533,7 @@ public class MinimalPerfectHash<K> {
x = ((x >>> 16) ^ x) * 0x45d9f3b; x = ((x >>> 16) ^ x) * 0x45d9f3b;
x = ((x >>> 16) ^ x) * 0x45d9f3b; x = ((x >>> 16) ^ x) * 0x45d9f3b;
x = (x >>> 16) ^ x; x = (x >>> 16) ^ x;
return Math.abs(x % size); return (x & (-1 >>> 1)) % size;
} }
private static int writeVarInt(ByteArrayOutputStream out, int x) { private static int writeVarInt(ByteArrayOutputStream out, int x) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论