Skip to content

Commit 69e2ca6

Browse files
committed
export module leetcode_test.print_zero_even_odd.ZeroEvenOdd;
1 parent e278eb3 commit 69e2ca6

File tree

8 files changed

+287
-20
lines changed

8 files changed

+287
-20
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,4 +2594,6 @@ https://leetcode.cn/problems/web-crawler-multithreaded/
25942594

25952595
https://leetcode.cn/problems/letter-tile-possibilities
25962596

2597+
https://leetcode.cn/problems/print-zero-even-odd/
2598+
25972599
</details>

print-zero-even-odd/index.ixx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
3+
module;
4+
#include<utility>
5+
#include<functional>
6+
export module leetcode_test.print_zero_even_odd.ZeroEvenOdd;
7+
import leetcode_test.print_foobar_alternately.BlockingQueue;
8+
using leetcode_test::print_foobar_alternately::BlockingQueue;
9+
using namespace std;
10+
namespace leetcode_test::print_zero_even_odd {
11+
export class ZeroEvenOdd {
12+
private:
13+
int n;
14+
15+
pair<BlockingQueue<int>, BlockingQueue<int>> channelEven;
16+
pair<BlockingQueue<int>, BlockingQueue<int>> channelOdd;
17+
18+
public:
19+
~ZeroEvenOdd() { }
20+
ZeroEvenOdd(int n) { this->n = n; }
21+
22+
// printNumber(x) outputs "x", where x is an integer.
23+
void zero(function<void(int)> printNumber)
24+
{
25+
for (auto i = 1; i <= n; i++) {
26+
27+
printNumber(0);
28+
29+
if (i % 2) {
30+
31+
channelOdd.second.put(i);
32+
auto msg2 = 0;
33+
channelOdd.first.take(msg2);
34+
35+
} else {
36+
channelEven.second.put(i);
37+
auto msg2 = 0;
38+
channelEven.first.take(msg2);
39+
}
40+
}
41+
42+
channelEven.second.put(-1);
43+
channelOdd.second.put(-1);
44+
}
45+
46+
void even(function<void(int)> printNumber)
47+
{
48+
while (true) {
49+
auto msg = 0;
50+
channelEven.second.take(msg);
51+
if (msg == -1)
52+
return;
53+
printNumber(msg);
54+
channelEven.first.put(0);
55+
}
56+
}
57+
58+
void odd(function<void(int)> printNumber)
59+
{
60+
while (true) {
61+
auto msg = 0;
62+
channelOdd.second.take(msg);
63+
if (msg == -1)
64+
return;
65+
printNumber(msg);
66+
channelOdd.first.put(0);
67+
}
68+
}
69+
};
70+
} // namespace leetcode_test::print_zero_even_odd
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33712.159
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "print-zero-even-odd", "print-zero-even-odd.vcxproj", "{30B3A081-CAD4-4CEA-A1AD-6B37B955B3C2}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{30B3A081-CAD4-4CEA-A1AD-6B37B955B3C2}.Debug|x64.ActiveCfg = Debug|x64
17+
{30B3A081-CAD4-4CEA-A1AD-6B37B955B3C2}.Debug|x64.Build.0 = Debug|x64
18+
{30B3A081-CAD4-4CEA-A1AD-6B37B955B3C2}.Debug|x86.ActiveCfg = Debug|Win32
19+
{30B3A081-CAD4-4CEA-A1AD-6B37B955B3C2}.Debug|x86.Build.0 = Debug|Win32
20+
{30B3A081-CAD4-4CEA-A1AD-6B37B955B3C2}.Release|x64.ActiveCfg = Release|x64
21+
{30B3A081-CAD4-4CEA-A1AD-6B37B955B3C2}.Release|x64.Build.0 = Release|x64
22+
{30B3A081-CAD4-4CEA-A1AD-6B37B955B3C2}.Release|x86.ActiveCfg = Release|Win32
23+
{30B3A081-CAD4-4CEA-A1AD-6B37B955B3C2}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {25196C2D-FFA5-44A4-B2ED-5A936F6C9861}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>16.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{30b3a081-cad4-4cea-a1ad-6b37b955b3c2}</ProjectGuid>
25+
<RootNamespace>printzeroevenodd</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>StaticLibrary</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>StaticLibrary</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>StaticLibrary</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>StaticLibrary</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v143</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<ClCompile>
75+
<WarningLevel>Level3</WarningLevel>
76+
<SDLCheck>true</SDLCheck>
77+
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
78+
<ConformanceMode>true</ConformanceMode>
79+
</ClCompile>
80+
<Link>
81+
<SubSystem>
82+
</SubSystem>
83+
<GenerateDebugInformation>true</GenerateDebugInformation>
84+
</Link>
85+
</ItemDefinitionGroup>
86+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
87+
<ClCompile>
88+
<WarningLevel>Level3</WarningLevel>
89+
<FunctionLevelLinking>true</FunctionLevelLinking>
90+
<IntrinsicFunctions>true</IntrinsicFunctions>
91+
<SDLCheck>true</SDLCheck>
92+
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
93+
<ConformanceMode>true</ConformanceMode>
94+
</ClCompile>
95+
<Link>
96+
<SubSystem>
97+
</SubSystem>
98+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
99+
<OptimizeReferences>true</OptimizeReferences>
100+
<GenerateDebugInformation>true</GenerateDebugInformation>
101+
</Link>
102+
</ItemDefinitionGroup>
103+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
104+
<ClCompile>
105+
<WarningLevel>Level3</WarningLevel>
106+
<SDLCheck>true</SDLCheck>
107+
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
108+
<ConformanceMode>true</ConformanceMode>
109+
<LanguageStandard>stdcpp20</LanguageStandard>
110+
</ClCompile>
111+
<Link>
112+
<SubSystem>
113+
</SubSystem>
114+
<GenerateDebugInformation>true</GenerateDebugInformation>
115+
</Link>
116+
</ItemDefinitionGroup>
117+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
118+
<ClCompile>
119+
<WarningLevel>Level3</WarningLevel>
120+
<FunctionLevelLinking>true</FunctionLevelLinking>
121+
<IntrinsicFunctions>true</IntrinsicFunctions>
122+
<SDLCheck>true</SDLCheck>
123+
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
124+
<ConformanceMode>true</ConformanceMode>
125+
</ClCompile>
126+
<Link>
127+
<SubSystem>
128+
</SubSystem>
129+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
130+
<OptimizeReferences>true</OptimizeReferences>
131+
<GenerateDebugInformation>true</GenerateDebugInformation>
132+
</Link>
133+
</ItemDefinitionGroup>
134+
<ItemGroup>
135+
<ClCompile Include="..\print-foobar-alternately\BlockingQueue.ixx" />
136+
<ClCompile Include="index.ixx" />
137+
</ItemGroup>
138+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
139+
<ImportGroup Label="ExtensionTargets">
140+
</ImportGroup>
141+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="源文件">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="头文件">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="资源文件">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="index.ixx">
19+
<Filter>源文件</Filter>
20+
</ClCompile>
21+
<ClCompile Include="..\print-foobar-alternately\BlockingQueue.ixx">
22+
<Filter>源文件</Filter>
23+
</ClCompile>
24+
</ItemGroup>
25+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup />
4+
</Project>

