File indexing completed on 2024-04-21 05:44:11
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 // Qt 0010 #include <QHash> 0011 0012 using namespace KompareDiff2; 0013 0014 unsigned int StringListPair::lengthFirst() const 0015 { 0016 return m_lengthFirst; 0017 } 0018 0019 unsigned int StringListPair::lengthSecond() const 0020 { 0021 return m_lengthSecond; 0022 } 0023 0024 MarkerList StringListPair::markerListFirst() const 0025 { 0026 return m_markersFirst; 0027 } 0028 0029 MarkerList StringListPair::markerListSecond() const 0030 { 0031 return m_markersSecond; 0032 } 0033 0034 void StringListPair::prependFirst(Marker *marker) 0035 { 0036 m_markersFirst.prepend(marker); 0037 } 0038 0039 void StringListPair::prependSecond(Marker *marker) 0040 { 0041 m_markersSecond.prepend(marker); 0042 } 0043 0044 StringListPair::StringListPair(const QStringList &first, const QStringList &second) 0045 : m_first(first) 0046 , m_second(second) 0047 // Do not forget about 1 virtual element - see LevenshteinTable 0048 , m_lengthFirst(first.length() + 1) 0049 , m_lengthSecond(second.length() + 1) 0050 , m_hashesFirst(m_lengthFirst) 0051 , m_hashesSecond(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() = default; 0064 0065 bool StringListPair::equal(unsigned int firstIndex, unsigned int secondIndex) const 0066 { 0067 if (m_hashesFirst[firstIndex] != m_hashesSecond[secondIndex]) { 0068 return false; 0069 } 0070 if (firstIndex == 0 || secondIndex == 0) { 0071 return firstIndex == 0 && secondIndex == 0; 0072 } 0073 return m_first[firstIndex - 1] == m_second[secondIndex - 1]; 0074 } 0075 0076 bool StringListPair::needFineGrainedOutput(unsigned int) const 0077 { 0078 return true; 0079 }