final int tIdx = hash(a, ptr); if (cmp.equals(a, recPtr(rec), a, ptr)) { int newCnt = recCnt(rec) + 1; if (MAX_CNT < newCnt) newCnt = MAX_CNT; recs[rIdx] = recCreate(recNext(rec), ptr, newCnt); next[ptr - ptrShift] = recPtr(rec); recIdx[ptr - ptrShift] = rIdx; continue SCAN; rIdx = recNext(rec); chainLen++; recs[rIdx] = recCreate(table[tIdx], ptr, 1); recIdx[ptr - ptrShift] = rIdx; table[tIdx] = rIdx;
Edit findLongestCommonSequence() { if (!scanA()) return null; lcs = new Edit(0, 0); cnt = maxChainLength + 1; for (int bPtr = region.beginB; bPtr < region.endB;) bPtr = tryLongestCommonSequence(bPtr); return hasCommon && maxChainLength < cnt ? null : lcs; }
HistogramDiffIndex(int maxChainLength, HashedSequenceComparator<S> cmp, HashedSequence<S> a, HashedSequence<S> b, Edit r) { this.maxChainLength = maxChainLength; this.cmp = cmp; this.a = a; this.b = b; this.region = r; if (region.endA >= MAX_PTR) throw new IllegalArgumentException( JGitText.get().sequenceTooLargeForDiffAlgorithm); final int sz = r.getLengthA(); final int tableBits = tableBits(sz); table = new int[1 << tableBits]; keyShift = 32 - tableBits; ptrShift = r.beginA; recs = new long[Math.max(4, sz >>> 3)]; next = new int[sz]; recIdx = new int[sz]; }
private void diffReplace(Edit r) { Edit lcs = new HistogramDiffIndex<>(maxChainLength, cmp, a, b, r) .findLongestCommonSequence(); if (lcs != null) { // If we were given an edit, we can prove a result here. // if (lcs.isEmpty()) { // An empty edit indicates there is nothing in common. // Replace the entire region. // edits.add(r); } else { queue.add(r.after(lcs)); queue.add(r.before(lcs)); } } else if (fallback instanceof LowLevelDiffAlgorithm) { LowLevelDiffAlgorithm fb = (LowLevelDiffAlgorithm) fallback; fb.diffNonCommon(edits, cmp, a, b, r); } else if (fallback != null) { SubsequenceComparator<HashedSequence<S>> cs = subcmp(); Subsequence<HashedSequence<S>> as = Subsequence.a(a, r); Subsequence<HashedSequence<S>> bs = Subsequence.b(b, r); EditList res = fallback.diffNonCommon(cs, as, bs); edits.addAll(Subsequence.toBase(res, as, bs)); } else { edits.add(r); } }
private void diffReplace(Edit r) { Edit lcs = new HistogramDiffIndex<>(maxChainLength, cmp, a, b, r) .findLongestCommonSequence(); if (lcs != null) { // If we were given an edit, we can prove a result here. // if (lcs.isEmpty()) { // An empty edit indicates there is nothing in common. // Replace the entire region. // edits.add(r); } else { queue.add(r.after(lcs)); queue.add(r.before(lcs)); } } else if (fallback instanceof LowLevelDiffAlgorithm) { LowLevelDiffAlgorithm fb = (LowLevelDiffAlgorithm) fallback; fb.diffNonCommon(edits, cmp, a, b, r); } else if (fallback != null) { SubsequenceComparator<HashedSequence<S>> cs = subcmp(); Subsequence<HashedSequence<S>> as = Subsequence.a(a, r); Subsequence<HashedSequence<S>> bs = Subsequence.b(b, r); EditList res = fallback.diffNonCommon(cs, as, bs); edits.addAll(Subsequence.toBase(res, as, bs)); } else { edits.add(r); } }
private int tryLongestCommonSequence(int bPtr) { int bNext = bPtr + 1; int rIdx = table[hash(b, bPtr)]; for (long rec; rIdx != 0; rIdx = recNext(rec)) { rec = recs[rIdx]; if (recCnt(rec) > cnt) { if (!hasCommon) hasCommon = cmp.equals(a, recPtr(rec), b, bPtr); continue; int as = recPtr(rec); if (!cmp.equals(a, as, b, bPtr)) continue; int ae = as + 1; int be = bs + 1; int rc = recCnt(rec); bs--; if (1 < rc) rc = Math.min(rc, recCnt(recs[recIdx[as - ptrShift]])); rc = Math.min(rc, recCnt(recs[recIdx[ae - ptrShift]])); ae++; be++;
Edit findLongestCommonSequence() { if (!scanA()) return null; lcs = new Edit(0, 0); cnt = maxChainLength + 1; for (int bPtr = region.beginB; bPtr < region.endB;) bPtr = tryLongestCommonSequence(bPtr); return hasCommon && maxChainLength < cnt ? null : lcs; }
private void diffReplace(Edit r) { Edit lcs = new HistogramDiffIndex<S>(maxChainLength, cmp, a, b, r) .findLongestCommonSequence(); if (lcs != null) { // If we were given an edit, we can prove a result here. // if (lcs.isEmpty()) { // An empty edit indicates there is nothing in common. // Replace the entire region. // edits.add(r); } else { queue.add(r.after(lcs)); queue.add(r.before(lcs)); } } else if (fallback instanceof LowLevelDiffAlgorithm) { LowLevelDiffAlgorithm fb = (LowLevelDiffAlgorithm) fallback; fb.diffNonCommon(edits, cmp, a, b, r); } else if (fallback != null) { SubsequenceComparator<HashedSequence<S>> cs = subcmp(); Subsequence<HashedSequence<S>> as = Subsequence.a(a, r); Subsequence<HashedSequence<S>> bs = Subsequence.b(b, r); EditList res = fallback.diffNonCommon(cs, as, bs); edits.addAll(Subsequence.toBase(res, as, bs)); } else { edits.add(r); } }
HistogramDiffIndex(int maxChainLength, HashedSequenceComparator<S> cmp, HashedSequence<S> a, HashedSequence<S> b, Edit r) { this.maxChainLength = maxChainLength; this.cmp = cmp; this.a = a; this.b = b; this.region = r; if (region.endA >= MAX_PTR) throw new IllegalArgumentException( JGitText.get().sequenceTooLargeForDiffAlgorithm); final int sz = r.getLengthA(); final int tableBits = tableBits(sz); table = new int[1 << tableBits]; keyShift = 32 - tableBits; ptrShift = r.beginA; recs = new long[Math.max(4, sz >>> 3)]; next = new int[sz]; recIdx = new int[sz]; }
final int tIdx = hash(a, ptr); if (cmp.equals(a, recPtr(rec), a, ptr)) { int newCnt = recCnt(rec) + 1; if (MAX_CNT < newCnt) newCnt = MAX_CNT; recs[rIdx] = recCreate(recNext(rec), ptr, newCnt); next[ptr - ptrShift] = recPtr(rec); recIdx[ptr - ptrShift] = rIdx; continue SCAN; rIdx = recNext(rec); chainLen++; recs[rIdx] = recCreate(table[tIdx], ptr, 1); recIdx[ptr - ptrShift] = rIdx; table[tIdx] = rIdx;
Edit findLongestCommonSequence() { if (!scanA()) return null; lcs = new Edit(0, 0); cnt = maxChainLength + 1; for (int bPtr = region.beginB; bPtr < region.endB;) bPtr = tryLongestCommonSequence(bPtr); return hasCommon && maxChainLength < cnt ? null : lcs; }
HistogramDiffIndex(int maxChainLength, HashedSequenceComparator<S> cmp, HashedSequence<S> a, HashedSequence<S> b, Edit r) { this.maxChainLength = maxChainLength; this.cmp = cmp; this.a = a; this.b = b; this.region = r; if (region.endA >= MAX_PTR) throw new IllegalArgumentException( JGitText.get().sequenceTooLargeForDiffAlgorithm); final int sz = r.getLengthA(); final int tableBits = tableBits(sz); table = new int[1 << tableBits]; keyShift = 32 - tableBits; ptrShift = r.beginA; recs = new long[Math.max(4, sz >>> 3)]; next = new int[sz]; recIdx = new int[sz]; }
final int tIdx = hash(a, ptr); if (cmp.equals(a, recPtr(rec), a, ptr)) { int newCnt = recCnt(rec) + 1; if (MAX_CNT < newCnt) newCnt = MAX_CNT; recs[rIdx] = recCreate(recNext(rec), ptr, newCnt); next[ptr - ptrShift] = recPtr(rec); recIdx[ptr - ptrShift] = rIdx; continue SCAN; rIdx = recNext(rec); chainLen++; recs[rIdx] = recCreate(table[tIdx], ptr, 1); recIdx[ptr - ptrShift] = rIdx; table[tIdx] = rIdx;
private int tryLongestCommonSequence(final int bPtr) { int bNext = bPtr + 1; int rIdx = table[hash(b, bPtr)]; for (long rec; rIdx != 0; rIdx = recNext(rec)) { rec = recs[rIdx]; if (recCnt(rec) > cnt) { if (!hasCommon) hasCommon = cmp.equals(a, recPtr(rec), b, bPtr); continue; int as = recPtr(rec); if (!cmp.equals(a, as, b, bPtr)) continue; int ae = as + 1; int be = bs + 1; int rc = recCnt(rec); bs--; if (1 < rc) rc = Math.min(rc, recCnt(recs[recIdx[as - ptrShift]])); rc = Math.min(rc, recCnt(recs[recIdx[ae - ptrShift]])); ae++; be++;
private int tryLongestCommonSequence(int bPtr) { int bNext = bPtr + 1; int rIdx = table[hash(b, bPtr)]; for (long rec; rIdx != 0; rIdx = recNext(rec)) { rec = recs[rIdx]; if (recCnt(rec) > cnt) { if (!hasCommon) hasCommon = cmp.equals(a, recPtr(rec), b, bPtr); continue; int as = recPtr(rec); if (!cmp.equals(a, as, b, bPtr)) continue; int ae = as + 1; int be = bs + 1; int rc = recCnt(rec); bs--; if (1 < rc) rc = Math.min(rc, recCnt(recs[recIdx[as - ptrShift]])); rc = Math.min(rc, recCnt(recs[recIdx[ae - ptrShift]])); ae++; be++;