split-a-circular-linked-list/test.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,28 @@ using namespace leetcode_test::split_a_circular_linked_list;
1717
using namespace std;
1818
using std::vector;
1919
template <class T>
20-
concept sizable = requires(T& t)
21-
{
20+
concept sizable = requires(T& t) {
2221
{
2322
t.size()
24-
} -> std::same_as<size_t>;
23+
} -> std::same_as<size_t>;
2524
};
2625
template <class T>
27-
concept iterable = requires(T& t)
28-
{
26+
concept iterable = requires(T& t) {
2927
++t.begin();
3028
{
3129
t.begin() != t.end()
3230

33-
} -> std::same_as<bool>;
31+
} -> std::same_as<bool>;
3432
};
3533

3634
template <class T, typename Y>
37-
concept equalable = requires(T& t, Y& y, size_t i)
38-
{
35+
concept equalable = requires(T& t, Y& y, size_t i) {
3936
{
4037
*t.begin() == *y.begin()
41-
} -> std::same_as<bool>;
38+
} -> std::same_as<bool>;
4239
};
4340
template <typename T, typename Y>
44-
requires sizable<T> and sizable<Y> and equalable<T, Y> and iterable<T> and iterable<Y>
41+
requires sizable<T> and sizable<Y> and equalable<T, Y> and iterable<T> and iterable<Y>
4542
auto assertContentEquals(T& left, Y& right)
4643
{
4744

web-crawler-multithreaded/test.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,27 @@ import leetcode_test.web_crawler_multithreaded.Solution;
1111
using namespace std;
1212
using namespace leetcode_test::web_crawler_multithreaded;
1313
template <class T>
14-
concept sizable = requires(T& t)
15-
{
14+
concept sizable = requires(T& t) {
1615
{
1716
t.size()
18-
} -> std::same_as<size_t>;
17+
} -> std::same_as<size_t>;
1918
};
2019
template <class T>
21-
concept iterable = requires(T& t)
22-
{
20+
concept iterable = requires(T& t) {
2321
++t.begin();
2422
{
2523
t.begin() != t.end()
26-
} -> std::same_as<bool>;
24+
} -> std::same_as<bool>;
2725
};
2826

2927
template <class T, typename Y>
30-
concept equalable = requires(T& t, Y& y, size_t i)
31-
{
28+
concept equalable = requires(T& t, Y& y, size_t i) {
3229
{
3330
*t.begin() == *y.begin()
34-
} -> std::same_as<bool>;
31+
} -> std::same_as<bool>;
3532
};
3633
template <typename T, typename Y>
37-
requires sizable<T> and sizable<Y> and equalable<T, Y> and iterable<T> and iterable<Y>
34+
requires sizable<T> and sizable<Y> and equalable<T, Y> and iterable<T> and iterable<Y>
3835
auto assertContentEquals(const T& left, const Y& right)
3936
{
4037

0 commit comments

Comments
 (0)