Repository navigation
Expand file tree
/
Copy pathMainwindow.cpp
More file actions
75 lines (65 loc) · 2.38 KB
/
Copy pathMainwindow.cpp
File metadata and controls
75 lines (65 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "Mainwindow.h"
Mainwindow::Mainwindow(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
Mainwindow::~Mainwindow()
{}
void Mainwindow::on_fileChoose_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("C Files (*.c)"));
if (!fileName.isEmpty()) {
currentFilePath = fileName;
ui.showFileDir->setText(fileName);
updateCodePreviewer(fileName);
}
}
void Mainwindow::on_startSearch_clicked()
{
if (!currentFilePath.isEmpty()) {
hashTable.statistic(currentFilePath);
binarySearch.statistic(currentFilePath);
updateResultsViewer();
}
}
void Mainwindow::updateCodePreviewer(const QString& filePath)
{
QFile file(filePath);
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream in(&file);
ui.codePreviewer->setText(in.readAll());
}
}
void Mainwindow::updateResultsViewer()
{
// 获取HashTable的结果
auto hashResults = hashTable.getResults();
int hashSearchCount = hashTable.getSearchCount();
qint64 hashElapsedTime = hashTable.getElapsedTime();
QString hashResultsStr = "HashTable Results:\n";
hashResultsStr += "Search Count: " + QString::number(hashSearchCount) + "\n";
hashResultsStr += "Elapsed Time: " + QString::number(hashElapsedTime) + " ms\n";
hashResultsStr += "Keywords and Frequencies:\n";
for (auto it = hashResults.constBegin(); it != hashResults.constEnd(); ++it)
{
hashResultsStr += it.key() + ": " + QString::number(it.value()) + "\n";
}
// 获取BinarySearch的结果
auto binaryResults = binarySearch.getResults();
int binarySearchCount = binarySearch.getSearchCount();
qint64 binaryElapsedTime = binarySearch.getElapsedTime();
QString binaryResultsStr = "BinarySearch Results:\n";
binaryResultsStr += "Search Count: " + QString::number(binarySearchCount) + "\n";
binaryResultsStr += "Elapsed Time: " + QString::number(binaryElapsedTime) + " ms\n";
binaryResultsStr += "Keywords and Frequencies:\n";
for (auto it = binaryResults.constBegin(); it != binaryResults.constEnd(); ++it)
{
if (it.value() == 0) continue;
binaryResultsStr += it.key() + ": " + QString::number(it.value()) + "\n";
}
// 更新UI组件
ui.hashResultViewer->setText(hashResultsStr);
ui.binaryResultViewer->setText(binaryResultsStr);
}