添加算法改进

This commit is contained in:
codeboss 2024-05-04 23:34:21 +08:00
parent 46fc8b0cb2
commit a3e255a991
6 changed files with 41 additions and 23 deletions

View File

@ -6,9 +6,9 @@
<LocalDebuggerCommandArguments>-path "D:\手作小说\科学+修仙+创造世界"</LocalDebuggerCommandArguments> <LocalDebuggerCommandArguments>-path "D:\手作小说\科学+修仙+创造世界"</LocalDebuggerCommandArguments>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-05-04T09:33:58.7289365Z</QtLastBackgroundBuild> <QtLastBackgroundBuild>2024-05-04T13:29:44.1342154Z</QtLastBackgroundBuild>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-05-04T09:33:58.9501188Z</QtLastBackgroundBuild> <QtLastBackgroundBuild>2024-05-04T13:29:44.5012357Z</QtLastBackgroundBuild>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -5,9 +5,9 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-05-04T09:33:59.3486956Z</QtLastBackgroundBuild> <QtLastBackgroundBuild>2024-05-04T13:29:47.7605591Z</QtLastBackgroundBuild>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-05-04T09:33:59.5091441Z</QtLastBackgroundBuild> <QtLastBackgroundBuild>2024-05-04T13:29:47.9767101Z</QtLastBackgroundBuild>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -122,39 +122,51 @@ void FragmentOrdersCheck::elements_link_build(const QList<std::shared_ptr<StoryS
} }
} }
void FragmentOrdersCheck::sort_cycle_check(const QList<std::shared_ptr<FragmentSortHelper>>& tracks, std::shared_ptr<FragmentSortHelper> current, int story_sort_source) template<class InputIt, class OutputIt, class Operate>
void cast(InputIt Begin, InputIt End, OutputIt Dst, Operate fn) {
while (Begin != End) {
*Dst++ = fn(*Begin++);
}
}
void FragmentOrdersCheck::sort_cycle_check(const QList<std::shared_ptr<FragmentSortHelper>>& tracks, std::shared_ptr<FragmentSortHelper> _current, int story_sort_source)
{ {
if (!current) if (!_current || !_current->next())
return; return;
if (tracks.contains(current)) { auto target = _current->next();
if (tracks.contains(peaks_appoint_element(target))) {
QString error_cycle; QString error_cycle;
for (auto& it : tracks) for (auto& it : tracks)
error_cycle += u8"->" + it->nodeBind()->element()->signature() + u8"\n"; error_cycle += u8"->" + it->nodeBind()->element()->signature() + u8"\n";
error_cycle += u8"->" + current->nodeBind()->element()->signature() + u8"¡£"; error_cycle += u8"->" + target->nodeBind()->element()->signature() + u8"¡£";
throw new lib_parse::CheckException(u8"Parse[0x0003]ÅÅÐòÒì³££º\n" + error_cycle); throw new lib_parse::CheckException(u8"Parse[0x0003]ÅÅÐòÒì³££º\n" + error_cycle);
} }
auto nlist = tracks; auto nlist = tracks;
nlist.append(peaks_appoint_element(target));
if (current->nodeType() == example_novel::FragmentSortHelper::Type::REFER) { if (target->nodeType() == example_novel::FragmentSortHelper::Type::REFER) {
decltype (current->siblings()) fork_list; decltype (target->siblings()) sibling_forks;
for (auto& vit : current->siblings()) {
auto siblings = target->siblings();
for (auto& vit : siblings) {
if (vit->storySort() <= story_sort_source) if (vit->storySort() <= story_sort_source)
fork_list << vit; sibling_forks << vit;
} }
for (auto& fork : fork_list) { for (auto& fork : sibling_forks) {
sort_cycle_check(nlist, fork, story_sort_source); sort_cycle_check(nlist, fork, story_sort_source);
} }
} }
nlist.append(peaks_appoint_element(current)); sort_cycle_check(nlist, target, story_sort_source);
sort_cycle_check(nlist, current->next(), story_sort_source);
} }
std::shared_ptr<FragmentSortHelper> example_novel::FragmentOrdersCheck::peaks_appoint_element(std::shared_ptr<FragmentSortHelper> refer_n) std::shared_ptr<FragmentSortHelper> example_novel::FragmentOrdersCheck::peaks_appoint_element(std::shared_ptr<FragmentSortHelper> refer_n) const
{ {
if (refer_n->nodeType() == example_novel::FragmentSortHelper::Type::ELEMENT) if (refer_n->nodeType() == example_novel::FragmentSortHelper::Type::ELEMENT)
return refer_n; return refer_n;
@ -230,8 +242,14 @@ void FragmentOrdersCheck::validCheck(std::shared_ptr<const ast_gen::ElementAcces
const_cast<FragmentOrdersCheck*>(this)->elements_link_build(this->stories_list); const_cast<FragmentOrdersCheck*>(this)->elements_link_build(this->stories_list);
for (auto& s : this->stories_list) for (auto& s : this->stories_list) {
const_cast<FragmentOrdersCheck*>(this)->sort_cycle_check(QList<std::shared_ptr<FragmentSortHelper>>(), s->fragmentSort(), s->sortValue()); if(!s->fragmentSort())
continue;
QList<std::shared_ptr<FragmentSortHelper>> tracks;
tracks << peaks_appoint_element(s->fragmentSort());
const_cast<FragmentOrdersCheck*>(this)->sort_cycle_check(tracks, s->fragmentSort(), s->sortValue());
}
} }
StorySortHelper::StorySortHelper(std::shared_ptr<const ast_gen::ElementAccess> story_bind) { StorySortHelper::StorySortHelper(std::shared_ptr<const ast_gen::ElementAccess> story_bind) {

View File

@ -25,7 +25,7 @@ namespace example_novel {
void sort_cycle_check(const QList<std::shared_ptr<FragmentSortHelper>>& tracks, std::shared_ptr<FragmentSortHelper> current, void sort_cycle_check(const QList<std::shared_ptr<FragmentSortHelper>>& tracks, std::shared_ptr<FragmentSortHelper> current,
int story_sort_source); int story_sort_source);
std::shared_ptr<FragmentSortHelper> peaks_appoint_element(std::shared_ptr<FragmentSortHelper> refer_n); std::shared_ptr<FragmentSortHelper> peaks_appoint_element(std::shared_ptr<FragmentSortHelper> refer_n) const;
// CheckProvider interface // CheckProvider interface
public: public:

View File

@ -5,9 +5,9 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-05-04T09:33:59.5719569Z</QtLastBackgroundBuild> <QtLastBackgroundBuild>2024-05-04T13:29:47.3997896Z</QtLastBackgroundBuild>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-05-04T09:33:59.7159031Z</QtLastBackgroundBuild> <QtLastBackgroundBuild>2024-05-04T13:29:47.5416879Z</QtLastBackgroundBuild>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -2,9 +2,9 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup /> <PropertyGroup />
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-05-04T09:33:59.0218626Z</QtLastBackgroundBuild> <QtLastBackgroundBuild>2024-05-04T13:29:46.3016809Z</QtLastBackgroundBuild>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2024-05-04T09:33:59.1804633Z</QtLastBackgroundBuild> <QtLastBackgroundBuild>2024-05-04T13:29:46.7433247Z</QtLastBackgroundBuild>
</PropertyGroup> </PropertyGroup>
</Project> </Project>