Remove unnecessary hash cache from PatienceDiffIndex

PatienceDiff always uses a HashedSequence, which promises to provide
constant time access for hash codes during the equals method and
aborts fast if the hash codes don't match.  Therefore we don't need
to cache the hash codes inside of the index, saving us memory.

Change-Id: I80bf1e95094b7670e6c0acc26546364a1012d60e
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
Shawn O. Pearce 2010-09-21 13:53:56 -07:00
parent a67afbfee1
commit e84d826eb6
1 changed files with 15 additions and 40 deletions

View File

@ -100,9 +100,6 @@ final class PatienceDiffIndex<S extends Sequence> {
// arrays. This permits us to get 3 values per entry, without paying
// the penalty for an object header on each entry.
/** Cached hash value for an element as returned by {@link #cmp}. */
private final int[] hash;
/**
* A matched (or partially examined) element from the two sequences.
*
@ -160,26 +157,15 @@ final class PatienceDiffIndex<S extends Sequence> {
this.pBegin = pIdx;
this.pEnd = pCnt;
final int blockCnt = region.getLengthB();
if (blockCnt < 1) {
table = new int[] {};
tableMask = 0;
final int sz = region.getLengthB();
table = new int[tableSize(sz)];
tableMask = table.length - 1;
hash = new int[] {};
ptrs = new long[] {};
next = new int[] {};
} else {
table = new int[tableSize(blockCnt)];
tableMask = table.length - 1;
// As we insert elements we preincrement so that 0 is never a
// valid entry. Therefore we have to allocate one extra space.
//
hash = new int[1 + blockCnt];
ptrs = new long[hash.length];
next = new int[hash.length];
}
// As we insert elements we preincrement so that 0 is never a
// valid entry. Therefore we have to allocate one extra space.
//
ptrs = new long[1 + sz];
next = new int[ptrs.length];
}
/**
@ -201,8 +187,7 @@ private void scanB() {
final int end = region.endB;
int pIdx = pBegin;
SCAN: while (ptr < end) {
final int key = cmp.hash(b, ptr);
final int tIdx = key & tableMask;
final int tIdx = cmp.hash(b, ptr) & tableMask;
if (pIdx < pEnd) {
final long priorRec = pCommon[pIdx];
@ -210,7 +195,7 @@ private void scanB() {
// We know this region is unique from a prior pass.
// Insert the start point, and skip right to the end.
//
insertB(key, tIdx, ptr);
insertB(tIdx, ptr);
pIdx++;
ptr = aOfRaw(priorRec);
continue SCAN;
@ -222,9 +207,6 @@ private void scanB() {
// was already a different entry present.
//
for (int eIdx = table[tIdx]; eIdx != 0; eIdx = next[eIdx]) {
if (hash[eIdx] != key)
continue;
final long rec = ptrs[eIdx];
if (cmp.equals(b, ptr, b, bOf(rec))) {
ptrs[eIdx] = rec | B_DUPLICATE;
@ -233,14 +215,13 @@ private void scanB() {
}
}
insertB(key, tIdx, ptr);
insertB(tIdx, ptr);
ptr++;
}
}
private void insertB(final int key, final int tIdx, int ptr) {
private void insertB(final int tIdx, int ptr) {
final int eIdx = ++entryCnt;
hash[eIdx] = key;
ptrs[eIdx] = ((long) ptr) << B_SHIFT;
next[eIdx] = table[tIdx];
table[tIdx] = eIdx;
@ -263,13 +244,13 @@ private void scanA() {
final int end = region.endA;
int pLast = pBegin - 1;
SCAN: while (ptr < end) {
final int key = cmp.hash(a, ptr);
final int tIdx = key & tableMask;
final int tIdx = cmp.hash(a, ptr) & tableMask;
for (int eIdx = table[tIdx]; eIdx != 0; eIdx = next[eIdx]) {
final long rec = ptrs[eIdx];
final int bs = bOf(rec);
if (isDuplicate(rec) || hash[eIdx] != key)
if (isDuplicate(rec) || !cmp.equals(a, ptr, b, bs))
continue;
final int aPtr = aOfRaw(rec);
@ -280,12 +261,6 @@ private void scanA() {
continue SCAN;
}
final int bs = bOf(rec);
if (!cmp.equals(a, ptr, b, bs)) {
ptr++;
continue SCAN;
}
// This element is both common and unique. Link the
// two sequences together at this point.
//