KompareDiff2

stringlistpair.cpp
1/*
2 SPDX-FileCopyrightText: 2011 Dmitry Risenberg <dmitry.risenberg@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "stringlistpair.h"
8
9// Qt
10#include <QHash>
11
12using namespace KompareDiff2;
13
14unsigned int StringListPair::lengthFirst() const
15{
16 return m_lengthFirst;
17}
18
19unsigned int StringListPair::lengthSecond() const
20{
21 return m_lengthSecond;
22}
23
24MarkerList StringListPair::markerListFirst() const
25{
26 return m_markersFirst;
27}
28
29MarkerList StringListPair::markerListSecond() const
30{
31 return m_markersSecond;
32}
33
34void StringListPair::prependFirst(Marker *marker)
35{
36 m_markersFirst.prepend(marker);
37}
38
39void StringListPair::prependSecond(Marker *marker)
40{
41 m_markersSecond.prepend(marker);
42}
43
44StringListPair::StringListPair(const QStringList &first, const QStringList &second)
45 : m_first(first)
46 , m_second(second)
47 // Do not forget about 1 virtual element - see LevenshteinTable
48 , m_lengthFirst(first.length() + 1)
49 , m_lengthSecond(second.length() + 1)
50 , m_hashesFirst(m_lengthFirst)
51 , m_hashesSecond(m_lengthSecond)
52{
53 m_hashesFirst[0] = qHash(QString());
54 for (unsigned int i = 1; i < m_lengthFirst; ++i) {
55 m_hashesFirst[i] = qHash(first[i - 1]);
56 }
57 m_hashesSecond[0] = qHash(QString());
58 for (unsigned int i = 1; i < m_lengthSecond; ++i) {
59 m_hashesSecond[i] = qHash(second[i - 1]);
60 }
61}
62
63StringListPair::~StringListPair() = default;
64
65bool StringListPair::equal(unsigned int firstIndex, unsigned int secondIndex) const
66{
67 if (m_hashesFirst[firstIndex] != m_hashesSecond[secondIndex]) {
68 return false;
69 }
70 if (firstIndex == 0 || secondIndex == 0) {
71 return firstIndex == 0 && secondIndex == 0;
72 }
73 return m_first[firstIndex - 1] == m_second[secondIndex - 1];
74}
75
76bool StringListPair::needFineGrainedOutput(unsigned int) const
77{
78 return true;
79}
KTEXTEDITOR_EXPORT size_t qHash(KTextEditor::Cursor cursor, size_t seed=0) noexcept
KompareDiff2 namespace.
void prepend(parameter_type value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:13:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.