1 /* 2 * Copyright (C) 2010, Google Inc. and others 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the Eclipse Distribution License v. 1.0 which is available at 6 * https://www.eclipse.org/org/documents/edl-v10.php. 7 * 8 * SPDX-License-Identifier: BSD-3-Clause 9 */ 10 11 package org.eclipse.jgit.diff; 12 13 /** 14 * Compares two sequences primarily based upon hash codes. 15 */ 16 public abstract class LowLevelDiffAlgorithm extends DiffAlgorithm { 17 /** {@inheritDoc} */ 18 @Override 19 public <S extends Sequence> EditList diffNonCommon( 20 SequenceComparator<? super S> cmp, S a, S b) { 21 HashedSequencePair<S> p = new HashedSequencePair<>(cmp, a, b); 22 HashedSequenceComparator<S> hc = p.getComparator(); 23 HashedSequence<S> ha = p.getA(); 24 HashedSequence<S> hb = p.getB(); 25 p = null; 26 27 EditList res = new EditList(); 28 Edit region = new Edit(0, a.size(), 0, b.size()); 29 diffNonCommon(res, hc, ha, hb, region); 30 return res; 31 } 32 33 /** 34 * Compare two sequences and identify a list of edits between them. 35 * 36 * This method should be invoked only after the two sequences have been 37 * proven to have no common starting or ending elements. The expected 38 * elimination of common starting and ending elements is automatically 39 * performed by the {@link #diff(SequenceComparator, Sequence, Sequence)} 40 * method, which invokes this method using 41 * {@link org.eclipse.jgit.diff.Subsequence}s. 42 * 43 * @param edits 44 * result list to append the region's edits onto. 45 * @param cmp 46 * the comparator supplying the element equivalence function. 47 * @param a 48 * the first (also known as old or pre-image) sequence. Edits 49 * returned by this algorithm will reference indexes using the 50 * 'A' side: {@link org.eclipse.jgit.diff.Edit#getBeginA()}, 51 * {@link org.eclipse.jgit.diff.Edit#getEndA()}. 52 * @param b 53 * the second (also known as new or post-image) sequence. Edits 54 * returned by this algorithm will reference indexes using the 55 * 'B' side: {@link org.eclipse.jgit.diff.Edit#getBeginB()}, 56 * {@link org.eclipse.jgit.diff.Edit#getEndB()}. 57 * @param region 58 * the region being compared within the two sequences. 59 */ 60 public abstract <S extends Sequence> void diffNonCommon(EditList edits, 61 HashedSequenceComparator<S> cmp, HashedSequence<S> a, 62 HashedSequence<S> b, Edit region); 63 }