mirror of
https://github.com/apache/lucene.git
synced 2025-03-03 14:59:16 +00:00
use more efficient quadratic hash impl; remove dead code
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1045053 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5106f914e8
commit
d2665fd86e
@ -28,8 +28,6 @@ final class NodeHash<T> {
|
|||||||
private final FST<T> fst;
|
private final FST<T> fst;
|
||||||
private final FST.Arc<T> scratchArc = new FST.Arc<T>();
|
private final FST.Arc<T> scratchArc = new FST.Arc<T>();
|
||||||
|
|
||||||
public static int conf;
|
|
||||||
|
|
||||||
public NodeHash(FST<T> fst) {
|
public NodeHash(FST<T> fst) {
|
||||||
table = new int[16];
|
table = new int[16];
|
||||||
mask = 15;
|
mask = 15;
|
||||||
@ -113,10 +111,9 @@ final class NodeHash<T> {
|
|||||||
public int add(Builder.UnCompiledNode<T> node) throws IOException {
|
public int add(Builder.UnCompiledNode<T> node) throws IOException {
|
||||||
// System.out.println("hash: add count=" + count + " vs " + table.length);
|
// System.out.println("hash: add count=" + count + " vs " + table.length);
|
||||||
final int h = hash(node);
|
final int h = hash(node);
|
||||||
int h2 = h;
|
int pos = h & mask;
|
||||||
int c = 1;
|
int c = 0;
|
||||||
while(true) {
|
while(true) {
|
||||||
final int pos = h2 & mask;
|
|
||||||
final int v = table[pos];
|
final int v = table[pos];
|
||||||
if (v == 0) {
|
if (v == 0) {
|
||||||
// freeze & add
|
// freeze & add
|
||||||
@ -135,28 +132,22 @@ final class NodeHash<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// quadratic probe
|
// quadratic probe
|
||||||
h2 = h+(c + c*c)/2;
|
pos = (pos + (++c)) & mask;
|
||||||
c++;
|
|
||||||
conf++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// called only by rehash
|
// called only by rehash
|
||||||
private void addNew(int address) throws IOException {
|
private void addNew(int address) throws IOException {
|
||||||
final int h = hash(address);
|
int pos = hash(address) & mask;
|
||||||
int h2 = h;
|
int c = 0;
|
||||||
int c = 1;
|
|
||||||
while(true) {
|
while(true) {
|
||||||
final int pos = h2 & mask;
|
|
||||||
if (table[pos] == 0) {
|
if (table[pos] == 0) {
|
||||||
table[pos] = address;
|
table[pos] = address;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// quadratic probe
|
// quadratic probe
|
||||||
h2 = h + (c + c*c)/2;
|
pos = (pos + (++c)) & mask;
|
||||||
c++;
|
|
||||||
conf++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user