File indexing completed on 2024-04-28 17:01:43

0001 /*
0002 SPDX-FileCopyrightText: 2011 Dmitry Risenberg <dmitry.risenberg@gmail.com>
0003 
0004 SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "stringlistpair.h"
0008 
0009 #include <QHash>
0010 
0011 using namespace Diff2;
0012 
0013 unsigned int StringListPair::lengthFirst() const
0014 {
0015     return m_lengthFirst;
0016 }
0017 
0018 unsigned int StringListPair::lengthSecond() const
0019 {
0020     return m_lengthSecond;
0021 }
0022 
0023 MarkerList StringListPair::markerListFirst() const
0024 {
0025     return m_markersFirst;
0026 }
0027 
0028 MarkerList StringListPair::markerListSecond() const
0029 {
0030     return m_markersSecond;
0031 }
0032 
0033 void StringListPair::prependFirst(Marker* marker)
0034 {
0035     m_markersFirst.prepend(marker);
0036 }
0037 
0038 void StringListPair::prependSecond(Marker* marker)
0039 {
0040     m_markersSecond.prepend(marker);
0041 }
0042 
0043 StringListPair::StringListPair(const QStringList& first, const QStringList& second)
0044     : m_first(first), m_second(second)
0045 {
0046     // Do not forget about 1 virtual element - see LevenshteinTable
0047     m_lengthFirst = first.length() + 1;
0048     m_lengthSecond = second.length() + 1;
0049 
0050     m_hashesFirst = new unsigned int[m_lengthFirst];
0051     m_hashesSecond = new unsigned int[m_lengthSecond];
0052 
0053     m_hashesFirst[0] = qHash(QString());
0054     for (unsigned int i = 1; i < m_lengthFirst; ++i) {
0055         m_hashesFirst[i] = qHash(first[i - 1]);
0056     }
0057     m_hashesSecond[0] = qHash(QString());
0058     for (unsigned int i = 1; i < m_lengthSecond; ++i) {
0059         m_hashesSecond[i] = qHash(second[i - 1]);
0060     }
0061 }
0062 
0063 StringListPair::~StringListPair()
0064 {
0065     delete[] m_hashesFirst;
0066     delete[] m_hashesSecond;
0067 }
0068 
0069 bool StringListPair::equal(unsigned int firstIndex, unsigned int secondIndex) const
0070 {
0071     if (m_hashesFirst[firstIndex] != m_hashesSecond[secondIndex]) {
0072         return false;
0073     }
0074     if (firstIndex == 0 || secondIndex == 0) {
0075         return firstIndex == 0 && secondIndex == 0;
0076     }
0077     return m_first[firstIndex - 1] == m_second[secondIndex - 1];
0078 }
0079 
0080 bool StringListPair::needFineGrainedOutput(unsigned int) const
0081 {
0082     return true;
0083 }