KompareDiff2

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

KDE's Doxygen guidelines are available online.