fix thread linker crash and other minor improvements

This commit is contained in:
Akash Mozumdar 2021-06-05 02:20:04 -06:00
parent b4aa113fac
commit d74dcdc286
4 changed files with 32 additions and 22 deletions

View File

@ -16,6 +16,13 @@
<item>
<widget class="QLineEdit" name="regexEdit"/>
</item>
<item>
<widget class="QPushButton" name="saveButton">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -28,13 +35,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveButton">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel">
<property name="text">

View File

@ -16,10 +16,10 @@ std::vector<int> GenerateSuffixArray(const std::wstring& text)
eqClasses[suffixArray[0]] = 0;
for (int i = 1; i < text.size(); ++i)
{
int currentSuffix = suffixArray[i];
int lastSuffix = suffixArray[i - 1];
int currentSuffix = suffixArray[i], lastSuffix = suffixArray[i - 1];
if (currentSuffix + length < text.size() && prevEqClasses[currentSuffix] == prevEqClasses[lastSuffix] &&
prevEqClasses[currentSuffix + length / 2] == prevEqClasses.at(lastSuffix + length / 2)) // not completely certain that this will stay in range
prevEqClasses[currentSuffix + length / 2] == prevEqClasses[lastSuffix + length / 2]
)
eqClasses[currentSuffix] = eqClasses[lastSuffix];
else eqClasses[currentSuffix] = i;
}

View File

@ -4,11 +4,12 @@
extern const char* THREAD_LINKER;
extern const char* LINK;
extern const char* UNLINK;
extern const char* THREAD_LINK_FROM;
extern const char* THREAD_LINK_TO;
extern const char* HEXADECIMAL;
std::unordered_map<int64_t, std::unordered_multiset<int64_t>> linkedTextHandles;
std::unordered_map<int64_t, std::unordered_set<int64_t>> linkedTextHandles;
std::shared_mutex m;
class Window : public QDialog, Localizer
@ -17,9 +18,14 @@ public:
Window() : QDialog(nullptr, Qt::WindowMinMaxButtonsHint)
{
connect(&linkButton, &QPushButton::clicked, this, &Window::Link);
connect(&unlinkButton, &QPushButton::clicked, this, &Window::Unlink);
layout.addWidget(&linkList);
layout.addWidget(&linkButton);
layout.addLayout(&buttons);
buttons.addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
buttons.addWidget(&linkButton);
buttons.addWidget(&unlinkButton);
buttons.addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding));
setWindowTitle(THREAD_LINKER);
QMetaObject::invokeMethod(this, &QWidget::show, Qt::QueuedConnection);
@ -34,14 +40,13 @@ private:
if (ok1 && ok2 && ok3 && ok4)
{
std::scoped_lock lock(m);
linkedTextHandles[from].insert(to);
linkList.addItem(QString::number(from, 16) + "->" + QString::number(to, 16));
if (linkedTextHandles[from].insert(to).second) linkList.addItem(QString::number(from, 16) + "->" + QString::number(to, 16));
}
}
void keyPressEvent(QKeyEvent* event) override
void Unlink()
{
if (event->key() == Qt::Key_Delete && linkList.currentItem())
if (linkList.currentItem())
{
QStringList link = linkList.currentItem()->text().split("->");
linkList.takeItem(linkList.currentRow());
@ -50,18 +55,22 @@ private:
}
}
void keyPressEvent(QKeyEvent* event) override
{
if (event->key() == Qt::Key_Delete) Unlink();
}
QHBoxLayout layout{ this };
QVBoxLayout buttons;
QListWidget linkList{ this };
QPushButton linkButton{ LINK, this };
QPushButton linkButton{ LINK, this }, unlinkButton{ UNLINK, this };
} window;
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
{
std::shared_lock lock(m);
int64_t textHandle = sentenceInfo["text number"];
for (auto linkedHandle : linkedTextHandles[textHandle])
((void(*)(int64_t, const wchar_t*))sentenceInfo["void (*AddText)(int64_t number, const wchar_t* text)"])(linkedHandle, sentence.c_str());
auto links = linkedTextHandles.find(sentenceInfo["text number"]);
if (links != linkedTextHandles.end()) for (auto link : links->second)
((void(*)(int64_t, const wchar_t*))sentenceInfo["void (*AddText)(int64_t number, const wchar_t* text)"])(link, sentence.c_str());
return false;
}

View File

@ -221,6 +221,7 @@ Whitespace in original_text is ignored, but replacement_text can contain spaces,
This file must be encoded in Unicode (UTF-16 Little Endian).)";
const char* THREAD_LINKER = u8"Thread Linker";
const char* LINK = u8"Link";
const char* UNLINK = u8"Unlink";
const char* THREAD_LINK_FROM = u8"Thread number to link from";
const char* THREAD_LINK_TO = u8"Thread number to link to";
const char* HEXADECIMAL = u8"Hexadecimal";